topology_test.py
High-level description
This file contains a test suite for the topology functions in the cassiopeia/tools/topology.py
module. It tests various functions related to tree topology, including expansion probabilities, cophenetic correlation, and simple coalescent probability calculations.
Code Structure
The main class TestTopology
inherits from unittest.TestCase
and contains several test methods. The setUp
method creates a sample tree and character matrix for use in the tests. Each test method focuses on a specific functionality of the topology module.
Symbols
TestTopology
Description
A test class that inherits from unittest.TestCase
and contains multiple test methods for the topology functions.
Internal Logic
- Sets up a sample tree and character matrix in the
setUp
method. - Implements various test methods to check different aspects of the topology functions.
test_simple_choose_function
Description
Tests the nCk
function from the topology module.
Internal Logic
- Checks if
nCk(10, 2)
returns the expected value of 45. - Verifies that
nCk(5, 7)
raises aCassiopeiaError
.
test_simple_coalescent_probability
Description
Tests the simple_coalescent_probability
function from the topology module.
Internal Logic
- Calculates the coalescent probability for given parameters and compares it to an expected value.
- Verifies that invalid input raises a
CassiopeiaError
.
test_expansion_probability
Description
Tests the compute_expansion_pvalues
function from the topology module.
Internal Logic
- Calls
compute_expansion_pvalues
with different parameters. - Compares the resulting expansion probabilities with expected values for each node in the tree.
test_expansion_probability_variable_depths
Description
Tests the compute_expansion_pvalues
function with variable depths.
Internal Logic
- Calls
compute_expansion_pvalues
with a minimum depth parameter. - Verifies the resulting expansion probabilities against expected values.
test_expansion_probability_copy_tree
Description
Tests the compute_expansion_pvalues
function with the copy option.
Internal Logic
- Calls
compute_expansion_pvalues
with the copy option set to True. - Verifies that the original tree is not modified and the new tree has the expected probabilities.
test_cophenetic_correlation_perfect
Description
Tests the compute_cophenetic_correlation
function with a perfect correlation scenario.
Internal Logic
- Creates a custom dissimilarity map.
- Calls
compute_cophenetic_correlation
and verifies that it returns a perfect correlation (1.0). - Tests the function with a custom weight matrix.
test_cophenetic_correlation_default
Description
Tests the compute_cophenetic_correlation
function with default parameters.
Internal Logic
- Calls
compute_cophenetic_correlation
without custom parameters. - Verifies that the resulting correlation is close to an expected value.
Dependencies
Dependency | Purpose |
---|---|
unittest | Provides the testing framework |
networkx | Used for creating and manipulating graphs |
numpy | Used for numerical operations |
pandas | Used for data manipulation and analysis |
cassiopeia | The main package being tested |
Error Handling
The test suite uses assertions to check for expected values and behaviors. It also tests for specific error cases, such as raising CassiopeiaError
for invalid inputs.