High-level description
This file contains unit tests for theparameter_estimators.py module in Cassiopeia. The tests cover functions that estimate parameters related to mutation rates and missing data in lineage tracing data.
Code Structure
TheTestCassiopeiaTree class contains multiple test methods, each testing different aspects of the parameter estimation functions. The tests are structured around two example trees: self.discrete_tree and self.continuous_tree, representing discrete and continuous character data respectively.
Symbols
TestCassiopeiaTree
Description
A class containing unit tests for parameter estimation functions.Inputs
NoneOutputs
NoneInternal Logic
The class uses theunittest framework to define and run tests. It sets up two example trees (self.discrete_tree and self.continuous_tree) in the setUp method, which are then used by the individual test methods.
test_proportions
Description
Tests theget_proportion_of_mutation and get_proportion_of_missing_data functions.
Inputs
Usesself.discrete_tree and self.continuous_tree
Outputs
NoneInternal Logic
- Calculates the proportion of mutations and missing data for both trees using the functions being tested.
- Asserts that the calculated proportions match the expected values.
test_estimate_mutation_rate
Description
Tests theestimate_mutation_rate function.
Inputs
Usesself.discrete_tree and self.continuous_tree
Outputs
NoneInternal Logic
- Estimates the mutation rate for both trees using the function being tested, with different combinations of the
continuousandassume_root_implicit_branchparameters. - Asserts that the estimated mutation rates are close to the expected values.
test_estimate_missing_data_bad_cases
Description
Tests the error handling of theestimate_missing_data_rates function.
Inputs
Usesself.discrete_tree and self.continuous_tree
Outputs
NoneInternal Logic
- Defines several scenarios where the
estimate_missing_data_ratesfunction should raise either aParameterEstimateErroror aParameterEstimateWarning. - Uses
assertRaisesto verify that the expected exceptions are raised in each scenario.
test_estimate_stochastic_missing_data_probability
Description
Tests theestimate_missing_data_rates function for estimating the stochastic missing data probability.
Inputs
Usesself.discrete_tree and self.continuous_tree
Outputs
NoneInternal Logic
- Estimates the stochastic missing data probability for both trees using the function being tested, with different combinations of the
continuous,assume_root_implicit_branch, andheritable_missing_rateparameters. - Asserts that the estimated probabilities are close to the expected values.
test_estimate_heritable_missing_data_rate
Description
Tests theestimate_missing_data_rates function for estimating the heritable missing data rate.
Inputs
Usesself.discrete_tree and self.continuous_tree
Outputs
NoneInternal Logic
- Estimates the heritable missing data rate for both trees using the function being tested, with different combinations of the
continuous,assume_root_implicit_branch, andstochastic_missing_probabilityparameters. - Asserts that the estimated rates are close to the expected values.
Dependencies
- unittest
- networkx
- numpy
- pandas
- cassiopeia
- cassiopeia.tools.parameter_estimators
- cassiopeia.mixins
Error Handling
The tests in this file primarily focus on verifying the correct error handling of the parameter estimation functions. They check for scenarios whereParameterEstimateError and ParameterEstimateWarning exceptions should be raised due to invalid input parameters or estimated values.