This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to get organism kingdom of an organism.

I want to get a Organism kingdom of an organism(esearch id) through ncbi taxonomy database, is there any method to do it.

EDIT:Sorry i want to search for the organism kingdom for that matter.

ncbi taxonomy

1 answer

There are many different ways, here's one way using Biopython. First, I checked the database using a webbrowser for Brassica napus: http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=3708

If you hover over the name at the top, you'll see that the kingdom is Viridiplantae.

In BioPython:

from Bio import Entrez
Entrez.email = "some_email@somewhere.edu.au" # we're nice and tell our address
handle = Entrez.esearch(db='taxonomy', term='Brassica napus', retmax=2, usehistory='y') # return 2 entries at the most - I expect only 1
search_results = Entrez.read(handle)
handle.close()
count = int(search_results['Count'])
print('Got %s records' %count) # should be 1

# get the cookies from the search
webenv = search_results["WebEnv"]
query_key = search_results["QueryKey"]

# download results from the database using our cookies from above

fetch_handle = Entrez.efetch(db='taxonomy', retmode='xml', webenv=webenv, query_key=query_key)
records = Entrez.read(fetch_handle)
assert len(records) == 1 # die if we get more than one record, unlikely?
lineage = records[0]['LineageEx'] # get the entire lineage of the first record
for entry in lineage:
    if entry['Rank'] == 'kingdom':
        print(entry) # prints: {u'ScientificName': 'Viridiplantae', u'TaxId': '33090', u'Rank': 'kingdom '}
        print(entry['ScientificName']) # prints: 'Viridiplantae'
fetch_handle.close()

Log in to answer this question.