codeine.CodingSpace¶
- class codeine.CodingSpace(aa_seq: str, *, translation_table: TranslationTable | None = None, rna: bool | None = None, codon_restrictions: Dict[int, str | Sequence[str]] | None = None, forbidden_motifs: str | RestrictionSite | Sequence[str | RestrictionSite] | None = None, max_homopolymer: int | None = None, context_l: str = '', context_r: str = '', codon_weights: CodonWeights | None = None, seed: None | int | float | str | bytes | bytearray = None)[source]¶
Bases:
objectRepresents a space of valid coding sequences for a protein under constraints.
- Parameters:
aa_seq – The amino acid sequence.
translation_table – The translation table to use. Leave blank to use standard table.
rna – Whether to use RNA. If false or blank, use DNA.
codon_restrictions – Any codon restrictions in the format e.g.
{4: 'TCC'}or{5: ['AGT', 'AGC']}. Positions are 1-based.forbidden_motifs – Forbidden motifs, either as strings or as
codeine.RestrictionSite.max_homopolymer – The maximum allowed length of nucleotide homopolymer
context_l – The context sequence to the left of the coding sequence.
context_r – The context sequence to the right of the coding sequence.
codon_weights – The codon weights to use. Leave blank to sample uniformly.
seed – Seed used to initialise the random number generator for sampling.
Properties¶
|
The amino acid sequence for this coding space. |
|
The fixed codon restrictions from the underlying graph. |
|
The codon weights being used in this space. |
|
The left context sequence from the underlying graph. |
|
The right context sequence from the underlying graph. |
|
The number of valid sequences in this space. |
|
Temporary codon pins currently applied to this coding space. |
|
The translation table being used in this space. |
Methods¶
Remove all forbidden motifs from this coding space. |
|
Remove the maximum homopolymer constraint from this coding space. |
|
Remove all temporary codon pins from this coding space. |
|
|
Check whether a coding sequence is contained in this coding space. |
Generate all sequences in this space. |
|
|
Load a coding space from disc. |
|
Return a space of mutants relative to a given coding sequence, i.e. a space derived from this one but which fixes the sequence on all but the specified positions. |
|
Pin temporary codons in this coding space. |
|
Sample one or more variants from this coding space. |
|
Save this coding space to disc. |
|
Set the forbidden motifs for this coding space. |
|
Set the maximum allowed homopolymer length. |
|
Replace all temporary codon pins on this coding space. |
|
Remove temporary codon pins by position. |
- CodingSpace.clear_forbidden_motifs() None[source]¶
Remove all forbidden motifs from this coding space.
- CodingSpace.clear_max_homopolymer() None[source]¶
Remove the maximum homopolymer constraint from this coding space.
- CodingSpace.contains(seq: str) bool[source]¶
Check whether a coding sequence is contained in this coding space.
- Parameters:
seq – The sequence to check.
- Return type:
True if and only if the sequence is contained in this coding space.
- CodingSpace.enumerate() Generator[str, None, None][source]¶
Generate all sequences in this space. If there are many (and often there are astronomically many), one would not expect to reach the ‘end’. However for smaller sequence spaces, such as mutation spaces, it’s quite possible to get there.
- Yields:
str – A valid coding sequence.
- classmethod CodingSpace.load(path) CodingSpace[source]¶
Load a coding space from disc.
- CodingSpace.mutants(cds: str, free_positions: Sequence[int] | None = None, min_nts: int | None = None, max_nts: int | None = None, min_codons: int | None = None, max_codons: int | None = None) MutationSpace[source]¶
Return a space of mutants relative to a given coding sequence, i.e. a space derived from this one but which fixes the sequence on all but the specified positions.
- Parameters:
cds – The sequence to mutate.
free_positions – The positions that are allowed to vary.
min_nts – The min nucleotide (Hamming) distance relative to the reference sequence.
max_nts – The max nucleotide (Hamming) distance relative to the reference sequence.
min_codons – The min number of changed codons relative to the reference sequence.
max_codons – The max number of changed codons relative to the reference sequence.
- CodingSpace.pin_codons(pinned_codons: Dict[int, str]) None[source]¶
Pin temporary codons in this coding space.
- Parameters:
pinned_codons – A dict specifying which codons to pin, by position.
- CodingSpace.sample(n: int | None = None) str[source]¶
Sample one or more variants from this coding space.
- Parameters:
n – Number of sequences to sample. If omitted, return a single sequence.
- Return type:
A sampled string sequence from this coding space.
- CodingSpace.set_forbidden_motifs(forbidden_motifs: str | RestrictionSite | Sequence[str | RestrictionSite]) None[source]¶
Set the forbidden motifs for this coding space.
- Parameters:
forbidden_motifs – Motifs that should be forbidden in generated sequences.
- CodingSpace.set_max_homopolymer(max_homopolymer: int | None) None[source]¶
Set the maximum allowed homopolymer length.
- Parameters:
max_homopolymer – The longest allowed repeated run of one nucleotide, or None for no limit.