mutcleaner.utils.cleaner_workers#
Functions
|
Apply mutations to a single sequence. |
|
Process a single row to infer mutations between WT and mutated sequences. |
|
Infer wild-type sequences by reversing the substitutions in one group. |
|
Process a single mutation string. |
- 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 datasetdataset_columns (
Index) – Column names of the datasetsequence_column (
str) – Column name containing sequencesname_column (
str) – Column name containing protein identifiersmutation_column (
str) – Column name containing mutation informationposition_columns (
Optional[Dict[str,str]]) – Position column mapping for sequence extractionmutation_sep (
str) – Separator for splitting multiple mutationsoffset (
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 applicationinclude_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 informationdataset_columns (
Index) – Column names of the datasetwt_sequence_column (
str) – Column key for wild-type sequencemut_sequence_column (
str) – Column key for mutated sequencemutation_sep (
str) – Separator for joining multiple mutationssequence_class (
Type[SequenceType]) – Sequence class to use for mutation inferencealphabet (
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
WTrow 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 anderror_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