mutcleaner.core.sequence#

Classes

BaseSequence(sequence[, alphabet, name, ...])

Base class for biological sequences

DNASequence(sequence[, alphabet, name, metadata])

DNA sequence with nucleotide validation

ProteinSequence(sequence[, alphabet, name, ...])

Protein sequence with amino acid validation

RNASequence(sequence[, alphabet, name, metadata])

RNA sequence with nucleotide validation

class mutcleaner.core.sequence.BaseSequence(sequence, alphabet=None, name=None, metadata=None)[source]#

Bases: ABC

Base class for biological sequences

Methods

apply_mutation(mutation)

Apply a mutation or set of mutations to the sequence and return a new sequence.

default_alphabet()

Subclasses may override this method to provide a default alphabet.

get_subsequence(start[, end])

get subsequence (0-indexed, inclusive)

infer_mutation(other)

Infer a mutation that leads to a specific sequence

apply_mutation(mutation)[source]#

Apply a mutation or set of mutations to the sequence and return a new sequence.

Parameters:

mutation (Union[BaseMutation, MutationSet, MutationSet[BaseMutation]]) – A single mutation or a set of mutations to apply

Return type:

TypeVar(SequenceType, bound= BaseSequence)

Returns:

A new sequence with the mutation(s) applied

Raises:
  • ValueError – If mutation position is invalid or mutation is incompatible

  • TypeError – If mutation type is not supported

classmethod default_alphabet()[source]#

Subclasses may override this method to provide a default alphabet.

By default, it returns None, indicating no default is provided and callers must pass alphabet explicitly.

Return type:

Optional[BaseAlphabet]

get_subsequence(start, end=None)[source]#

get subsequence (0-indexed, inclusive)

Return type:

TypeVar(SequenceType, bound= BaseSequence)

infer_mutation(other)[source]#

Infer a mutation that leads to a specific sequence

Return type:

MutationSet

class mutcleaner.core.sequence.DNASequence(sequence, alphabet=None, name=None, metadata=None)[source]#

Bases: BaseSequence

DNA sequence with nucleotide validation

Methods

apply_mutation(mutation)

Apply a mutation or set of mutations to the sequence and return a new sequence.

default_alphabet()

Subclasses may override this method to provide a default alphabet.

get_subsequence(start[, end])

get subsequence (0-indexed, inclusive)

infer_mutation(other)

Infer a mutation that leads to a specific sequence

reverse_complement()

Get reverse complement of DNA sequence

transcribe()

Transcribe DNA sequence into RNA sequence

translate([codon_table, start_at_first_met, ...])

Translate DNA sequence into amino acid sequence using this codon table.

classmethod default_alphabet()[source]#

Subclasses may override this method to provide a default alphabet.

By default, it returns None, indicating no default is provided and callers must pass alphabet explicitly.

Return type:

Optional[BaseAlphabet]

reverse_complement()[source]#

Get reverse complement of DNA sequence

Return type:

DNASequence

transcribe()[source]#

Transcribe DNA sequence into RNA sequence

Return type:

RNASequence

translate(codon_table=None, start_at_first_met=False, stop_at_stop_codon=False, require_mod3=True, start=None, end=None)[source]#

Translate DNA sequence into amino acid sequence using this codon table.

Parameters:
  • codon_table (Optional[CodonTable]) – Codon table to use for translation. If None, uses standard genetic code.

  • start_at_first_met (bool) – Start translation at the first start codon if found.

  • stop_at_stop_codon (bool) – Stop translation when a stop codon is encountered.

  • require_mod3 (bool) – Whether the sequence must be a multiple of 3 in length.

  • start (Optional[int]) – Custom 0-based start position. Overrides start_at_first_met.

  • end (Optional[int]) – Custom 0-based end position. Overrides stop_at_stop_codon.

Return type:

ProteinSequence

Returns:

Translated amino acid sequence.

class mutcleaner.core.sequence.ProteinSequence(sequence, alphabet=None, name=None, metadata=None)[source]#

Bases: BaseSequence

Protein sequence with amino acid validation

Methods

apply_mutation(mutation)

Apply a mutation or set of mutations to the sequence and return a new sequence.

default_alphabet()

Subclasses may override this method to provide a default alphabet.

find_motif(motif)

Find all positions where motif occurs (0-indexed)

get_residue(position)

Get amino acid at specific position (0-indexed)

get_subsequence(start[, end])

get subsequence (0-indexed, inclusive)

infer_mutation(other)

Infer a mutation that leads to a specific sequence

classmethod default_alphabet()[source]#

Subclasses may override this method to provide a default alphabet.

By default, it returns None, indicating no default is provided and callers must pass alphabet explicitly.

Return type:

Optional[BaseAlphabet]

find_motif(motif)[source]#

Find all positions where motif occurs (0-indexed)

Return type:

List[int]

get_residue(position)[source]#

Get amino acid at specific position (0-indexed)

Return type:

str

class mutcleaner.core.sequence.RNASequence(sequence, alphabet=None, name=None, metadata=None)[source]#

Bases: BaseSequence

RNA sequence with nucleotide validation

Methods

apply_mutation(mutation)

Apply a mutation or set of mutations to the sequence and return a new sequence.

back_transcribe()

Back-transcribe RNA sequence into DNA sequence

default_alphabet()

Subclasses may override this method to provide a default alphabet.

get_subsequence(start[, end])

get subsequence (0-indexed, inclusive)

infer_mutation(other)

Infer a mutation that leads to a specific sequence

reverse_complement()

Get reverse complement of RNA sequence

translate([codon_table, start_at_first_met, ...])

Translate RNA sequence into amino acid sequence using this codon table.

back_transcribe()[source]#

Back-transcribe RNA sequence into DNA sequence

Return type:

DNASequence

classmethod default_alphabet()[source]#

Subclasses may override this method to provide a default alphabet.

By default, it returns None, indicating no default is provided and callers must pass alphabet explicitly.

Return type:

Optional[BaseAlphabet]

reverse_complement()[source]#

Get reverse complement of RNA sequence

Return type:

RNASequence

translate(codon_table=None, start_at_first_met=False, stop_at_stop_codon=False, require_mod3=True, start=None, end=None)[source]#

Translate RNA sequence into amino acid sequence using this codon table.

Parameters:
  • codon_table (Optional[CodonTable]) – Codon table to use for translation. If None, uses standard genetic code.

  • start_at_first_met (bool) – Start translation at the first start codon if found.

  • stop_at_stop_codon (bool) – Stop translation when a stop codon is encountered.

  • require_mod3 (bool) – Whether the sequence must be a multiple of 3 in length.

  • start (Optional[int]) – Custom 0-based start position. Overrides start_at_first_met.

  • end (Optional[int]) – Custom 0-based end position. Overrides stop_at_stop_codon.

Return type:

ProteinSequence

Returns:

Translated amino acid sequence.