Question: Ncbi Eutilities Get Data By Accession Number , Perl
1
gravatar for Maria
5.9 years ago by
Maria150
Maria150 wrote:

Hello,

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: http://www.ncbi.nlm.nih.gov/books/NBK25498/

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 = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/';
$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 • 3.3k views
ADD COMMENTlink modified 5.9 years ago by Tky990 • written 5.9 years ago by Maria150
4
gravatar for Tky
5.9 years ago by
Tky990
Japan
Tky990 wrote:

You need to modify this line

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

to

$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 5.9 years ago by Tky990
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: 675 users visited in the last hour