<p>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: <a href="https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi" rel="nofollow noreferrer">https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi</a></p>
<p>If I search a taxid into the website, eg 7227, the page for <em>Drosophila melanogaster</em> will come up but the URL will remain unmodified. However, you can get a modified URL specific to a taxid by appending ?mode=Info&amp;id=<em>your_taxid</em> to the above URL. Eg for <em>D. melanogaster</em> again, it has this unique URL for its Taxonomy browser page: <a href="https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&amp;id=7227" rel="nofollow noreferrer">https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&amp;id=7227</a></p>
<p>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 <em>D. melanogaster</em> with this approach, use the urllib package in Python.</p>
<pre><code>import urllib.request
url = &quot;https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&amp;id=7227&quot;
weburl = urllib.request.urlopen(url)
data = weburl.read().decode(&quot;utf-8&quot;)  # decode because page returned in binary

data_s = data.split('&lt;')

for d in data_s:
    if &quot;Translation table&quot; in d:
        print(d.split('&gt;')[1])
</code></pre>
<p>The output is:</p>
<pre><code>Translation table 1 (Standard)
Translation table 5 (Invertebrate Mitochondrial)
</code></pre>
<p>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.</p>
<pre><code>import urllib.request

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

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

    data_s = data.split('&lt;')

    tr_table = []

    for d in data_s:
        if &quot;Translation table&quot; in d:
            tr_table += [d.split('&gt;')[1]]

    return tr_table

your_tables = list(map(get_translation_table,my_taxids))

print(your_tables)
</code></pre>
<p>The output is:</p>
<pre><code>[['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)']]
</code></pre>
<p>And if you want the results nicely formatted into a pandas dataframe, just add:</p>
<pre><code>import pandas as pd
</code></pre>
<p>To the top of the script, and</p>
<pre><code>t = pd.DataFrame(your_tables,columns=[&quot;Nuclear&quot;,&quot;Mitochondrial&quot;])
print(t)
</code></pre>
<p>To the bottom. Output of this print (if you have too many taxids use the head method instead so not everything prints):</p>
<pre><code>                          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)
</code></pre>

CC BY-SA 4.0
2022-12-04T18:37:56.807Z
2022-12-04T18:37:56.807Z
arara
<p>You can find them here at least:
<a href="https://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi" rel="nofollow noreferrer">https://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi</a></p>
<p>You can download the complete list of codes (using FTP) <a href="ftp://ftp.ncbi.nih.gov/entrez/misc/data/gc.prt" rel="nofollow noreferrer">here</a>.</p>
<p>However, to link a specific organism to a specific codon usage table, you'll need to do a bit of extra work. Perhaps the <a href="https://github.com/sleyn/get_taxonomy_by_NCBI_TaxID" rel="nofollow noreferrer">script here</a> can give you a starting point?</p>

CC BY-SA 4.0
2021-11-08T07:16:27.557Z
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.
weddegege
CC BY-SA 4.0
2021-11-08T12:07:31.513Z
Yeah, you'd need to code that together using an ASN.1 parser I guess?
Dan Bolser
CC BY-SA 4.0
2021-11-05T14:37:46.273Z
2021-11-08T12:14:48.660Z
2021-11-08T12:14:48.660Z
Dan Bolser
<p>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?</p>
<p>(packages in R, Python etc. would be fine too)</p>

<phylogenetics><entrez>
Getting translation table of organisms through Entrez direct (or other CLIs)
# Getting translation table of organisms through Entrez direct (or other CLIs)

(Asked by: username_0 on 2021-11-05)

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)

**Tags:** phylogenetics, entrez

---

## 2 answers

### Answer by username_1 on 2022-12-04. Score: 1

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)


---

### Answer by username_2 on 2021-11-05. Score: 0

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](ftp://ftp.ncbi.nih.gov/entrez/misc/data/gc.prt).

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](https://github.com/sleyn/get_taxonomy_by_NCBI_TaxID) can give you a starting point?

> **Comments:**
> **username_0**: 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.  
> **username_2**: Yeah, you'd need to code that together using an ASN.1 parser I guess?  

---

