Skip to content

Instantly share code, notes, and snippets.

@jmberros
Last active November 23, 2016 01:42
Show Gist options
  • Save jmberros/d0422c337f998ce972e6d0698a89e466 to your computer and use it in GitHub Desktop.
Save jmberros/d0422c337f998ce972e6d0698a89e466 to your computer and use it in GitHub Desktop.
Get Taxa scientific name and lineage from Entrez
from Bio import Entrez
taxids_filename = '/tmp/taxids.list' # Replace with the path to your Tax IDs file!
with open(taxids_filename) as f:
tax_ids = f.read().split('\n')
Entrez.email = '[email protected]' # Put your email here
handle = Entrez.efetch('taxonomy', id=tax_ids, rettype='xml')
response = Entrez.read(handle)
for entry in response:
sci_name = entry.get('ScientificName')
lineage_taxa = entry.get('Lineage').split(';')
print(sci_name, ' > '.join(lineage_taxa), sep=',')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment