simulator_tests
simple_fit_subclone_simulator_test.py
High-level description
This file contains unit tests for the SimpleFitSubcloneSimulator class, which simulates a clonal population that develops one fit subclone. The tests verify the correctness of the simulated phylogenetic tree structure and branch lengths in both deterministic and stochastic scenarios.
Symbols
TestSimpleFitSubcloneSimulator
Description
A unittest.TestCase subclass that contains test methods for the SimpleFitSubcloneSimulator class.
test_deterministic
Description
Tests the SimpleFitSubcloneSimulator with deterministic branch lengths to ensure the generated phylogeny is correct.
Internal Logic
- Creates a SimpleFitSubcloneSimulator instance with specific parameters.
- Simulates a tree using the simulator.
- Asserts that the generated tree has the expected structure:
- Correct node names
- Correct edge connections
- Correct node times
test_stochastic
Description
Tests the SimpleFitSubcloneSimulator with stochastic branch lengths to ensure non-deterministic behavior.
Internal Logic
- Sets a random seed for reproducibility.
- Defines two functions for generating random branch lengths:
branch_length_neutral
: Returns an exponentially distributed value with mean 1.0branch_length_fit
: Returns an exponentially distributed value with mean 0.5
- Creates a SimpleFitSubcloneSimulator instance with the random branch length functions.
- Simulates a tree using the simulator.
- Extracts branch lengths for non-leaf nodes.
- Asserts that all branch lengths are distinct, confirming non-determinism.
Dependencies
Dependency | Purpose |
---|---|
numpy | Used for random number generation and array operations |
unittest | Provides the testing framework |
cassiopeia.simulator.SimpleFitSubcloneSimulator | The class being tested |
Notes
- The tests cover both deterministic and stochastic scenarios, ensuring the simulator works correctly in different conditions.
- The stochastic test uses a fixed random seed to ensure reproducibility while still testing random behavior.
- The tests focus on verifying the tree structure, node naming, and branch length generation, which are key aspects of the SimpleFitSubcloneSimulator’s functionality.