High-level description
This file provides functions for collapsing and preprocessing Unique Molecular Identifiers (UMIs) in sequencing data. It handles tasks like grouping reads by cell barcodes and UMIs, forming consensus sequences for each UMI cluster, and error-correcting UMI sequences.Code Structure
The code defines several functions that work together to perform UMI collapsing and error correction. The main functions aresort_bam, form_collapsed_clusters, form_clusters, form_clusters_likelihood, and correct_umis_in_group. sort_bam sorts the input BAM file by cell barcode and UMI. form_collapsed_clusters groups reads with the same cell barcode and UMI, and then calls either form_clusters or form_clusters_likelihood to form consensus sequences for each UMI cluster. correct_umis_in_group further groups reads by cell barcode, UMI, and optionally allele, and then performs error correction on the UMI sequences within each group.
References
This file references the following symbols:cassiopeia.preprocess.constants.BAM_CONSTANTScassiopeia.preprocess.utilities.convert_bam_to_dfcassiopeia.mixins.loggercassiopeia.mixins.PreprocessErrorcassiopeia.mixins.PreprocessWarning
Symbols
detect_cell_bc_tag
Description
This function determines the appropriate BAM tag for cell barcodes by checking if the corrected cell barcode tag exists in the BAM file. If it does, it returns the corrected tag; otherwise, it returns the raw cell barcode tag.Inputs
Outputs
group_bam_by_key
Description
This generator function iterates through a sorted BAM file and yields groups of alignments that share the same key, defined by thesort_key function.
Inputs
Outputs
sort_bam
Description
This function sorts a BAM file by a specified key and filters alignments based on a filter function. It splits the BAM file into chunks, sorts and filters each chunk, and then merges the sorted chunks into a final sorted BAM file.Inputs
Outputs
form_collapsed_clusters
Description
This function groups reads with the same cell barcode and UMI, and then forms consensus sequences for each UMI cluster. It uses either a hard cutoff method or a likelihood-based method to form the initial sequence clusters, and then attempts to merge clusters with similar sequences.Inputs
Outputs
form_clusters
Description
This function implements the hard cutoff method for forming consensus sequences for UMI clusters. It iteratively finds the most frequent sequence in the remaining alignments and groups all sequences within a certain Hamming distance from it.Inputs
Outputs
form_clusters_likelihood
Description
This function implements the likelihood-based method for forming consensus sequences for UMI clusters. It uses the quality scores of the bases to calculate the probability of each base being correct and forms consensus sequences based on these probabilities.Inputs
Outputs
align_clusters
Description
This function calculates the number of indels and high-quality mismatches between two aligned segments using the Smith-Waterman algorithm.Inputs
Outputs
within_radius_of_seed
Description
This function takes a seed sequence and a list of alignments and returns two lists: one containing alignments whose sequences are within a certain Hamming distance from the seed sequence, and another containing the remaining alignments.Inputs
Outputs
propose_seed
Description
This function proposes a seed sequence for clustering by finding the most frequent sequence in a list of alignments. If there is no most frequent sequence, it callscall_consensus to generate a consensus sequence.
