Question: Ncbi Eutilities Get Data By Accession Number , Perl
gravatar for Maria
7.5 years ago by
Maria170 wrote:


I want to retrieve genbank files for all Chordata. I have already the accession numbers for all the Chordata. I read about getting data by accession numbers using NCBI eutilities , but unfortunately the sample that does this is not working. Here is the copied code from NCBI tutorial: application 2:

use Data::Dumper;
use LWP::Simple;
$acc_list = 'NC_000834,NC_000877,NC_000880,NC_000886';
@acc_array = split(/,/, $acc_list);

#append [accn] field to each accession
for ($i=0; $i < @acc_array; $i++) {
   $acc_array[$i] .= "[accn]";

#join the accessions with OR
$query = join('+OR+',@acc_array);

#assemble the esearch URL
$base = '';
$url = $base . "esearch.fcgi?db=nucleotide&term=$query&usehistory=y";

#post the esearch URL
$output = get($url);

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

#assemble the efetch URL
$url = $base . "efetch.fcgi?db=protein&query_key=$key&WebEnv=$web";
$url .= "&rettype=fasta&retmode=text";

#post the efetch URL
$fasta = get($url);
print Dumper $fasta;

the dumper result is $VAR1 = undef($fasta).

My problem is that I can't adjust the script to retrieve the genbank files because the sample is not working. How to solve this problem ? can I retirieve the genbank data using another method ? i.e something related to the world chordata. thanks in advance for any hlep.

ncbi perl entrez error • 4.0k views
ADD COMMENTlink modified 7.5 years ago by Tky1.0k • written 7.5 years ago by Maria170
gravatar for Tky
7.5 years ago by
Tky1.0k wrote:

You need to modify this line

$url = $base . "efetch.fcgi?db=protein&query_key=$key&WebEnv=$web";


$url = $base . "efetch.fcgi?db=nucleotide&query_key=$key&WebEnv=$web";

because you first search on the database of nucleotide (Esearch0, then you can not change to protein in the retrive step. you need keep them consistent.

ADD COMMENTlink written 7.5 years ago by Tky1.0k
Please log in to add an answer.


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