Dear Monks,
I am trying to use LWP::Simple to get sequences from a website. The web address for each sequence is always the same except for the sequence id at the end. I am only retrieving 537/603 sequences with the below code.
Obviously it seems that some of my sequences can't be found. However, if it can't find a sequence I am trying to print an error message to say so in the output - this is the part that i can't get to work.
I wondered if someone could suggest how I can print an error message if the sequence can't be found (e.g. web site is empty or doesn't exist). Thanks!
use strict;
use LWP::Simple;
my @fasta;
my $o;
# Note: @accession defined earlier has 603 elements
for (my $i=0; $i<@accession; $i++) {
if ($accession[$i] =~ /^(\w+)\_(\w+)\_(\w+)\;/) {
#print "$accession[$i]\n";
if ($1 eq $3) {
# USE $1 AS THE ACCESSION NUMBER
my $seq = get "http://us.expasy.org/cgi-bin/get-sprot-
+fasta?$1";
#print "$seq\n";
push (@fasta, $seq);
push @fasta, "> COULDN'T FIND IT" unless defin
+ed $seq;
}
else {
# # USE $3 AS THE ACCESSION NUMBER
my $seq = "http://us.expasy.org/cgi-bin/get-sprot-fas
+ta?$3";
push (@fasta, $seq);
push @fasta, "> COULDN'T FIND IT" unless defin
+ed $seq;
}
}
}
#print "$o\n";
# fasta only has 537 / 603 elements
print "@fasta\n";
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.