This file contains unit tests for the CCPhylo solver implementations in the Cassiopeia package. It compares the results of CCPhylo solvers (NJ, DNJ, HNJ, and UPGMA) against standard Neighbor Joining (NJ) and UPGMA implementations for phylogenetic tree reconstruction.
The code defines a test class TestCCPhyloSolver
that inherits from unittest.TestCase
. It includes several test methods to compare different solver implementations and their behavior under various conditions.
find_triplet_structure
This function determines the structure of a triplet in a given tree.
Name | Type | Description |
---|---|---|
triplet | tuple | A tuple containing three node labels |
T | networkx.Graph | The tree to analyze |
Name | Type | Description |
---|---|---|
structure | str | The structure of the triplet (“ab”, “ac”, “bc”, or ”-“) |
delta_fn
This function calculates the dissimilarity between two arrays.
Name | Type | Description |
---|---|---|
x | np.array | First array |
y | np.array | Second array |
missing_state | int | Value representing missing data |
priors | Optional[Dict[int, Dict[int, float]]] | Prior probabilities |
Name | Type | Description |
---|---|---|
d | int | The number of differences between the two arrays |
TestCCPhyloSolver
This is the main test class containing various test methods for CCPhylo solvers.
setUp
methodtest_ccphylo_invalid_input
: Tests error handling for invalid solver inputstest_ccphylo_nj_solver
: Compares CCPhylo NJ solver with standard NJ solvertest_ccphylo_dnj_solver
: Compares CCPhylo DNJ solver with standard NJ solvertest_ccphylo_hnj_solver
: Compares CCPhylo HNJ solver with standard NJ solvertest_ccphylo_upgma_solver
: Compares CCPhylo UPGMA solver with standard UPGMA solvertest_collapse_mutationless_edges_ccphylo
: Tests collapsing mutationless edges in CCPhylo NJ solvertest_duplicate_sample_ccphylo
: Tests CCPhylo NJ solver with duplicate samplesDependency | Purpose |
---|---|
unittest | For creating and running unit tests |
mock | For mocking objects in tests |
configparser | For reading configuration files |
itertools | For generating combinations |
networkx | For working with graph structures |
numpy | For numerical operations |
pandas | For data manipulation |
cassiopeia | The main package being tested |
The tests check for the existence of a config.ini
file and a ccphylo_path
setting to determine if CCPhylo is configured.
The code uses unittest.skipUnless
to skip tests if CCPhylo is not configured. It also tests for DistanceSolverError
when invalid inputs are provided to solvers.
This file contains unit tests for the CCPhylo solver implementations in the Cassiopeia package. It compares the results of CCPhylo solvers (NJ, DNJ, HNJ, and UPGMA) against standard Neighbor Joining (NJ) and UPGMA implementations for phylogenetic tree reconstruction.
The code defines a test class TestCCPhyloSolver
that inherits from unittest.TestCase
. It includes several test methods to compare different solver implementations and their behavior under various conditions.
find_triplet_structure
This function determines the structure of a triplet in a given tree.
Name | Type | Description |
---|---|---|
triplet | tuple | A tuple containing three node labels |
T | networkx.Graph | The tree to analyze |
Name | Type | Description |
---|---|---|
structure | str | The structure of the triplet (“ab”, “ac”, “bc”, or ”-“) |
delta_fn
This function calculates the dissimilarity between two arrays.
Name | Type | Description |
---|---|---|
x | np.array | First array |
y | np.array | Second array |
missing_state | int | Value representing missing data |
priors | Optional[Dict[int, Dict[int, float]]] | Prior probabilities |
Name | Type | Description |
---|---|---|
d | int | The number of differences between the two arrays |
TestCCPhyloSolver
This is the main test class containing various test methods for CCPhylo solvers.
setUp
methodtest_ccphylo_invalid_input
: Tests error handling for invalid solver inputstest_ccphylo_nj_solver
: Compares CCPhylo NJ solver with standard NJ solvertest_ccphylo_dnj_solver
: Compares CCPhylo DNJ solver with standard NJ solvertest_ccphylo_hnj_solver
: Compares CCPhylo HNJ solver with standard NJ solvertest_ccphylo_upgma_solver
: Compares CCPhylo UPGMA solver with standard UPGMA solvertest_collapse_mutationless_edges_ccphylo
: Tests collapsing mutationless edges in CCPhylo NJ solvertest_duplicate_sample_ccphylo
: Tests CCPhylo NJ solver with duplicate samplesDependency | Purpose |
---|---|
unittest | For creating and running unit tests |
mock | For mocking objects in tests |
configparser | For reading configuration files |
itertools | For generating combinations |
networkx | For working with graph structures |
numpy | For numerical operations |
pandas | For data manipulation |
cassiopeia | The main package being tested |
The tests check for the existence of a config.ini
file and a ccphylo_path
setting to determine if CCPhylo is configured.
The code uses unittest.skipUnless
to skip tests if CCPhylo is not configured. It also tests for DistanceSolverError
when invalid inputs are provided to solvers.