mutcleaner.utils.cleaner_workers#

Functions

apply_single_mutation(row_data, ...[, ...])

Apply mutations to a single sequence.

infer_single_mutationset(row_data, ...[, ...])

Process a single row to infer mutations between WT and mutated sequences.

infer_wt_sequence_grouped(group_data, ...)

Infer wild-type sequences by reversing the substitutions in one group.

valid_single_mutation(args)

Process a single mutation string.

validate_single_mutation_and_sequence(...)

mutcleaner.utils.cleaner_workers.apply_single_mutation(row_data, dataset_columns, sequence_column, name_column, mutation_column, position_columns, mutation_sep, offset, mutation_type, alphabet, sequence_class, *, include_ambiguous=False, include_sec_pyl=False, reject_redundant=True)[source]#

Apply mutations to a single sequence.

Parameters:
  • row_data (Tuple) – Row data from the dataset

  • dataset_columns (Index) – Column names of the dataset

  • sequence_column (str) – Column name containing sequences

  • name_column (str) – Column name containing protein identifiers

  • mutation_column (str) – Column name containing mutation information

  • position_columns (Optional[Dict[str, str]]) – Position column mapping for sequence extraction

  • mutation_sep (str) – Separator for splitting multiple mutations

  • offset (int) – Input position of the first residue or codon.

  • mutation_type (Optional[Type[BaseMutation]]) – Mutation class to use when parsing the annotation.

  • alphabet (Optional[BaseAlphabet]) – Alphabet for parsing mutations. For proteins, it also validates the sequence.

  • sequence_class (Type[Union[ProteinSequence, DNASequence, RNASequence]]) – Sequence class to use for mutation application

  • include_ambiguous (bool) – Include B, Z, J, and X in the default protein alphabet.

  • include_sec_pyl (bool) – Include U and O in the default protein alphabet.

  • reject_redundant (bool) – Reject an annotation containing an unchanged amino acid.

Return type:

Tuple[Optional[str], Optional[str]]

Returns:

(mutated_sequence, error_message) - either sequence or error, not both

mutcleaner.utils.cleaner_workers.infer_single_mutationset(row_data, dataset_columns, wt_sequence_column, mut_sequence_column, mutation_sep, sequence_class, *, alphabet=None, include_ambiguous=False, include_sec_pyl=False)[source]#

Process a single row to infer mutations between WT and mutated sequences.

This function is designed to be used with parallel processing.

Parameters:
  • row_data (Tuple) – Single row data containing sequence information

  • dataset_columns (Index) – Column names of the dataset

  • wt_sequence_column (str) – Column key for wild-type sequence

  • mut_sequence_column (str) – Column key for mutated sequence

  • mutation_sep (str) – Separator for joining multiple mutations

  • sequence_class (Type[SequenceType]) – Sequence class to use for mutation inference

  • alphabet (Optional[BaseAlphabet]) – Alphabet shared by the wild-type and mutated sequences.

  • include_ambiguous (bool) – Allow ambiguous symbols in the default protein alphabet.

  • include_sec_pyl (bool) – Allow U and O in the default protein alphabet.

Return type:

Tuple[Optional[str], Optional[str]]

Returns:

(result, error_message) where error_message is None on success

mutcleaner.utils.cleaner_workers.infer_wt_sequence_grouped(group_data, name_column, mutation_column, sequence_column, label_columns, wt_label, mutation_sep, offset, sequence_class, *, alphabet, include_ambiguous, include_sec_pyl, reject_redundant)[source]#

Infer wild-type sequences by reversing the substitutions in one group.

Each row supplies a mutated sequence and its mutation annotation. If all rows yield the same wild type, append one WT row to the original rows. Each appended row copies the group’s first row and replaces its mutation annotation, sequence, and specified labels.

Parameters:
  • group_data (Tuple[Any, DataFrame]) – Group key and a pandas DataFrame containing that group’s variant rows.

  • name_column (str) – Column containing the group identifier.

  • mutation_column (str) – Column containing the substitutions from wild type to mutant.

  • sequence_column (str) – Column containing the mutated sequence for each annotation.

  • label_columns (List[str]) – Label columns to set in appended wild-type rows, if present.

  • wt_label (float) – Value assigned to those label columns.

  • mutation_sep (str) – Delimiter between substitutions in a multi-site annotation.

  • offset (int) – Annotated position of the first reference residue or codon. Subtract this value from each annotated position to obtain its zero-based index.

  • sequence_class (Type[Union[ProteinSequence, DNASequence, RNASequence]]) – Sequence class for the group (ProteinSequence, DNASequence, or RNASequence).

  • alphabet (Optional[BaseAlphabet]) – Alphabet used for the sequence and its annotation. An explicit alphabet takes precedence over the protein options below.

  • include_ambiguous (bool) – Accept B, Z, J, and X when building the protein alphabet.

  • include_sec_pyl (bool) – Accept selenocysteine (U) and pyrrolysine (O) when building the protein alphabet.

  • reject_redundant (bool) – Reject the group if an annotation contains an amino acid substitution that leaves the residue unchanged.

Return type:

Tuple[List[Dict[str, Any]], str]

Returns:

  • rows (list of dict) – Original rows followed by any appended wild-type rows. If sequence validation, mutation parsing, or reverse application fails for any row, or the group yields multiple wild types, return only the group’s first row with error_message. For an empty group, the error row contains the group identifier and error_message.

  • status ({‘success’, ‘failed’}) – Outcome for the entire group.

mutcleaner.utils.cleaner_workers.valid_single_mutation(args)[source]#

Process a single mutation string.

Parameters:

args (Tuple) – (mut_info, format_mutations, mutation_sep, offset, mutation_type, alphabet, include_ambiguous, include_sec_pyl, reject_redundant, shared_cache). Share a cache only across calls with the same parsing and formatting options.

Return type:

Tuple[Optional[str], Optional[str]]

Returns:

(formatted_mutation, error_message) - one will be None

mutcleaner.utils.cleaner_workers.validate_single_mutation_and_sequence(row_data, dataset_columns, wt_sequence_column, name_column, mutation_column, mut_sequence_column, mutation_sep, offset, sequence_class)[source]#
Return type:

Tuple[Optional[str], Optional[str]]