This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to get Taxonomy and Taxon ID for an Accession number using Python?

Hi! I am writing a python script to obtain the taxonomic classification to the phylum level of some protein sequences. I currently have the NCBI accession numbers (see question Retrieving taxonomy from entrez search in biopython). I realized that I need the taxon ID to search it in the taxonomy database to obtain the information about the phylum. Do you know how to do this in Python?

Many thanks!

python biopython entrez

1 answer

Using EntrezDirect (you will need to translate this to biopython):

Following answers will work for both of your questions.

$ esearch -db protein -query OGI11933 | elink -target taxonomy | efetch -format native -mode xml | xtract -pattern Taxon -block "*/Taxon" -unless Rank -equals "no rank" -tab "\n" -element Rank,ScientificName,TaxId
superkingdom    Archaea 2157
clade   DPANN group     1783276
phylum  Candidatus Micrarchaeota        1801631

$ esearch -db protein -query OGI11933 | elink -target taxonomy | efetch -format native -mode xml | xtract -pattern Taxon -block "*/Taxon" -if Rank -equals "phylum" -element ScientificName
Candidatus Micrarchaeota

Log in to answer this question.