943,856 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Marked Solved
  • Views: 741
  • Perl RSS
May 20th, 2009
0

LWP problem

Expand Post »
Dear people
I have been trying to fetch some data from the web. For this I am using the
LWP:: Simple module.
The problem is that I have been trying to pass a value to the URL in get function.

here is my code:
use LWP:: Simple;
$iq= 'all_proteins.data';
$id= 'seq.txt';
open(INFILE,"$iq");
while(<INFILE>)
{
$line= $_;
$line=~tr/\n//d;
($tax_id,$geneID,$genesymbol,$gene_des,$proteinacc_ver,$mrna_acc,$length,$nucleotide_gi,$start_gene,$end_gene,$strand) = split('\t');
push(@protacc_arr,"$proteinacc_ver");
}
$arr_size = $#protacc_arr;
open(OUTFILE,">>$id");
for($i=0;$i<=$arr_size;$i++)
{
$content = get('http://www.ncbi.nlm.nih.gov/sviewer/viewer.fcgi?db=protein&sendto=t&dopt=fasta&list_uids=$protacc_arr[$i]');
$store = $content;
print OUTFILE"$store\n";
}
close(INFILE);
close(OUTFILE);
exit;
--------------------------------------------------------------------------
ok So the main problem that I am facing over here is that the value which is a ID ($protacc_arr[$i]) acquires some ids from my earlier code.
but I think when i am trying to pass it in the get function ..i am not able to.

I want to ask:
can we pass a value in a URL.
If yes , how do we do it...if not what is an alternative to do that in perl.

I am confused how to do it, as the code works fine i write a value such as NP_332.1 instead of passing it using an array.. but the problem is that I haver to do it for more than lakhs of ids ..so I really need to automate it..can sumbosy help..
I would be really grateful.

Thanks
Aj
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
ajay_p5 is offline Offline
29 posts
since Apr 2009
May 20th, 2009
0

Re: LWP problem

I didn't look at all your code but this line:

Perl Syntax (Toggle Plain Text)
  1. $content = get('http://www.ncbi.nlm.nih.gov/sviewer/viewer.fcgi?db=protein&sendto=t&dopt=fasta&list_uids=$protacc_arr[$i]');

Needs double-quotes so that the variables are interpolated:

Perl Syntax (Toggle Plain Text)
  1. $content = get("http://www.ncbi.nlm.nih.gov/sviewer/viewer.fcgi?db=protein&sendto=t&dopt=fasta&list_uids=$protacc_arr[$i]");

Change that and see if it helps.
Last edited by KevinADC; May 20th, 2009 at 8:05 pm.
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
May 20th, 2009
0

Re: LWP problem

This line also needs to be changed:

Perl Syntax (Toggle Plain Text)
  1. $nucleotide_gi,$start_gene,$end_gene,$strand) = split('\t');

\t in single-quotes is a literal string, not a tab, so use forward slashes for the split() delimter:

Perl Syntax (Toggle Plain Text)
  1. $nucleotide_gi,$start_gene,$end_gene,$strand) = split(/\t/);
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
May 22nd, 2009
0

Re: LWP problem

hey
Thanks a lot for your suggestion ..the code is working perfectly now ..
Though I would like to pose one more question as you know there are certain variables which i am not using to print any values but just to split my data..
thus ..as I run my code there are certain warnings that comes at the starting ..
for e.g:
Name::main $tax_id not used more than once ..

what I mean is that it is not creating any problem but can I do something to avoid those warnings.

Thanks
Aj
.
Reputation Points: 10
Solved Threads: 0
Light Poster
ajay_p5 is offline Offline
29 posts
since Apr 2009
May 23rd, 2009
0

Re: LWP problem

Yes there is something you can do. There are a few things actually. But I think this is the best suggestion. Instead of returning a list of scalars with some that you don't use, return a list slice consisting only of the ones you want to use. Look at this line:

Perl Syntax (Toggle Plain Text)
  1. ($tax_id,$geneID,$genesymbol,$gene_des,$proteinacc_ver,$mrna_acc,$length,$nucleotide_gi,$start_gene,$end_gene,$strand) = split("\t");

It returns a list of 11 scalars. They are numbered 0 thru 10, so your line above is the same as this:

Perl Syntax (Toggle Plain Text)
  1. ($tax_id,$geneID,$genesymbol,$gene_des,$proteinacc_ver,$mrna_acc,$length,$nucleotide_gi,$start_gene,$end_gene,$strand) = (split("\t"))[0..10];

Now what you can do is take just the elements of the list you want by including only those ones in the index list, say you only want $geneId (#1) and $nucleotide_gi (#7):

Perl Syntax (Toggle Plain Text)
  1. my ($geneID,$nucleotide_gi) = (split("\t"))[1,7];

Note the extra set of parenthisis on the right side of the assignment operator, that is important. Note I added "my" in the above line also. You need to start using "strict" and "warnings" with your script (not the -w switch) and declaring the varaibles within their intended scope of use with "my" (lexical) or "our" (global). You can look them all up in the perl documentation:

strict
warnings
my
our
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
May 23rd, 2009
0

Re: LWP problem

Hey thanks a lot for your excellent suggestions .. the code looks extremely perfect now.

Cheers
Ajay
Reputation Points: 10
Solved Threads: 0
Light Poster
ajay_p5 is offline Offline
29 posts
since Apr 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: how does gt work for comparing?
Next Thread in Perl Forum Timeline: help with Regular Expression





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC