High-level description
TheCas9LineageTracingDataSimulator class simulates Cas9-based lineage tracing data by overlaying mutations onto a CassiopeiaTree. It models Cas9 cutting as an exponential process and incorporates features like cassettes, state distributions, and silencing rates to mimic real-world lineage tracing experiments.
Code Structure
TheCas9LineageTracingDataSimulator class inherits from the LineageTracingDataSimulator class. It defines several parameters in its constructor to control the simulation process, such as the number of cassettes, size of each cassette, mutation rate, state distribution, and silencing rates. The main functionality is implemented in the overlay_data method, which modifies the character states of the input CassiopeiaTree in place.
References
cassiopeia.data.CassiopeiaTree: The class representing the tree structure on which the data is overlaid.cassiopeia.simulator.LineageTracingDataSimulator: The parent class defining the interface for lineage tracing data simulators.
Symbols
Cas9LineageTracingDataSimulator
Description
This class simulates Cas9-based lineage tracing data by overlaying mutations onto a CassiopeiaTree. It models Cas9 cutting as an exponential process and incorporates features like cassettes, state distributions, and silencing rates to mimic real-world lineage tracing experiments.Inputs
Outputs
NoneInternal Logic
The constructor initializes the simulator with the provided parameters and performs several checks to ensure the validity of the input. It also pre-computes the mutation rate and state priors for each character in the lineage.overlay_data
Description
This method overlays Cas9-based lineage tracing data onto the provided CassiopeiaTree. It simulates mutations, silencing events, and cassette dropouts based on the parameters specified in the constructor.Inputs
Outputs
NoneInternal Logic
- Initialize character states: Sets all character states to 0 (unmutated) for the root node and -1 (missing) for all other nodes.
- Simulate mutations: For each non-root node, calculate the mutation probability for each open site based on the node’s lifetime and the site’s mutation rate. Randomly introduce mutations based on these probabilities.
- Collapse sites on cassettes: If
collapse_sites_on_cassetteis True andsize_of_cassetteis greater than 1, collapse cuts that occur within the same cassette in a single iteration. - Introduce states at cut sites: For each cut site, randomly select a state from the state distribution and assign it to the site.
- Silence cassettes: Randomly silence entire cassettes based on the heritable silencing rate.
- Apply stochastic silencing: Randomly drop out cassettes at the leaves based on the stochastic silencing rate.
- Set character states: Update the character states of all nodes in the tree based on the simulated mutations and silencing events.
collapse_sites
Description
This method collapses cassettes by identifying cuts that occur within the same cassette and collapsing the sites between them.Inputs
Outputs
Internal Logic
- Identify cassettes with multiple cuts: Group the cuts by the cassette they belong to.
- Collapse sites within cassettes: For each cassette with multiple cuts, identify the leftmost and rightmost cut sites and set all sites between them to the heritable missing data state.
- Return updated character array and remaining cuts: Return the updated character array and the list of cuts that were not part of a cassette collapse.
introduce_states
Description
This method introduces new states at the specified cut sites in the character array.Inputs
Outputs
Internal Logic
- Iterate over cut sites: For each cut site, randomly select a state from the state distribution based on the site’s prior probabilities.
- Assign new states: Assign the selected state to the corresponding site in the character array.
- Return updated character array: Return the updated character array.
silence_cassettes
Description
This method randomly silences cassettes based on the specified silencing rate.Inputs
Outputs
Internal Logic
- Iterate over cassettes: For each cassette, randomly decide whether to silence it based on the silencing rate.
- Silence cassettes: If a cassette is selected for silencing, set all sites within that cassette to the missing data state.
- Return updated character array: Return the updated character array.
get_cassettes
Description
This method returns a list of indices corresponding to the start positions of the cassettes in the character array.Inputs
NoneOutputs
Internal Logic
Calculates the start positions of each cassette based on thesize_of_cassette and number_of_cassettes parameters.
Side Effects
Theoverlay_data method modifies the character states of the input CassiopeiaTree in place.
Dependencies
numpy: Used for random number generation and array operations.pandas: Used for representing the character matrix.
Error Handling
The constructor raisesDataSimulatorError if any of the input parameters are invalid.