High-level description
This file provides utility functions for handling sequence alignments, particularly for processing TargetSite sequencing data. It includes functions for performing local and global alignment, parsing CIGAR strings to identify indels, and extracting integration barcodes.Code Structure
Theparse_cigar function utilizes the output of the align_local and align_global functions, specifically the CIGAR string, to identify indels.
Symbols
Symbol Name
align_local
Description
Performs local alignment of a query sequence (seq) to a reference sequence (ref) using the Smith-Waterman algorithm.
Inputs
Outputs
Internal Logic
- Initializes a Smith-Waterman aligner using the provided substitution matrix and gap penalties.
- Performs local alignment using the
alignmethod of the aligner. - Extracts the alignment results, including the aligned sequences, start positions, and alignment score.
- Converts the alignment results to a CIGAR string using the
ngs.sequence.alignment_to_cigarfunction. - Returns the CIGAR string, start positions, alignment score, and the input query sequence.
Symbol Name
align_global
Description
Performs global alignment of a query sequence (seq) to a reference sequence (ref) using the Needleman-Wunsch algorithm.
Inputs
Outputs
Internal Logic
- Initializes a Needleman-Wunsch aligner using the provided substitution matrix and gap penalties.
- Note: The
no_end_gap_penaltyparameter is set toTruebecause reads are expected to be shorter than the reference.
- Note: The
- Performs global alignment using the
alignmethod of the aligner. - Extracts the alignment results, including the aligned sequences, start positions, and alignment score.
- Converts the alignment results to a CIGAR string using the
ngs.sequence.alignment_to_cigarfunction. - Returns the CIGAR string, start positions, alignment score, and the input query sequence.
Symbol Name
parse_cigar
Description
Parses a CIGAR string to identify insertions and deletions (indels) relative to a reference sequence, focusing on regions around specified cutsites and a barcode interval.Inputs
Outputs
Internal Logic
-
Initialization:
- Creates lists to store indels (
indels) and indels occurring outside cutsite windows (uncut_indels) for each cutsite. - Initializes the integration barcode (
intBC) to “NC” (not captured). - Extracts the anchor sequence from the reference for later intBC extraction.
- Sets up pointers to track the current position in the reference (
ref_pointer) and query (query_pointer) sequences. - Initializes a variable
query_padto account for potential insertions or deletions at the beginning of the intBC.
- Creates lists to store indels (
-
CIGAR Parsing:
- Iterates through each chunk (operation and length) in the CIGAR string.
- Match (M):
- Updates
ref_pointerandquery_pointer. - If the match overlaps with the
barcode_interval, extracts theintBC. - If the match overlaps with any
cutsitewindow and no indel has been recorded for that cutsite, records “None” (no indel) with optional context. - Handles partial deletions within the
barcode_interval.
- Updates
- Insertion (I):
- Increments
query_pointer. - If the insertion occurs within any
cutsitewindow, records the insertion with its position and length, along with optional context.
- Increments
- Deletion (D):
- Increments
ref_pointer. - If the deletion occurs within any
cutsitewindow, records the deletion with its position and length, along with optional context.
- Increments
- Hard Clip (H):
- Increments
query_pointer.
- Increments
- Unknown Operation:
- Raises an
UnknownCigarStringError.
- Raises an
-
Integration Barcode (intBC) Handling:
- If
intBCis still “NC” or its length is less than expected, attempts to extract it based on the anchor sequence.
- If
-
Indel Finalization:
- Replaces empty indel strings in
indelswith corresponding entries fromuncut_indels.
- Replaces empty indel strings in
-
Return:
- Returns the extracted
intBCand the list ofindels.
- Returns the extracted
References
- This code references the
ngs_toolslibrary for sequence manipulation and alignment functions. - It also references the
pyseq_alignlibrary for the Smith-Waterman and Needleman-Wunsch alignment algorithms. - The code utilizes the
UnknownCigarStringErrorfrom thecassiopeia.mixinsmodule.
Error Handling
- The
parse_cigarfunction raises anUnknownCigarStringErrorif it encounters an unsupported CIGAR operation.
