mutcleaner.core.mutation#
Classes
|
Represents an amino acid mutation (e.g., A123V) |
|
Represents a set of amino acid mutations |
|
Base class for all mutations |
|
Represent a codon substitution. |
|
Represents a set of codon mutations |
|
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:
BaseMutationRepresents an amino acid mutation (e.g., A123V)
- Attributes:
effect_typeGet the effect type of the mutation (synonymous, nonsense, or missense)
typeGet the type of mutation
Methods
from_string(mutation_str[, is_zero_based, ...])Parse mutation from string format like 'A123V' or 'Ala123Val'
Get mutation classification
Check if mutation is missense (changes amino acid)
Check if mutation introduces stop codon
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:
- get_mutation_category()[source]#
Get mutation classification
- Return type:
Literal['synonymous','nonsense','missense']
- 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_subtypeGet 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 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 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 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 all synonymous mutations
has_mutation_at(position)Check if there is a mutation at specified position
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
- 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]
- class mutcleaner.core.mutation.BaseMutation(wild_type, mutant_type, position, alphabet=None, metadata=None)[source]#
Bases:
ABCBase class for all mutations
- Attributes:
typeGet the type of mutation
Methods
from_string(mutation_string, is_zero_based)Parse mutation from string format like 'A123V' or 'Ala123Val'
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:
- 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:
BaseMutationRepresent a codon substitution.
The
positionattribute is always stored as a zero-based codon index relative to the coding sequence. The corresponding nucleotide interval isposition * 3 : position * 3 + 3.- Attributes:
nucleotide_endReturn the exclusive nucleotide end of this codon.
nucleotide_startReturn the zero-based nucleotide start of this codon.
typeGet the type of mutation
Methods
from_string(mutation_str[, is_zero_based, ...])Parse mutation from string format like 'ATG123TAA' or 'AUG123UAA'
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:
- 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:
- 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_subtypeGet the specific mutation subtype (e.g., ‘amino_acid’, ‘codon_dna’, ‘codon_rna’, ‘codon_both’)
seq_typeGet 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
- 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_subtypeGet 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 category statistics
Get number of mutations
Get all mutation positions
Get all mutation positions as a set
Get mutations sorted by position without modifying the original list
has_mutation_at(position)Check if there is a mutation at specified position
Check if this contains multiple mutations
Check if this is a single mutation
remove_mutation(position)Remove mutation at specified position, return True if removed
Sort mutations by position in ascending order
Validate all mutations
- 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 delimitersep (
Optional[str]) – Separator to use. If None, will try to guessis_zero_based (
bool) – Whether origin mutation positions are zero-basedreject_redundant (
bool) – Whether to reject synonymous/no-op mutationsreject_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 mutationalphabet (
Optional[BaseAlphabet]) – Alphabet to use for mutation parsing (if applicable)name (
Optional[str]) – Optional name for the mutation setmetadata (
Optional[Dict[str,Any]]) – Optional metadata for the mutation set
- Return type:
- 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_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
- property mutation_subtype: str#
Get the specific mutation subtype (e.g., ‘amino_acid’, ‘codon_dna’, ‘codon_rna’, ‘codon_both’)