codeine.CodonWeights

class codeine.CodonWeights(weights: Dict[str, Dict[str, float | int]])[source]

Bases: object

A class to store codon weights, for example codon usage information for a specific organism.

Input weights are grouped by amino acid:

{
    'A': {'GCT': 1.0, 'GCC': 1.0, ...},
    'R': {'CGT': 1.0, 'CGC': 1.0, ...},
    ...
}

Stored weights are flat:

{
    'GCT': 0.25,
    'GCC': 0.25,
    ...
}

Weights are normalised per amino acid. Weights can be inputted as either RNA or DNA, they will be normalised later.

Parameters:

weights

Codon weights grouped by amino acid.

Example:

{
    'A': {'GCT': 1.0, 'GCC': 1.0, 'GCA': 1.0, 'GCG': 1.0},
    'R': {'CGT': 1.0, 'CGC': 1.0, 'CGA': 1.0,
          'CGG': 1.0, 'AGA': 1.0, 'AGG': 1.0},
    ...
}

Methods

arabidopsis()

Construct a CodonWeights object with codon probabilities corresponding to A.

by_aa(aa)

Return the codon weights corresponding to a particular AA.

drosophila()

Construct a CodonWeights object with codon probabilities corresponding to D.

ecoli()

Construct a CodonWeights object with codon probabilities corresponding to E.

for_table(table)

Resolve this CodonWeights class against a translation table, i.e. check that the codons match and normalise to RNA/DNA, and return the resolved version.

human()

Construct a CodonWeights object with codon probabilities corresponding to Human.

mouse()

Construct a CodonWeights object with codon probabilities corresponding to Mouse.

restrict(table)

Return compatible translation table and codon weights containing only codons with positive weight.

threshold(min_weight)

Set codon weights below a minimum value to zero.

uniform([table])

Construct a CodonWeights object with uniform codon weights for a given translation table.

yeast()

Construct a CodonWeights object with codon probabilities corresponding to 'yeast'.

classmethod CodonWeights.arabidopsis() CodonWeights[source]

Construct a CodonWeights object with codon probabilities corresponding to A. thaliana.

Weights are based on codon usage counts from GenScript:

https://www.genscript.com/tools/codon-frequency-table

Return type:

A CodonWeights object corresponding to Arabidopsis thaliana.

CodonWeights.by_aa(aa: str) Dict[str, float][source]

Return the codon weights corresponding to a particular AA.

Parameters:

aa – The amino acid of interest.

Return type:

A set of codon weights keyed by codon.

classmethod CodonWeights.drosophila() CodonWeights[source]

Construct a CodonWeights object with codon probabilities corresponding to D. melanogaster.

Weights are based on codon usage counts from GenScript:

https://www.genscript.com/tools/codon-frequency-table

Return type:

A CodonWeights object corresponding to Drosophila melanogaster.

classmethod CodonWeights.ecoli() CodonWeights[source]

Construct a CodonWeights object with codon probabilities corresponding to E. coli.

Weights are based on codon usage counts from GenScript:

https://www.genscript.com/tools/codon-frequency-table

Return type:

A CodonWeights object corresponding to E. Coli

CodonWeights.for_table(table: TranslationTable) CodonWeights[source]

Resolve this CodonWeights class against a translation table, i.e. check that the codons match and normalise to RNA/DNA, and return the resolved version.

Parameters:

table – The translation table to resolve against.

Return type:

A resolved CodonWeights object.

classmethod CodonWeights.human() CodonWeights[source]

Construct a CodonWeights object with codon probabilities corresponding to Human.

Weights are based on codon usage counts from GenScript:

https://www.genscript.com/tools/codon-frequency-table

Return type:

A CodonWeights object corresponding to Human.

classmethod CodonWeights.mouse() CodonWeights[source]

Construct a CodonWeights object with codon probabilities corresponding to Mouse.

Weights are based on codon usage counts from GenScript:

https://www.genscript.com/tools/codon-frequency-table

Return type:

A CodonWeights object corresponding to Mouse.

CodonWeights.restrict(table: TranslationTable) Tuple[TranslationTable, CodonWeights][source]

Return compatible translation table and codon weights containing only codons with positive weight.

The weights are first resolved against the supplied translation table. Codons with zero weight are then removed from both the table and the returned weights.

Parameters:

table – The translation table to restrict.

Returns:

A matched translation table and codon weights containing only codons with positive weight.

Return type:

TranslationTable and CodonWeights

CodonWeights.threshold(min_weight: float) CodonWeights[source]

Set codon weights below a minimum value to zero.

The threshold is applied to the normalised (fractional) weight of each codon within its amino acid. Remaining non-zero weights are then renormalised.

Parameters:

min_weight – Minimum codon weight to retain, between 0 and 1.

Returns:

  • A new CodonWeights object with weights below the threshold set to

  • zero. If no weights are changed, return this object unchanged.

classmethod CodonWeights.uniform(table: TranslationTable | None = None) CodonWeights[source]

Construct a CodonWeights object with uniform codon weights for a given translation table.

Parameters:

table – The reference table. If blank, use the standard genetic code.

Return type:

A uniform CodonWeights object.

classmethod CodonWeights.yeast() CodonWeights[source]

Construct a CodonWeights object with codon probabilities corresponding to ‘yeast’.

Weights are based on codon usage counts from GenScript:

https://www.genscript.com/tools/codon-frequency-table

Return type:

A CodonWeights object corresponding to S. cerevisiea