mutcleaner.core.mutation#

Classes

AminoAcidMutation(wild_type, position, ...)

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

AminoAcidMutationSet(mutations[, name, metadata])

Represents a set of amino acid mutations

BaseMutation(wild_type, mutant_type, position)

Base class for all mutations

CodonMutation(wild_type, position, mutant_type)

Represent a codon substitution.

CodonMutationSet(mutations[, name, metadata])

Represents a set of codon mutations

MutationSet(mutations, mutation_type[, ...])

Represents a set of mutations of the same type

class mutcleaner.core.mutation.AminoAcidMutation(wild_type, position, mutant_type, alphabet=None, metadata=None)[source]#

Bases: BaseMutation

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

Attributes:
effect_type

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

type

Get the type of mutation

Methods

from_string(mutation_str[, is_zero_based, ...])

Parse mutation from string format like 'A123V' or 'Ala123Val'

get_mutation_category()

Get mutation classification

is_missense()

Check if mutation is missense (changes amino acid)

is_nonsense()

Check if mutation introduces stop codon

is_synonymous()

Check if mutation is synonymous (no change)

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

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

classmethod from_string(mutation_str, is_zero_based=False, alphabet=None)[source]#

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

Return type:

AminoAcidMutation

get_mutation_category()[source]#

Get mutation classification

Return type:

Literal['synonymous', 'nonsense', 'missense']

is_missense()[source]#

Check if mutation is missense (changes amino acid)

Return type:

bool

is_nonsense()[source]#

Check if mutation introduces stop codon

Return type:

bool

is_synonymous()[source]#

Check if mutation is synonymous (no change)

Return type:

bool

property type: str#

Get the type of mutation

class mutcleaner.core.mutation.AminoAcidMutationSet(mutations, name=None, metadata=None)[source]#

Bases: MutationSet[AminoAcidMutation]

Represents a set of amino acid mutations

Attributes:
mutation_subtype

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

Methods

add_mutation(mutation)

Add a mutation to this set

count_by_effect_type()

Count mutations by effect type

filter_by_category(category)

Filter mutations by category

from_string(string[, sep, is_zero_based, ...])

Create a mutation set from a string

get_missense_mutations()

Get all missense mutations

get_mutation_at(position)

Get mutation at specified position

get_mutation_categories()

Get mutation category statistics

get_mutation_count()

Get number of mutations

get_nonsense_mutations()

Get all nonsense mutations

get_positions()

Get all mutation positions

get_positions_set()

Get all mutation positions as a set

get_sorted_by_position()

Get mutations sorted by position without modifying the original list

get_synonymous_mutations()

Get all synonymous mutations

has_mutation_at(position)

Check if there is a mutation at specified position

has_stop_codon_mutations()

Check if any mutations introduce stop codons

is_multiple_mutations()

Check if this contains multiple mutations

is_single_mutation()

Check if this is a single mutation

remove_mutation(position)

Remove mutation at specified position, return True if removed

sort_by_position()

Sort mutations by position in ascending order

validate_all()

Validate all mutations

count_by_effect_type()[source]#

Count mutations by effect type

Return type:

Dict[str, int]

get_missense_mutations()[source]#

Get all missense mutations

Return type:

List[AminoAcidMutation]

get_nonsense_mutations()[source]#

Get all nonsense mutations

Return type:

List[AminoAcidMutation]

get_synonymous_mutations()[source]#

Get all synonymous mutations

Return type:

List[AminoAcidMutation]

has_stop_codon_mutations()[source]#

Check if any mutations introduce stop codons

Return type:

bool

class mutcleaner.core.mutation.BaseMutation(wild_type, mutant_type, position, alphabet=None, metadata=None)[source]#

Bases: ABC

Base class for all mutations

Attributes:
type

Get the type of mutation

Methods

from_string(mutation_string, is_zero_based)

Parse mutation from string format like 'A123V' or 'Ala123Val'

get_mutation_category()

Get mutation category

abstractmethod classmethod from_string(mutation_string, is_zero_based, alphabet=None)[source]#

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

Return type:

BaseMutation

abstractmethod get_mutation_category()[source]#

Get mutation category

Return type:

str

abstract property type: str#

Get the type of mutation

class mutcleaner.core.mutation.CodonMutation(wild_type, position, mutant_type, alphabet=None, metadata=None)[source]#

Bases: BaseMutation

Represent a codon substitution.

The position attribute is always stored as a zero-based codon index relative to the coding sequence. The corresponding nucleotide interval is position * 3 : position * 3 + 3.

Attributes:
nucleotide_end

Return the exclusive nucleotide end of this codon.

nucleotide_start

Return the zero-based nucleotide start of this codon.

type

Get the type of mutation

Methods

from_string(mutation_str[, is_zero_based, ...])

Parse mutation from string format like 'ATG123TAA' or 'AUG123UAA'

get_mutation_category()

