compare_tree_test.py
High-level description
This file contains unit tests for the cassiopeia.critique.compare
module, specifically focusing on the comparison of phylogenetic trees. It uses various tree structures, including balanced trees, multifurcating trees, and rake-shaped trees, to test the accuracy of the comparison metrics.
Code Structure
The TestTreeComparisons
class contains multiple test methods, each designed to test a specific aspect of the tree comparison functionality. The setUp
method initializes various tree structures used throughout the tests. The test methods then utilize these trees to calculate and validate different comparison metrics.
Symbols
TestTreeComparisons
Description
A class containing unit tests for tree comparison functions in the cassiopeia.critique.compare
module.
Inputs
None
Outputs
None (test results are outputted to the console)
Internal Logic
This class utilizes the unittest
framework in Python. Each test method within this class is executed independently and checks for specific outcomes from the tree comparison functions. Assertions are used to validate the expected results.
setUp
Description
Initializes various CassiopeiaTree
objects with different tree structures for testing purposes.
Inputs
None
Outputs
None (sets up instance variables)
test_out_group
Description
Tests the get_outgroup
function, which identifies the outlier node in a triplet.
Inputs
None
Outputs
None (assertions are used to validate the output of get_outgroup
)
test_same_tree_gives_perfect_triplets_correct
Description
Tests the triplets_correct
function when comparing a tree to itself, expecting perfect agreement.
Inputs
None
Outputs
None (assertions are used to validate the output of triplets_correct
)
test_triplets_correct_different_trees
Description
Tests the triplets_correct
function with different trees, expecting variations in agreement.
Inputs
None
Outputs
None (assertions are used to validate the output of triplets_correct
)
test_triplets_correct_multifurcating_same_tree
Description
Tests the triplets_correct
function with a multifurcating tree compared to itself, considering unresolvable triplets.
Inputs
None
Outputs
None (assertions are used to validate the output of triplets_correct
)
test_triplets_correct_multifurcating_different_trees
Description
Tests the triplets_correct
function with different multifurcating trees, considering unresolvable triplets.
Inputs
None
Outputs
None (assertions are used to validate the output of triplets_correct
)
test_rake_tree
Description
Tests the triplets_correct
function with a rake-shaped tree, which has all nodes at the same depth.
Inputs
None
Outputs
None (assertions are used to validate the output of triplets_correct
)
test_robinson_foulds_same_tree_bifurcating
Description
Tests the robinson_foulds
function, which calculates the Robinson-Foulds distance between trees.
Inputs
None
Outputs
None (assertions are used to validate the output of robinson_foulds
)
References
This code references the following symbols from other files:
cassiopeia.critique.critique_utilities.get_outgroup
cassiopeia.critique.triplets_correct
cassiopeia.critique.robinson_foulds
cassiopeia.data.CassiopeiaTree
Dependencies
Dependency | Purpose |
---|---|
unittest | Provides the framework for writing and running unit tests. |
networkx | Used for creating and manipulating graph structures, representing phylogenetic trees. |
numpy | Used for numerical operations and array manipulation. |
pandas | Used for data manipulation and analysis, particularly with DataFrames. |
cassiopeia | The core library for single-cell lineage tracing analysis. |