codeine.MutationSpace¶
- class codeine.MutationSpace(space: CodingSpace, cds: str, *, free_positions: Collection[int] | None = None, min_nts: int | None = None, max_nts: int | None = None, min_codons: int | None = None, max_codons: int | None = None)[source]¶
Bases:
objectRepresents the subset of valid coding sequences reachable from a reference CDS by mutation under constraints.
A
MutationSpaceis defined by:A
CodingSpacecontaining the global sequence constraints.A reference CDS.
A set of codon positions that are free to mutate.
Positions that are not free are temporarily considered frozen and will remain identical to the reference CDS.
- Parameters:
space – The
CodingSpaceobject to which this given sequence should belong.cds – The parent/reference CDS.
free_positions – Which positions are allowed to change?
min_nts – Minimum number of nucleotide differences from the reference CDS.
max_nts – Maximum number of nucleotide differences from the reference CDS.
min_codons – Minimum number of codon differences from the reference CDS.
max_codons – Maximum number of codon differences from the reference CDS.
Properties¶
|
The amino acid sequence for this mutation space. |
|
The fixed codon restrictions from the underlying graph. |
|
The codon weights from the underlying graph. |
|
The left context sequence from the underlying graph. |
|
The right context sequence from the underlying graph. |
|
Codon positions that are currently free to mutate. |
|
Codon positions that are currently fixed to the reference CDS. |
|
Whether this mutation space has mutation distance constraints. |
|
Number of valid variants under the current mutation constraints. |
|
Pins currently applied to the mutation view. |
|
The translation table from the underlying graph. |
Methods¶
Remove all mutation distance constraints. |
|
|
Compile this mutation space. |
|
Check whether a coding sequence is contained in this mutation space. |
Generate all sequences in this mutation space. |
|
Freeze all codon positions. |
|
|
Freeze the given codon positions. |
|
Sample one or more variants from this mutation space. |
|
Set mutation distance constraints. |
|
Replace the current set of free positions. |
Unfreeze all codon positions. |
|
|
Unfreeze the given codon positions. |
- MutationSpace.compile() None[source]¶
Compile this mutation space.
If
compile()has not been called manually, it will automatically be called before sampling, enumeration, or counting.
- MutationSpace.contains(seq: str) bool[source]¶
Check whether a coding sequence is contained in this mutation space.
- Parameters:
seq – The sequence to check
- Return type:
True if and only if the sequence is contained in this mutation space.
- MutationSpace.enumerate() Iterator[str][source]¶
Generate all sequences in this mutation space.
- Yields:
str – A valid coding sequence.
- MutationSpace.freeze_positions(positions: Collection[int]) None[source]¶
Freeze the given codon positions.
- MutationSpace.sample(n: int | None = None) str | List[str][source]¶
Sample one or more variants from this mutation space.
- Parameters:
n – Number of sequences to sample. If omitted, return a single sequence.
- Return type:
A sampled sequence or list of sequences from this mutation space.
- MutationSpace.set_distance_constraints(min_nts: int | None = None, max_nts: int | None = None, min_codons: int | None = None, max_codons: int | None = None) None[source]¶
Set mutation distance constraints.
Distances are measured from the reference CDS and can be either nucleotide (Hamming) distances, i.e. the number of nucleotides that are different from the reference CDS, or codon distances, i.e. the number of codons that are different.