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: object

Represents the subset of valid coding sequences reachable from a reference CDS by mutation under constraints.

A MutationSpace is defined by:

  • A CodingSpace containing 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 CodingSpace object 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

aa_seq

The amino acid sequence for this mutation space.

codon_restrictions

The fixed codon restrictions from the underlying graph.

codon_weights

The codon weights from the underlying graph.

context_l

The left context sequence from the underlying graph.

context_r

The right context sequence from the underlying graph.

free_positions

Codon positions that are currently free to mutate.

frozen_positions

Codon positions that are currently fixed to the reference CDS.

has_distance_constraints

Whether this mutation space has mutation distance constraints.

n_valid_variants

Number of valid variants under the current mutation constraints.

pinned_codons

Pins currently applied to the mutation view.

translation_table

The translation table from the underlying graph.

Methods

clear_distance_constraints()

Remove all mutation distance constraints.

contains(seq)

Check whether a coding sequence is contained in this mutation space.

enumerate()

Generate all sequences in this mutation space.

freeze_all()

Freeze all codon positions.

freeze_positions(positions)

Freeze the given codon positions.

sample([n])

Sample one or more variants from this mutation space.

set_distance_constraints([min_nts, max_nts, ...])

Set mutation distance constraints.

set_free_positions(positions)

Replace the current set of free positions.

unfreeze_all()

Unfreeze all codon positions.

unfreeze_positions(positions)

Unfreeze the given codon positions.

MutationSpace.clear_distance_constraints() None[source]

Remove all mutation distance constraints.

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() Generator[str, None, None][source]

Generate all sequences in this mutation space.

Yields:

str – A valid coding sequence.

MutationSpace.freeze_all() None[source]

Freeze all codon positions.

MutationSpace.freeze_positions(positions: Collection[int]) None[source]

Freeze the given codon positions.

MutationSpace.sample(n: int | None = None) 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 string sequence 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 (Hammming) 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.

MutationSpace.set_free_positions(positions: Collection[int]) None[source]

Replace the current set of free positions.

MutationSpace.unfreeze_all() None[source]

Unfreeze all codon positions.

MutationSpace.unfreeze_positions(positions: Collection[int]) None[source]

Unfreeze the given codon positions.