High-level description
This file contains unit tests for thefilter_bam function from the cassiopeia.preprocess.pipeline module. The tests verify that the function correctly filters BAM files based on a specified read quality threshold.
Symbols
TestFilterBam
Description
This is a test class that inherits fromunittest.TestCase. It contains test methods to verify the functionality of the filter_bam function.
Internal Logic
- Sets up the test environment by defining the path to a test BAM file.
- Implements a test method
test_filterto check the filtering functionality with different quality thresholds.
setUp
Description
This method is called before each test method to set up the test environment.Internal Logic
- Determines the directory path of the current file.
- Constructs the path to the test files directory.
- Sets the path to a 10x Genomics v3 unmapped BAM file for testing.
test_filter
Description
This method tests thefilter_bam function with different quality thresholds.
Internal Logic
- Calls
filter_bamwith a quality threshold of 10 and verifies that 2 alignments pass the filter. - Calls
filter_bamwith a quality threshold of 20 and verifies that 0 alignments pass the filter. - Uses
pysam.AlignmentFileto read the filtered BAM files and count the number of alignments. - Uses
assertEqualto check if the number of filtered alignments matches the expected count.
Dependencies
Error Handling
The test class uses theunittest framework’s assertion methods to check for expected outcomes. If any assertion fails, the test will raise an exception, indicating a test failure.
Notes
- The test file uses a specific 10x Genomics v3 unmapped BAM file for testing, located in the “test_files” directory.
- The
filter_bamfunction is called with temporary directories created usingtempfile.mkdtemp()to store the output filtered BAM files. - The tests check two scenarios: one where some reads pass the quality filter (threshold 10) and another where no reads pass the filter (threshold 20).
- The
pysamlibrary is used to read the filtered BAM files and count the number of alignments. - The
ngs_toolsmodule is imported but not used directly in this test file.
