2
$\begingroup$

I'm trying to use Entrez (through Biopython) to download the sequence of a TMV replicase gene.

I have the following code:

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

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

But when I run it it throws the exception on the SeqIO.read line: ValueError: No records found in handle.

The IDs provided in idlist are: ['1494081', '1494082'].

$\endgroup$

1 Answer 1

2
$\begingroup$

Did you try to fetch from the database nucleotide instead of gene ?

# load modules
from Bio import SeqIO
from Bio import Entrez

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

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

It returns

>>> read
SeqRecord(seq=Seq('GTATTTTTACAACAATTACCAACAACAACAAACAACAAACAACATTACAATTAC...GGG'), id='MN912489.1', name='MN912489', description='Tobacco mosaic virus isolate TMV:BR:SC:02:01, complete genome', dbxrefs=[])
>>> tmv_replicase
Seq('GTATTTTTACAACAATTACCAACAACAACAAACAACAAACAACATTACAATTAC...GGG')

$\endgroup$
3
  • $\begingroup$ Thank you, this gets me what I wanted. Out of interest though, do you know why using the gene database for this wouldn't work? (I'm new to Entrez). $\endgroup$
    – blammo69
    Commented Jun 3, 2021 at 9:34
  • $\begingroup$ It is simply 2 differents databases. The ID into nucleotide is not the same into gene. Thus from the website NCBI it is possible to extract a fasta from a gene query it doesn't seem possible with biopython biopython.readthedocs.io/en/latest/chapter_entrez.html $\endgroup$ Commented Jun 4, 2021 at 8:03
  • $\begingroup$ If you want to filter your queries from the nucleotide database in order to get only the specific genes you can check my code as an example: gitlab.mbb.univ-montp2.fr/bev/target_genes_from_ncbi/-/blob/… $\endgroup$ Commented Jun 4, 2021 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.