> ## Documentation Index
> Fetch the complete documentation index at: https://demo.agenticlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Layers.py

Here's a detailed documentation for the `Layers` class in the `cassiopeia/data/Layers.py` file:

## High-level description

The `Layers` 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

The `Layers` 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

| Name   | Type               | Description                           |
| :----- | :----------------- | :------------------------------------ |
| parent | CassiopeiaTree     | The parent CassiopeiaTree object      |
| layers | Optional\[Mapping] | Initial layers to populate the object |

#### 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

| Name   | Type | Description                                |
| :----- | :--- | :----------------------------------------- |
| return | str  | String representation of the Layers object |

### *ipython\_key\_completions*

#### Description

Returns a list of keys for iPython autocompletion.

#### Outputs

| Name   | Type       | Description        |
| :----- | :--------- | :----------------- |
| return | List\[str] | List of layer keys |

### copy

#### Description

Creates a shallow copy of the Layers object.

#### Outputs

| Name   | Type   | Description                          |
| :----- | :----- | :----------------------------------- |
| return | Layers | A new Layers object with copied data |

### **getitem**

#### Description

Retrieves a layer by key.

#### Inputs

| Name | Type | Description                      |
| :--- | :--- | :------------------------------- |
| key  | str  | The key of the layer to retrieve |

#### Outputs

| Name   | Type         | Description              |
| :----- | :----------- | :----------------------- |
| return | pd.DataFrame | The requested layer data |

### **setitem**

#### Description

Sets a layer with the given key and value.

#### Inputs

| Name  | Type         | Description           |
| :---- | :----------- | :-------------------- |
| key   | str          | The key for the layer |
| value | pd.DataFrame | The layer data to set |

#### Internal Logic

* Validates the input value using the `_validate_value` method.
* Stores the validated value in the internal dictionary.

### **delitem**

#### Description

Deletes a layer with the given key.

#### Inputs

| Name | Type | Description                    |
| :--- | :--- | :----------------------------- |
| key  | str  | The key of the layer to delete |

### **contains**

#### Description

Checks if a layer with the given key exists.

#### Inputs

| Name | Type | Description          |
| :--- | :--- | :------------------- |
| key  | str  | The key to check for |

#### Outputs

| Name   | Type | Description                             |
| :----- | :--- | :-------------------------------------- |
| return | bool | True if the key exists, False otherwise |

### **iter**

#### Description

Returns an iterator over the layer keys.

#### Outputs

| Name   | Type           | Description              |
| :----- | :------------- | :----------------------- |
| return | Iterator\[str] | Iterator over layer keys |

### **len**

#### Description

Returns the number of layers.

#### Outputs

| Name   | Type | Description      |
| :----- | :--- | :--------------- |
| return | int  | Number of layers |

### \_validate\_value

#### Description

Validates the input value for a layer.

#### Inputs

| Name | Type         | Description                       |
| :--- | :----------- | :-------------------------------- |
| val  | pd.DataFrame | The value to validate             |
| key  | str          | The key associated with the value |

#### Outputs

| Name   | Type         | Description         |
| :----- | :----------- | :------------------ |
| return | pd.DataFrame | The validated value |

#### 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

| Dependency                     | Purpose                |
| :----------------------------- | :--------------------- |
| typing                         | Type hinting           |
| pandas                         | DataFrame operations   |
| cassiopeia.data.CassiopeiaTree | Parent class reference |

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.
