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

  1. Sets up a sample tree and character matrix in the setUp method.
  2. 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

  1. Checks if nCk(10, 2) returns the expected value of 45.
  2. Verifies that nCk(5, 7) raises a CassiopeiaError.

test_simple_coalescent_probability

Description

Tests the simple_coalescent_probability function from the topology module.

Internal Logic

  1. Calculates the coalescent probability for given parameters and compares it to an expected value.
  2. Verifies that invalid input raises a CassiopeiaError.

test_expansion_probability

Description

Tests the compute_expansion_pvalues function from the topology module.

Internal Logic

  1. Calls compute_expansion_pvalues with different parameters.
  2. 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

  1. Calls compute_expansion_pvalues with a minimum depth parameter.
  2. 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

  1. Calls compute_expansion_pvalues with the copy option set to True.
  2. 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

  1. Creates a custom dissimilarity map.
  2. Calls compute_cophenetic_correlation and verifies that it returns a perfect correlation (1.0).
  3. Tests the function with a custom weight matrix.

test_cophenetic_correlation_default

Description

Tests the compute_cophenetic_correlation function with default parameters.

Internal Logic

  1. Calls compute_cophenetic_correlation without custom parameters.
  2. Verifies that the resulting correlation is close to an expected value.

Dependencies

DependencyPurpose
unittestProvides the testing framework
networkxUsed for creating and manipulating graphs
numpyUsed for numerical operations
pandasUsed for data manipulation and analysis
cassiopeiaThe 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.