CodonTable#

class biotite.sequence.CodonTable(codon_dict, starts)[source]#

Bases: object

A CodonTable maps a codon (sequence of 3 nucleotides) to an amino acid. It also defines start codons. A CodonTable takes/outputs either the symbols or code of the codon/amino acid.

Furthermore, this class is able to give a list of codons that corresponds to a given amino acid.

The load() method allows loading of NCBI codon tables.

Objects of this class are immutable.

Parameters:
codon_dictdict of (str -> str)

A dictionary that maps codons to amino acids. The keys must be strings of length 3 and the values strings of length 1 (all upper case). The dictionary must provide entries for all 64 possible codons.

startsiterable object of str

The start codons. Each entry must be a string of length 3 (all upper case).

Examples

Get the amino acid coded by a given codon (symbol and code):

>>> table = CodonTable.default_table()
>>> print(table["ATG"])
M
>>> print(table[(1,2,3)])
14

Get the codons coding for a given amino acid (symbol and code):

>>> table = CodonTable.default_table()
>>> print(table["M"])
('ATG',)
>>> print(table[14])
((0, 2, 0), (0, 2, 2), (1, 2, 0), (1, 2, 1), (1, 2, 2), (1, 2, 3))
codon_dict(code=False)#

Get the codon to amino acid mappings dictionary.

Parameters:
codebool

If true, the dictionary contains keys and values as code. Otherwise, the dictionary contains strings for codons and amino acid. (Default: False)

Returns:
codon_dictdict

The dictionary mapping codons to amino acids.

static default_table()#

The default codon table. The table is equal to the NCBI “Standard” codon table, with the difference that only “ATG” is a start codon.

Returns:
tableCodonTable

The default codon table.

is_start_codon(codon_codes)#
static load(table_name)#

Load a NCBI codon table.

Parameters:
table_namestr or int

If a string is given, it is interpreted as official NCBI codon table name (e.g. “Vertebrate Mitochondrial”). An integer is interpreted as NCBI codon table ID.

Returns:
tableCodonTable

The NCBI codon table.

map_codon_codes(codon_codes)#

Efficiently map multiple codons to the corresponding amino acids.

Parameters:
codon_codesndarray, dtype=int, shape=(n,3)

The codons to be translated into amino acids. The codons are given as symbol codes. n is the amount of codons.

Returns:
aa_codesndarray, dtype=int, shape=(n,)

The amino acids as symbol codes.

Examples

>>> dna = NucleotideSequence("ATGGTTTAA")
>>> sequence_code = dna.code
>>> print(sequence_code)
[0 3 2 2 3 3 3 0 0]
>>> # Reshape to get codons
>>> codon_codes = sequence_code.reshape(-1, 3)
>>> print(codon_codes)
[[0 3 2]
 [2 3 3]
 [3 0 0]]
>>> # Map to amino acids
>>> aa_codes = CodonTable.default_table().map_codon_codes(codon_codes)
>>> print(aa_codes)
[10 17 23]
>>> # Put into a protein sequence
>>> protein = ProteinSequence()
>>> protein.code = aa_codes
>>> print(protein)
MV*
start_codons(code=False)#

Get the start codons of the codon table.

Parameters:
codebool

If true, the code will be returned instead of strings. (Default: False)

Returns:
start_codonstuple

The start codons. Contains strings or tuples, depending on the code parameter.

static table_names()#

The possible codon table names for load().

Returns:
nameslist of str

List of valid codon table names.

with_codon_mappings(codon_dict)#

Create an new CodonTable with partially changed codon mappings.

Parameters:
codon_dictdict of (str -> str)

The changed codon mappings.

Returns:
new_tableCodonTable

The codon table with changed codon mappings.

with_start_codons(starts)#

Create an new CodonTable with the same codon mappings, but changed start codons.

Parameters:
startsiterable object of str

The new start codons.

Returns:
new_tableCodonTable

The codon table with the new start codons.