This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Can't get accession number using Entrez.

I have the following Python code in which I am trying to get the sequence of a TMV replicase gene:

# Lookup ID
search = Entrez.esearch(db='gene', term='Tobacco mosaic virus[Orgn] replicase', idtype="acc")
read = Entrez.read(search)
idlist = read["IdList"]

# Get sequence
search = Entrez.efetch(db='gene', id=idlist[0], retmode='text', rettype='gb')
read = SeqIO.read(search, "genbank")
sequence = read.seq

However, using idtype="acc" doesn't give me an accession number. Instead, I get 1494081, the ID for the gene in the gene database.

When I then try and fetch it in the gene database it throws ValueError: No records found in handle.

I've also tried fetching with the nucleotide database but without the accession number the ID leads to the wrong thing.

python search entrez

Using EntrezDirect:

$ esearch -db gene -query "Tobacco mosaic virus [Orgn] AND replicase"| esummary | xtract -pattern GenomicInfoType -element ChrAccVer,ChrStart,ChrStop
NC_001367.1 68  3418
NC_001367.1 68  4918

To get the sequence

$ esearch -db gene -query "Tobacco mosaic virus [Orgn] AND replicase"| esummary | xtract -pattern GenomicInfoType -element ChrAccVer,ChrStart,ChrStop | xargs -n 3 sh -c 'efetch -db nuccore -id "$0" -seq_start "$1" -seq_stop "$2" -format fasta'

Is there an equivalent to xtract for biopython? I can't seem to find one.

0 answers

No answers yet.

Log in to answer this question.