#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0

    Need help with backticks script!!!


    Using system_cmd.pl as a starting point,
    rename the script as blast_grep.pl
    Add comments to explain the code you write.
    You will lose points for inadequate comments.

    Make the following modifications to the script:
    a. Remove the code that creates a file with numbered lines
    b. Using backtics, run the command `grep JAY291 $file.blastn` and capture the results of the grep in an array
    c. For each element in the resulting array, print a substring of the array element that includes only the GI number (use substr).
    (Note that in general, substr is not a good way to extract GI numbers as they may vary in length…we’ll learn a better way soon.)
    d. To make the script more flexible, add code to accept a second command line argument that
    replaces the hard-coded JAY291 in the grep command. Example runs with output might
    look like this:

    [service1][~/ ecol553_week7]> perl blast_grep.pl yeastgenes.fa Patent
    Starting BLAST run...Finished BLAST run.
    254748699
    257307076
    257307082

    [service1][~/week7]> perl blast_grep.pl yeastgenes.fa EC1118
    Starting BLAST run...Finished BLAST run.
    259149040
    259145041
    259148440
    259145824


    WHAT I HAVE SO FAR:

    #!/usr/bin/perl
    use warnings;
    use strict;

    # Demonstration of Perl's system function
    # Run a BLAST job

    my $file = $ARGV[0];
    if (!defined $file) {
    die "Usage: $0 FASTAfile\n";
    }

    print "Starting BLAST run...";
    #show_gis = show the GI numbers
    my $cmd = "/uaopt/ncbi/blast-2.2.25+/bin/blastn -db /genome/eeb553/yeast_sub -query $file -out $file.blastn -num_descriptions 1 -num_alignments 0 -evalue 1e-100 -show_gis";
    system($cmd);
    print "Finished BLAST run.\n";
    `grep JAY291 $file.blastn` > my @grep_results

    foreach $grep_results {

    THIS IS THE ORIGINAL:
    #!/usr/bin/perl
    use warnings;
    use strict;

    # Demonstration of Perl's system function
    # Run a BLAST job

    my $file = $ARGV[0];
    if (!defined $file) {
    die "Usage: $0 FASTAfile\n";
    }

    print "Starting BLAST run...";
    my $cmd = "/uaopt/ncbi/blast-2.2.25+/bin/blastn -db /genome/eeb553/yeast_sub -query $file -out $file.blastn -num_descriptions 1 -num_alignments 0 -evalue 1e-100 -show_gis";
    system($cmd);
    print "Finished BLAST run.\nNumbering output lines.\n";
    $cmd = "perl file_output.pl $file.blastn";
    system($cmd);
    print "Finished numbering output lines.\n";


    Please help me!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    832
    Rep Power
    496
    Hi,

    follow the instructions.

    a. Remove the code that creates a file with numbered lines
    You did not remove that code, as far as I can say.

    b. Using backtics, run the command `grep JAY291 $file.blastn` and capture the results of the grep in an array
    Your try:

    Perl Code:
    `grep JAY291 $file.blastn` > my @grep_results

    You can't redirect output in Perl the same way as you would do in a shell script. The backticks command returns the result of the system command.

    Try something like this:

    Perl Code:
    my @grep_result = `grep JAY291 $file.blastn`;
    chomp @grep_result;


    Here is an example of a Perl one-liner where I look for all instances of the "use" word in the Perl files of my current directory:

    Perl Code:
    perl -e '@foo = `grep use *.pl`; chomp @foo; print "$_\n" foreach @foo;'


    This is part of the output:

    Code:
    filter.pl:use 5.10.0;
    filter.pl:use strict;
    filter.pl:use warnings;
    genetic.pl:use strict;
    genetic.pl:use warnings;
    genetic2.pl:use strict;
    genetic2.pl:use warnings;
    genetic3.pl:use strict;
    genetic3.pl:use warnings;
    Then, you need to go through each element of your @grep_result array. Something like this:

    Perl Code:
    foreach my $line (@grep_result) { # ...

    I'll leave it there, as this is obviously homework assignment, you should probably try to figure out the rest by yourself.

IMN logo majestic logo threadwatch logo seochat tools logo