LWP problem

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Apr 2009
Posts: 19
Reputation: ajay_p5 is an unknown quantity at this point 
Solved Threads: 0
ajay_p5 ajay_p5 is offline Offline
Newbie Poster

LWP problem

 
0
  #1
May 20th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: LWP problem

 
0
  #2
May 20th, 2009
I didn't look at all your code but this line:

  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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: LWP problem

 
0
  #3
May 20th, 2009
This line also needs to be changed:

  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:

  1. $nucleotide_gi,$start_gene,$end_gene,$strand) = split(/\t/);
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 19
Reputation: ajay_p5 is an unknown quantity at this point 
Solved Threads: 0
ajay_p5 ajay_p5 is offline Offline
Newbie Poster

Re: LWP problem

 
0
  #4
May 22nd, 2009
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
.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: LWP problem

 
0
  #5
May 23rd, 2009
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:

  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:

  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):

  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
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 19
Reputation: ajay_p5 is an unknown quantity at this point 
Solved Threads: 0
ajay_p5 ajay_p5 is offline Offline
Newbie Poster

Re: LWP problem

 
0
  #6
May 23rd, 2009
Hey thanks a lot for your excellent suggestions .. the code looks extremely perfect now.

Cheers
Ajay
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Perl Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC