tidymut.core.mutation module

class tidymut.core.mutation.AminoAcidMutation(wild_type: str, position: int, mutant_type: str, alphabet: ProteinAlphabet | None = None, metadata: Dict[str, Any] | None = None)[source]

Bases: BaseMutation

Represents an amino acid mutation (e.g., A123V)

property effect_type: Literal['synonymous', 'nonsense', 'missense']

Get the effect type of the mutation (synonymous, nonsense, or missense)

classmethod from_string(mutation_str: str, is_zero_based: bool = False, alphabet: ProteinAlphabet | None = None) AminoAcidMutation[source]

Parse mutation from string format like ‘A123V’ or ‘Ala123Val’

get_mutation_category() Literal['synonymous', 'nonsense', 'missense'][source]

Get mutation classification

is_missense() bool[source]

Check if mutation is missense (changes amino acid)

is_nonsense() bool[source]

Check if mutation introduces stop codon

is_synonymous() bool[source]

Check if mutation is synonymous (no change)

property type: str

Get the type of mutation

class tidymut.core.mutation.AminoAcidMutationSet(mutations: Sequence[AminoAcidMutation], name: str | None = None, metadata: Dict[str, Any] | None = None)[source]

Bases: MutationSet[AminoAcidMutation]

Represents a set of amino acid mutations

count_by_effect_type() Dict[str, int][source]

Count mutations by effect type

get_missense_mutations() List[AminoAcidMutation][source]

Get all missense mutations

get_nonsense_mutations() List[AminoAcidMutation][source]

Get all nonsense mutations

get_synonymous_mutations() List[AminoAcidMutation][source]

Get all synonymous mutations

has_stop_codon_mutations() bool[source]

Check if any mutations introduce stop codons

class tidymut.core.mutation.BaseMutation(wild_type: str, mutant_type: str, position: int, alphabet: BaseAlphabet | None = None, metadata: Dict[str, Any] | None = None)[source]

Bases: ABC

Base class for all mutations

abstractmethod classmethod from_string(mutation_string: str, is_zero_based: bool, alphabet: BaseAlphabet | None = None) BaseMutation[source]

Parse mutation from string format like ‘A123V’ or ‘Ala123Val’

abstractmethod get_mutation_category() str[source]

Get mutation category

abstract property type: str

Get the type of mutation

class tidymut.core.mutation.CodonMutation(wild_type: str, position: int, mutant_type: str, alphabet: BaseAlphabet | None = None, metadata: Dict[str, Any] | None = None)[source]

Bases: BaseMutation

Represents a codon mutation

classmethod from_string(mutation_str: str, is_zero_based: bool = False, alphabet: BaseAlphabet | None = None) CodonMutation[source]

Parse mutation from string format like ‘ATG123TAA’ or ‘AUG123UAA’

get_mutation_category() str[source]

Get mutation category

to_amino_acid_mutation(codon_table: CodonTable | None = None) AminoAcidMutation[source]

Convert codon mutation to amino acid mutation

property type: str

Get the type of mutation

class tidymut.core.mutation.CodonMutationSet(mutations: Sequence[CodonMutation], name: str | None = None, metadata: Dict[str, Any] | None = None)[source]

Bases: MutationSet[CodonMutation]

Represents a set of codon mutations

property seq_type: Literal['DNA', 'RNA', 'Both']

Get the sequence type (DNA, RNA, or Both) of the codon mutations

to_amino_acid_mutation_set(codon_table: CodonTable | None = None) AminoAcidMutationSet[source]

Convert all codon mutations to amino acid mutations

class tidymut.core.mutation.MutationSet(mutations: Sequence[MutationType], mutation_type: Type[MutationType] | None, name: str | None = None, metadata: Dict[str, Any] | None = None)[source]

Bases: Generic[MutationType]

Represents a set of mutations of the same type

add_mutation(mutation: MutationType) None[source]

Add a mutation to this set

filter_by_category(category: str) List[MutationType][source]

Filter mutations by category

classmethod from_string(string: str, sep: str | None = None, is_zero_based: bool = False, mutation_type: Type[MutationType] | None = None, alphabet: BaseAlphabet | None = None, name: str | None = None, metadata: Dict[str, Any] | None = None) MutationSet[source]

Create a mutation set from a string

Parameters:
  • string (str) – String containing mutations separated by delimiter

  • sep (Optional[str], default=None) – Separator to use. If None, will try to guess

  • is_zero_based (bool, default=False) – Whether origin mutation positions are zero-based

  • mutation_type (Type[MutationType], default=None) – The type of mutations to create. If None, will infer from first mutation

  • alphabet (Optional[BaseAlphabet], default=None) – Alphabet to use for mutation parsing (if applicable)

  • name (str, default=None) – Optional name for the mutation set

  • metadata (Optional[Dict[str, Any]], default=None) – Optional metadata for the mutation set

Returns:

A MutationSet created from the input string. Returns AminoAcidMutationSet for amino acid mutations, CodonMutationSet for codon mutations, or generic MutationSet for others.

Return type:

MutationSet

Raises:
  • ValueError – If string is empty, no valid mutations found, or mutations are inconsistent

  • TypeError – If mutation_type is not a subclass of BaseMutation

get_mutation_at(position: int) MutationType | None[source]

Get mutation at specified position

get_mutation_categories() Dict[str, int][source]

Get mutation category statistics

get_mutation_count() int[source]

Get number of mutations

get_positions() List[int][source]

Get all mutation positions

get_positions_set() Set[int][source]

Get all mutation positions as a set

get_sorted_by_position() List[MutationType][source]

Get mutations sorted by position without modifying the original list

has_mutation_at(position: int) bool[source]

Check if there is a mutation at specified position

is_multiple_mutations() bool[source]

Check if this contains multiple mutations

is_single_mutation() bool[source]

Check if this is a single mutation

property mutation_subtype: str

Get the specific mutation subtype (e.g., ‘amino_acid’, ‘codon_dna’, ‘codon_rna’, ‘codon_both’)

remove_mutation(position: int) bool[source]

Remove mutation at specified position, return True if removed

sort_by_position() None[source]

Sort mutations by position in ascending order

validate_all() bool[source]

Validate all mutations