Get mutation category

to_amino_acid_mutation([codon_table])

Convert codon mutation to amino acid mutation

classmethod from_string(mutation_str, is_zero_based=False, alphabet=None)[source]#

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

Return type:

CodonMutation

get_mutation_category()[source]#

Get mutation category

Return type:

str

property nucleotide_end: int#

Return the exclusive nucleotide end of this codon.

property nucleotide_start: int#

Return the zero-based nucleotide start of this codon.

to_amino_acid_mutation(codon_table=None)[source]#

Convert codon mutation to amino acid mutation

Return type:

AminoAcidMutation

property type: str#

Get the type of mutation

class mutcleaner.core.mutation.CodonMutationSet(mutations, name=None, metadata=None)[source]#

Bases: MutationSet[CodonMutation]

Represents a set of codon mutations

Attributes:
mutation_subtype

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

seq_type

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

Methods

add_mutation(mutation)

Add a mutation to this set

filter_by_category(category)

Filter mutations by category

from_string(string[, sep, is_zero_based, ...])

Create a mutation set from a string

get_mutation_at(position)

Get mutation at specified position

get_mutation_categories()

Get mutation category statistics

get_mutation_count()

Get number of mutations

get_positions()

Get all mutation positions

get_positions_set()

Get all mutation positions as a set

get_sorted_by_position()

Get mutations sorted by position without modifying the original list

has_mutation_at(position)

Check if there is a mutation at specified position

is_multiple_mutations()

Check if this contains multiple mutations

is_single_mutation()

Check if this is a single mutation

remove_mutation(position)

Remove mutation at specified position, return True if removed

sort_by_position()

Sort mutations by position in ascending order

to_amino_acid_mutation_set([codon_table])

Convert all codon mutations to amino acid mutations

validate_all()

Validate all 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=None)[source]#

Convert all codon mutations to amino acid mutations

Return type:

AminoAcidMutationSet

class mutcleaner.core.mutation.MutationSet(mutations, mutation_type, name=None, metadata=None)[source]#

Bases: Generic[MutationType]

Represents a set of mutations of the same type

Attributes:
mutation_subtype

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

Methods

add_mutation(mutation)

Add a mutation to this set

filter_by_category(category)

Filter mutations by category

from_string(string[, sep, is_zero_based, ...])

Create a mutation set from a string

get_mutation_at(position)

Get mutation at specified position

get_mutation_categories()

Get mutation category statistics

get_mutation_count()

Get number of mutations

get_positions()

Get all mutation positions

get_positions_set()

Get all mutation positions as a set

get_sorted_by_position()

Get mutations sorted by position without modifying the original list

has_mutation_at(position)

Check if there is a mutation at specified position

is_multiple_mutations()

Check if this contains multiple mutations

is_single_mutation()

Check if this is a single mutation

remove_mutation(position)

Remove mutation at specified position, return True if removed

sort_by_position()

Sort mutations by position in ascending order

validate_all()

Validate all mutations

add_mutation(mutation)[source]#

Add a mutation to this set

Return type:

None

filter_by_category(category)[source]#

Filter mutations by category

Return type:

List[TypeVar(MutationType, bound= BaseMutation)]

classmethod from_string(string, sep=None, is_zero_based=False, reject_redundant=True, reject_nonsense=True, mutation_type=None, alphabet=None, name=None, metadata=None)[source]#

Create a mutation set from a string

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

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

  • is_zero_based (bool) – Whether origin mutation positions are zero-based

  • reject_redundant (bool) – Whether to reject synonymous/no-op mutations

  • reject_nonsense (bool) – Whether to reject nonsense mutations.

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

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

  • name (Optional[str]) – Optional name for the mutation set

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

Return type:

MutationSet

Returns:

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

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)[source]#

Get mutation at specified position

Return type:

Optional[TypeVar(MutationType, bound= BaseMutation)]

get_mutation_categories()[source]#

Get mutation category statistics

Return type:

Dict[str, int]

get_mutation_count()[source]#

Get number of mutations

Return type:

int

get_positions()[source]#

Get all mutation positions

Return type:

List[int]

get_positions_set()[source]#

Get all mutation positions as a set

Return type:

Set[int]

get_sorted_by_position()[source]#

Get mutations sorted by position without modifying the original list

Return type:

List[TypeVar(MutationType, bound= BaseMutation)]

has_mutation_at(position)[source]#

Check if there is a mutation at specified position

Return type:

bool

is_multiple_mutations()[source]#

Check if this contains multiple mutations

Return type:

bool

is_single_mutation()[source]#

Check if this is a single mutation

Return type:

bool

property mutation_subtype: str#

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

remove_mutation(position)[source]#

Remove mutation at specified position, return True if removed

Return type:

bool

sort_by_position()[source]#

Sort mutations by position in ascending order

Return type:

None

validate_all()[source]#

Validate all mutations

Return type:

bool