Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 11th, 2012, 02:00 PM
noobie2 noobie2 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 3 noobie2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 8 sec
Reputation 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!

Reply With Quote
  #2  
Old October 11th, 2012, 05:03 PM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 508 Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 4 Days 19 h 27 m 4 sec
Reputation Power: 385
Hi,

follow the instructions.

Quote:
a. Remove the code that creates a file with numbered lines

You did not remove that code, as far as I can say.

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

Your try:

Perl Code:
Original - Perl Code
  1. `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:
Original - Perl Code
  1. my @grep_result = `grep JAY291 $file.blastn`;
  2. 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:
Original - Perl Code
  1. 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:
Original - Perl Code
  1. foreach my $line (@grep_result) { # ...
  2.  

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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Need help with backticks script!!!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap