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, offset[, ...])Parse an amino acid substitution.
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, offset, alphabet=None, *, include_ambiguous=False, include_sec_pyl=False, include_stop=True)[source]#
Parse an amino acid substitution.
- Parameters:
mutation_str (
str) – Mutation in one- or three-letter notation, such as ‘A2V’ or ‘Ala2Val’.offset (
int) – Input number of the first reference residue. Subtracting it from the annotated position gives the zero-based residue index.alphabet (
Optional[ProteinAlphabet]) – Alphabet used to interpret the amino acid symbols. If supplied, it takes precedence over the alphabet options below.include_ambiguous (
bool) – Include the ambiguous residue symbols B, Z, J, and X when creating the alphabet.include_sec_pyl (
bool) – Include selenocysteine (U) and pyrrolysine (O) when creating the alphabet.include_stop (
bool) – Accept the stop symbol (*) on either side when creating the alphabet.
- 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, reject_redundant, ...])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, offset[, alphabet])Parse a mutation string by subtracting offset from its input position.
Get mutation category
- abstractmethod classmethod from_string(mutation_string, offset, alphabet=None)[source]#
Parse a mutation string by subtracting offset from its input position.
- 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, offset[, alphabet])Parse a codon substitution.
Get mutation category
to_amino_acid_mutation([codon_table])Convert codon mutation to amino acid mutation
- classmethod from_string(mutation_str, offset, alphabet=None)[source]#
Parse a codon substitution.
- Parameters:
mutation_str (
str) – Codon mutation in DNA or RNA notation, such as ‘ATG2GTG’ or ‘AUG2GUG’.offset (
int) – Input number of the first reference codon. Subtracting it from the annotated position gives the zero-based codon index.alphabet (
Optional[BaseAlphabet]) – Alphabet used to validate the codons.
- 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, reject_redundant, ...])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[MutationType: BaseMutation](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, reject_redundant, ...])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
- classmethod from_string(string, sep=None, reject_redundant=True, mutation_type=None, alphabet=None, name=None, metadata=None, *, offset, include_ambiguous=False, include_sec_pyl=False, include_stop=False)[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 guessreject_redundant (
bool) – Whether to reject synonymous/no-op mutationsmutation_type (
Optional[Type[MutationType]]) – The type of mutations to create. If None, will infer from first mutationalphabet (
Optional[BaseAlphabet]) – Alphabet used for parsing. If supplied, it takes precedence over the amino acid options below.name (
Optional[str]) – Optional name for the mutation setmetadata (
Optional[Dict[str,Any]]) – Optional metadata for the mutation setoffset (
int) – Input number of the first reference residue or codon. This value is subtracted from every annotated position.include_ambiguous (
bool) – Accept B, Z, J, and X when parsing amino acid substitutions.include_sec_pyl (
bool) – Accept selenocysteine (U) and pyrrolysine (O) when parsing amino acid substitutions.include_stop (
bool) – Accept the stop symbol (*) on either side of an amino acid substitution.
- 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[MutationType]
- get_sorted_by_position()[source]#
Get mutations sorted by position without modifying the original list
- Return type:
List[MutationType]
- 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’)