SenseCodonAlphabet#
- class SenseCodonAlphabet(words: tuple[str, ...], monomers: CharAlphabet[str], gap: str | None = None)#
represents the sense-codons of a GeneticCode
- Attributes:
- gap_char
- gap_index
missing_charnot supported on CodonAlphabet
missing_indexnot supported on CodonAlphabet
- moltype
motif_lenalways 3 for codon alphabets
num_canonicalreturns the number of canonical states
Methods
count(value, /)Return number of occurrences of value.
from_index(index)returns a single codon from an index
from_indices(indices)returns a list of codons from a numpy array of indices
from_rich_dict(data)returns an instance from a serialised dictionary
index(value[, start, stop])Return first index of value.
is_valid(seq)seq is valid for alphabet
to_index(codon[, validate])encodes a codon as a single integer
to_indices(seq[, validate])returns a sequence of codon indices
to_json()returns a serialisable string
to_rich_dict([for_pickle])returns a serialisable dictionary
with_gap_motif(**kwargs)returns a new SenseCodonAlphabet with the gap motif '---' added
- count(value, /)#
Return number of occurrences of value.
- from_index(index: int) str#
returns a single codon from an index
- from_indices(indices: ndarray[tuple[Any, ...], dtype[integer]]) list[str]#
returns a list of codons from a numpy array of indices
- classmethod from_rich_dict(data: dict[str, Any]) SenseCodonAlphabet#
returns an instance from a serialised dictionary
- property gap_char: str | None#
- property gap_index: int | None#
- index(value, start=0, stop=sys.maxsize, /)#
Return first index of value.
Raises ValueError if the value is not present.
- is_valid(seq: str | bytes | ndarray[tuple[Any, ...], dtype[integer]]) bool#
seq is valid for alphabet
- property missing_char: None#
not supported on CodonAlphabet
- property missing_index: None#
not supported on CodonAlphabet
- property motif_len: int#
always 3 for codon alphabets
- property num_canonical: int#
returns the number of canonical states
- to_index(codon: str, validate: bool = True) int#
encodes a codon as a single integer
- Parameters:
- codon
string to be converted into index
- validate
raises an AlphabetError if the resulting sequence does not satisfy self.is_valid()
- Raises:
- ValueError
if codon is not of length 3
- AlphabetError
if codon contains an invalid nucleotide or is not present in the code
- to_indices(seq: str | list[str] | tuple[str, ...] | ndarray[tuple[Any, ...], dtype[integer]], validate: bool = True) ndarray[tuple[Any, ...], dtype[integer]]#
returns a sequence of codon indices
- Parameters:
- seq
input sequence to be converted to a numpy array of uint
- validate
raises an AlphabetError if the resulting sequence does not satisfy self.is_valid()
- Raises:
- TypeError
if seq is unsupported type
- AlphabetError
if resulting sequence is not valid
- to_json() str#
returns a serialisable string
- to_rich_dict(for_pickle: bool = False) dict[str, Any]#
returns a serialisable dictionary
- with_gap_motif(**kwargs: Any) Self#
returns a new SenseCodonAlphabet with the gap motif ‘—’ added
Notes
kwargs is for compatibility with the ABC method