1
$\begingroup$

I have a long list of NCBI taxonomic ids for organisms and I want to write a script to get their corresponding translation tables. Is there a way to do this through Entrez?

(packages in R, Python etc. would be fine too)

$\endgroup$

2 Answers 2

1
$\begingroup$

I came up with this idea. So, the information for the translation table of any particular organism can be found on its page on the Taxonomy Browser: https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi

If I search a taxid into the website, eg 7227, the page for Drosophila melanogaster will come up but the URL will remain unmodified. However, you can get a modified URL specific to a taxid by appending ?mode=Info&id=your_taxid to the above URL. Eg for D. melanogaster again, it has this unique URL for its Taxonomy browser page: https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=7227

Since you have a list of taxids, you can programmatically access Taxonomy browser pages by modifying the URL in the way I said. To programmatically get the translation tables of D. melanogaster with this approach, use the urllib package in Python.

import urllib.request
url = "https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=7227"
weburl = urllib.request.urlopen(url)
data = weburl.read().decode("utf-8")  # decode because page returned in binary

data_s = data.split('<')

for d in data_s:
    if "Translation table" in d:
        print(d.split('>')[1])

The output is:

Translation table 1 (Standard)
Translation table 5 (Invertebrate Mitochondrial)

This will work for one taxid. But you have a list of them. However, with this approach in mind, it's elementary to construct a Python function for getting the Translation table of all your taxids.

import urllib.request

my_taxids = ['7227','9606','10090']

def get_translation_table(taxid):
    url = "https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=" + taxid
    weburl = urllib.request.urlopen(url)
    data = weburl.read().decode("utf-8")

    data_s = data.split('<')

    tr_table = []

    for d in data_s:
        if "Translation table" in d:
            tr_table += [d.split('>')[1]]

    return tr_table

your_tables = list(map(get_translation_table,my_taxids))

print(your_tables)

The output is:

[['Translation table 1 (Standard)', 'Translation table 5 (Invertebrate Mitochondrial)'], ['Translation table 1 (Standard)', 'Translation table 2 (Vertebrate Mitochondrial)'], ['Translation table 1 (Standard)', 'Translation table 2 (Vertebrate Mitochondrial)']]

And if you want the results nicely formatted into a pandas dataframe, just add:

import pandas as pd

To the top of the script, and

t = pd.DataFrame(your_tables,columns=["Nuclear","Mitochondrial"])
print(t)

To the bottom. Output of this print (if you have too many taxids use the head method instead so not everything prints):

                          Nuclear                                     Mitochondrial
0  Translation table 1 (Standard)  Translation table 5 (Invertebrate Mitochondrial)
1  Translation table 1 (Standard)    Translation table 2 (Vertebrate Mitochondrial)
2  Translation table 1 (Standard)    Translation table 2 (Vertebrate Mitochondrial)
$\endgroup$
0
$\begingroup$

You can find them here at least: https://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi

You can download the complete list of codes (using FTP) here.

However, to link a specific organism to a specific codon usage table, you'll need to do a bit of extra work. Perhaps the script here can give you a starting point?

$\endgroup$
2
  • 2
    $\begingroup$ What I was really looking for was some way to input the taxonomic id/name of an organism and have its translation table returned. NCBI does seem to have this data for specific taxa, because a button on the page you linked ('Genetic Code in Taxonomy Tree') matches organisms with translation tables. $\endgroup$
    – weddegege
    Nov 8, 2021 at 7:16
  • $\begingroup$ Yeah, you'd need to code that together using an ASN.1 parser I guess? $\endgroup$
    – Dan Bolser
    Nov 8, 2021 at 12:07

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.