> ## Documentation Index
> Fetch the complete documentation index at: https://demo.agenticlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# character_matrix_test.py

Here's a high-level description and documentation of the provided code:

## High-level description

This file contains unit tests for the character matrix formation functionality in the Cassiopeia preprocessing pipeline. It tests various aspects of converting allele tables to character matrices and lineage profiles, including handling of missing data, conflicts, and different input formats.

## Code Structure

The code defines a TestCharacterMatrixFormation class that inherits from unittest.TestCase. This class contains multiple test methods, each focusing on a specific aspect of the character matrix formation process. The setUp method initializes test data used across multiple test cases.

## Symbols

### TestCharacterMatrixFormation

#### Description

A test class containing multiple unit tests for the character matrix formation functionality.

#### Internal Logic

1. Sets up test data in the setUp method.
2. Defines multiple test methods, each testing a specific aspect of the character matrix formation process.
3. Uses assertions to verify the correctness of the output.

### setUp

#### Description

Initializes test data used across multiple test cases.

#### Internal Logic

1. Creates sample allele tables with various configurations.
2. Sets up mutation priors for testing.

### test\_basic\_character\_matrix\_formation

#### Description

Tests the basic functionality of converting an allele table to a character matrix.

#### Internal Logic

1. Calls convert\_alleletable\_to\_character\_matrix with basic input.
2. Verifies the shape and content of the resulting character matrix.

### test\_character\_matrix\_formation\_custom\_missing\_data

#### Description

Tests character matrix formation with custom missing data handling.

#### Internal Logic

1. Modifies the input data to include custom missing data.
2. Calls convert\_alleletable\_to\_character\_matrix with custom missing data parameters.
3. Verifies the correct handling of missing data in the output.

### test\_character\_matrix\_formation\_with\_conflicts

#### Description

Tests character matrix formation when there are conflicting alleles.

#### Internal Logic

1. Uses an allele table with conflicting data.
2. Calls convert\_alleletable\_to\_character\_matrix.
3. Verifies that conflicts are correctly represented in the output.

### test\_ignore\_intbc

#### Description

Tests the ability to ignore specific integration barcodes (intBCs) during character matrix formation.

#### Internal Logic

1. Calls convert\_alleletable\_to\_character\_matrix with specific intBCs to ignore.
2. Verifies that the specified intBCs are not included in the output.

### test\_filter\_out\_low\_diversity\_intbcs

#### Description

Tests filtering out integration barcodes with low diversity.

#### Internal Logic

1. Calls convert\_alleletable\_to\_character\_matrix with a high allele representation threshold.
2. Verifies that low-diversity intBCs are removed from the output.

### test\_mutation\_prior\_formation

#### Description

Tests the formation of mutation priors during character matrix conversion.

#### Internal Logic

1. Calls convert\_alleletable\_to\_character\_matrix with mutation priors.
2. Verifies that the resulting prior probabilities are correct.

### test\_indel\_state\_mapping\_formation

#### Description

Tests the formation of indel state mappings during character matrix conversion.

#### Internal Logic

1. Calls convert\_alleletable\_to\_character\_matrix with mutation priors.
2. Verifies that the resulting indel state mappings are correct.

### test\_alleletable\_to\_lineage\_profile

#### Description

Tests the conversion of an allele table to a lineage profile.

#### Internal Logic

1. Calls convert\_alleletable\_to\_lineage\_profile.
2. Verifies that the resulting lineage profile is correct.

### test\_lineage\_profile\_to\_character\_matrix\_no\_priors

#### Description

Tests the conversion of a lineage profile to a character matrix without priors.

#### Internal Logic

1. Converts an allele table to a lineage profile.
2. Calls convert\_lineage\_profile\_to\_character\_matrix without priors.
3. Verifies the correctness of the resulting character matrix.

### test\_lineage\_profile\_to\_character\_matrix\_with\_priors

#### Description

Tests the conversion of a lineage profile to a character matrix with priors.

#### Internal Logic

1. Converts an allele table to a lineage profile.
2. Calls convert\_lineage\_profile\_to\_character\_matrix with priors.
3. Verifies the correctness of the resulting character matrix and priors.

### test\_compute\_empirical\_indel\_probabilities

#### Description

Tests the computation of empirical indel probabilities.

#### Internal Logic

1. Calls compute\_empirical\_indel\_priors.
2. Verifies that the resulting probabilities are correct.

### test\_noncanonical\_cut\_sites\_allele\_table\_to\_character\_matrix

#### Description

Tests character matrix formation with non-canonical cut site names.

#### Internal Logic

1. Uses an allele table with non-standard cut site column names.
2. Calls convert\_alleletable\_to\_character\_matrix with custom cut site names.
3. Verifies that the resulting character matrix is correct.

## Dependencies

* unittest: For defining and running unit tests
* numpy: For numerical operations
* pandas: For data manipulation and analysis
* cassiopeia: The main package being tested

This test suite provides comprehensive coverage of the character matrix formation functionality in Cassiopeia, ensuring that it handles various edge cases and input formats correctly.
