insitupy.InSituExperiment

insitupy.InSituExperiment#

class insitupy.InSituExperiment(data_type='insitupy')#

A class to manage and analyze multiple spatially resolved single-cell transcriptomics experiments.

../../_images/insituexperiment_overview.svg

This class provides functionality for managing datasets, performing differential gene expression analysis, querying metadata, visualizing data, and saving/loading experiments. It operates on multiple datasets, each represented as an InSituData object, and maintains associated metadata in a pandas.DataFrame.

Supports two modes: 1. InSituPy mode (default): Stores InSituData objects 2. SpatialData mode: Stores StructuredSpatialData objects from SpatialData zarr stores

Examples

>>> # Create an InSituExperiment object
>>> experiment = InSituExperiment()
>>> # Add a dataset
>>> experiment.add(data="path/to/dataset", mode="insitupy", metadata={"experiment": "test"})
>>> # Read from SpatialData
>>> exp = InSituExperiment.read_spatialdata("path/to/data.zarr")
>>> # Perform differential gene expression analysis
>>> experiment.dge(target_id=0, ref_id=1, target_annotation_tuple=("cell_type", "neuron"))
>>> # Save the experiment
>>> experiment.saveas("path/to/save", overwrite=True)
>>> # Query the experiment
>>> subset = experiment.query({"experiment": ["test"]})
>>> # Plot UMAPs
>>> experiment.plot_umaps(color="cell_type", title_column="experiment")
__init__(data_type='insitupy')#

Initialize an InSituExperiment object.

Parameters:

data_type (Literal['insitupy', 'spatialdata'] (default: 'insitupy')) – The type of data to store. Either “insitupy” (default) or “spatialdata”. Note: “spatialdata” mode is currently disabled and will be enabled in a future release.

Methods

__init__([data_type])

Initialize an InSituExperiment object.

add(data[, mode, metadata])

Add a dataset to the experiment and update metadata.

add_metadata_column(column_name, values[, ...])

Add a metadata column to the experiment.

append_metadata(new_metadata[, by, overwrite])

Append metadata to the existing InSituExperiment object.

calculate_qc_metrics([cells_layer, layer, ...])

Calculate quality control metrics for the InSituExperiment.

collect_anndatas(*args, **kwargs)

concat(objs[, new_col_name])

Concatenate multiple InSituExperiment objects.

copy()

Create a deep copy of the InSituExperiment object.

dge(target_id[, ref_id, ...])

Wrapper function for performing differential gene expression analysis within an InSituExperiment object.

from_config(config_path, mode[, ...])

Create an InSituExperiment object from a configuration file.

from_regions(data, region_key[, region_names])

Creates an InSituExperiment object from specified regions in the given InSituData.

get_n_cells([cells_layer])

Get the total number of cells across all datasets.

imetadata([fixed])

Displays the experiment-level metadata as an interactive table using itables.

import_from_anndata(adata, uid_column, ...)

Import observation and observation matrix data from an AnnData object into the experiment.

import_obs(*args, **kwargs)

iterdata()

Iterate over the metadata rows and corresponding data.

load_all([skip])

Load all data modalities for all datasets.

load_annotations()

Load annotations for all datasets.

load_cells()

Load cells for all datasets.

load_images([names, overwrite, verbose])

Load images for all datasets.

load_regions()

Load regions for all datasets.

load_transcripts([transcript_filename])

Load transcripts for all datasets.

plot_embedding(basis[, cells_layer, color, ...])

Create a plot with embeddings of all datasets as subplots.

plot_overview(*args, **kwargs)

plot_umaps([cells_layer, color, ...])

Create a plot with UMAPs of all datasets as subplots.

query(criteria)

Query the experiment based on metadata criteria.

read(path[, mode, filter_key])

Read an InSituExperiment object from a specified folder.

remove_history()

Remove history from all datasets.

remove_metadata_columns(columns)

Remove specified columns from the internal metadata.

save([verbose, collect_warnings_mode])

Save the full experiment to its existing project path.

save_colors([path, overwrite])

Save only experiment colors to colors.json.

save_filters([path])

Save only experiment filters to filters.json.

save_images([overwrite, collect_warnings_mode])

Save only image data for datasets in the experiment.

save_metadata([path, overwrite])

Save only experiment metadata to metadata.csv.

saveas(path[, overwrite, verbose, ...])

Save experiment to a new location (initial full write).

set_metadata_values(index, column_name, values)

Set metadata values for one or more indices.

show(index[, verbose])

Displays the dataset at the specified index.

show_modality(modality[, uid_column])

Show a modality for all datasets.

sync_colors(keys[, cells_layer, palette, ...])

Synchronize color dictionaries for categorical metadata across datasets.

to_anndata([cells_layer, label_col, ...])

Concatenate all datasets into a single AnnData object.

Attributes

annotations

Displays a summary of the 'annotations' modality for all datasets.

applied_filters

cells

Displays a summary of cells for all datasets.

colors

Color dictionaries created by sync_colors().

data

List of datasets as InSituData or StructuredSpatialData objects.

data_type

The type of data stored in this experiment ('insitupy' or 'spatialdata').

filter_masks

Raw filter dictionary mapping keys to boolean masks.

filters

Filter manager exposing filter operations (create, remove, clear, apply, view, rename).

images

Displays a summary of the 'images' modality for all datasets.

is_view

metadata

Returns the experiment-level metadata as a pandas DataFrame.

path

Save path of the InSituExperiment object.

regions

Displays a summary of the 'regions' modality for all datasets.

transcripts

Displays a summary of the 'transcripts' modality for all datasets.