Layers class in the cassiopeia/data/Layers.py file:
High-level description
TheLayers class implements a data structure for storing multiple versions of mutation data for each cell in a CassiopeiaTree object. It behaves like a dictionary, allowing users to store, retrieve, and delete entries using standard dictionary operations.
Code Structure
TheLayers class is a subclass of dict and is closely tied to the CassiopeiaTree class. It maintains a reference to its parent CassiopeiaTree object and stores layer data in an internal dictionary.
Symbols
Layers
Description
A class that represents a collection of character matrices, each storing a version of mutation data for cells in a CassiopeiaTree.Inputs
Internal Logic
- Initializes with a reference to the parent CassiopeiaTree and an empty internal dictionary.
- If initial layers are provided, they are added to the internal dictionary.
- Implements dictionary-like methods for accessing, setting, and deleting layers.
- Provides custom string representation and iPython key completion.
repr
Description
Returns a string representation of the Layers object.Outputs
ipython_key_completions
Description
Returns a list of keys for iPython autocompletion.Outputs
copy
Description
Creates a shallow copy of the Layers object.Outputs
getitem
Description
Retrieves a layer by key.Inputs
Outputs
setitem
Description
Sets a layer with the given key and value.Inputs
Internal Logic
- Validates the input value using the
_validate_valuemethod. - Stores the validated value in the internal dictionary.
delitem
Description
Deletes a layer with the given key.Inputs
contains
Description
Checks if a layer with the given key exists.Inputs
Outputs
iter
Description
Returns an iterator over the layer keys.Outputs
len
Description
Returns the number of layers.Outputs
_validate_value
Description
Validates the input value for a layer.Inputs
Outputs
Internal Logic
- Checks if the input value has the correct number of samples (rows) compared to the parent CassiopeiaTree.
- Raises a ValueError if the shape is incorrect.
Dependencies
This
Layers class provides a flexible way to store and manage multiple versions of mutation data for cells in a CassiopeiaTree object, allowing for easy experimentation with different data representations or imputations.