Question: Retrieve a large dataset of biological sequences with Perl
0
gravatar for Helder Gomes
3.7 years ago by
Helder Gomes10
Helder Gomes10 wrote:

Hi. 

I am trying a Perl script from NCBI´s EUtils to retrieve a large dataset of sequences of the microbiome of Xestospongia testudinaria.

use LWP::Simple;
use warnings;
# Download FASTA records linked to xestospongia testudinaria on Nucleotide.

$db1 = 'pubmed';
$db2 = 'nuccore';
$linkname = 'pubmed_nuccore';
$query = 'xestospongia testudinaria';

#assemble the esearch URL
$base = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/';
$url = $base . "esearch.fcgi?db=$db1&term=$query&usehistory=y";
#post the esearch URL
$output = get($url);

#parse WebEnv and QueryKey
$web1 = $1 if ($output =~ /<WebEnv>(\S+)<\/WebEnv>/);
$key1 = $1 if ($output =~ /<QueryKey>(\d+)<\/QueryKey>/);

#assemble the elink URL
$base = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/';
$url = $base . "elink.fcgi?dbfrom=$db1&db=$db2";
$url .= "&query_key=$key1&WebEnv=$web1";
$url .= "&linkname=$linkname&cmd=neighbor_history";
print "$url\n";

#post the elink URL
$output = get($url);
print "$output\n";

#parse WebEnv and QueryKey
$web2 = $1 if ($output =~ /<WebEnv>(\S+)<\/WebEnv>/);
$key2 = $1 if ($output =~ /<QueryKey>(\d+)<\/QueryKey>/);

#assemble the efetch URL
$url = $base . "efetch.fcgi?db=$db2&query_key=$key2&WebEnv=$web2";
$url .= "&rettype=fasta&retmode=text";
#post the efetch URL
$data = get($url);
print "$data";

The script is ALMOST working except for one thing: it is displaying all the info (including the sequences) in my command line instead of in a document. Can you help me?

 

sequence perl ncbi • 1.1k views
ADD COMMENTlink written 3.7 years ago by Helder Gomes10
4

And that is because :

1. you stated that you wish to print it into your "command line": print "$data"; says print to stdout

2. you did not specify the output file.

 

a simple fix would be to redirect the stdout to a file : perl your_script.pl > myfile

ADD REPLYlink written 3.7 years ago by mxs530

Thanks mxs. It works great!

ADD REPLYlink written 3.7 years ago by Helder Gomes10
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1121 users visited in the last hour