parameter_estimators_test.py
High-level description
This file contains unit tests for the parameter_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
The TestCassiopeiaTree
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
None
Outputs
None
Internal Logic
The class uses the unittest
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 the get_proportion_of_mutation
and get_proportion_of_missing_data
functions.
Inputs
Uses self.discrete_tree
and self.continuous_tree
Outputs
None
Internal 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 the estimate_mutation_rate
function.
Inputs
Uses self.discrete_tree
and self.continuous_tree
Outputs
None
Internal Logic
- Estimates the mutation rate for both trees using the function being tested, with different combinations of the
continuous
andassume_root_implicit_branch
parameters. - Asserts that the estimated mutation rates are close to the expected values.
test_estimate_missing_data_bad_cases
Description
Tests the error handling of the estimate_missing_data_rates
function.
Inputs
Uses self.discrete_tree
and self.continuous_tree
Outputs
None
Internal Logic
- Defines several scenarios where the
estimate_missing_data_rates
function should raise either aParameterEstimateError
or aParameterEstimateWarning
. - Uses
assertRaises
to verify that the expected exceptions are raised in each scenario.
test_estimate_stochastic_missing_data_probability
Description
Tests the estimate_missing_data_rates
function for estimating the stochastic missing data probability.
Inputs
Uses self.discrete_tree
and self.continuous_tree
Outputs
None
Internal 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_rate
parameters. - Asserts that the estimated probabilities are close to the expected values.
test_estimate_heritable_missing_data_rate
Description
Tests the estimate_missing_data_rates
function for estimating the heritable missing data rate.
Inputs
Uses self.discrete_tree
and self.continuous_tree
Outputs
None
Internal 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_probability
parameters. - 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 where ParameterEstimateError
and ParameterEstimateWarning
exceptions should be raised due to invalid input parameters or estimated values.