Here’s a detailed documentation of the target file test/preprocess_tests/collapse_umi_test.py:

High-level description

This file contains unit tests for the UMI Collapsing module in the Cassiopeia preprocessing pipeline. It tests various aspects of UMI collapsing, including sorting BAM files, forming collapsed clusters, and converting BAM files to DataFrames.

Code Structure

The main class TestCollapseUMIs inherits from unittest.TestCase and contains several test methods. The setUp method prepares the test environment by creating test files and running UMI collapsing operations. The test methods then verify the correctness of these operations.

Symbols

TestCollapseUMIs

Description

A test class that contains unit tests for the UMI Collapsing functionality.

Internal Logic

  1. Sets up test files and performs UMI collapsing operations in setUp.
  2. Tests various aspects of UMI collapsing in individual test methods.

setUp

Description

Prepares the test environment by creating test files and running UMI collapsing operations.

Internal Logic

  1. Creates test directories and files.
  2. Sorts BAM files.
  3. Performs UMI collapsing using different methods and parameters.

test_sort_bam

Description

Tests the sorting of BAM files.

Internal Logic

  1. Opens the sorted BAM file.
  2. Extracts cell barcodes and UMIs.
  3. Verifies the correctness of specific entries.

test_sort_bam_uncorrected

Description

Tests the sorting of uncorrected BAM files.

Internal Logic

Similar to test_sort_bam, but uses uncorrected test files.

test_collapse_bam

Description

Tests the collapsing of BAM files.

Internal Logic

  1. Opens the collapsed BAM file.
  2. Extracts various fields (cell barcodes, UMIs, read counts, cluster IDs, qualities).
  3. Verifies the correctness of specific entries and counts.

test_collapse_bam_bayesian

Description

Tests the Bayesian collapsing of BAM files.

Internal Logic

Similar to test_collapse_bam, but uses Bayesian collapsed files.

test_collapse_bam_uncorrected

Description

Tests the collapsing of uncorrected BAM files.

Internal Logic

Similar to test_collapse_bam, but uses uncorrected collapsed files.

test_bam2DF

Description

Tests the conversion of BAM files to DataFrames.

Internal Logic

  1. Converts BAM to DataFrame.
  2. Verifies specific entries in the resulting DataFrame.
  3. Compares with a separately loaded DataFrame from a text file.

test_collapsing_passes_header

Description

Tests that the collapsing process correctly passes header information.

Internal Logic

  1. Opens the collapsed BAM file.
  2. Verifies that the alignment has non-None query sequence and qualities.

Dependencies

DependencyPurpose
osFile and directory operations
unittestUnit testing framework
pandasData manipulation and analysis
pathlibObject-oriented filesystem paths
pysamReading/writing SAM/BAM/VCF/BCF files
cassiopeia.preprocessUMI collapsing functionality

Error Handling

The tests use assertions to verify the correctness of operations. If any assertion fails, an AssertionError will be raised, indicating a test failure.

This file is crucial for ensuring the correctness of the UMI collapsing functionality in the Cassiopeia preprocessing pipeline. It covers various scenarios and edge cases, helping to maintain the reliability of the UMI collapsing process.