insitupy.InSituExperiment#
- class insitupy.InSituExperiment#
A class to manage and analyze multiple spatially resolved single-cell transcriptomics experiments.
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
InSituDataobject, and maintains associated metadata in apandas.DataFrame.Examples
>>> # Create an InSituExperiment object >>> experiment = InSituExperiment()
>>> # Add a dataset >>> experiment.add(data="path/to/dataset", mode="insitupy", metadata={"experiment": "test"})
>>> # 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__()#
Initialize an InSituExperiment object.
Methods
__init__()Initialize an InSituExperiment object.
add(data[, mode, metadata])Add a dataset to the experiment and update metadata.
add_metadata_column(column_name, values)append_metadata(new_metadata, by[, overwrite])Append metadata to the existing InSituExperiment object.
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
InSituExperimentobject.from_config(config_path[, mode])Create an InSituExperiment object from a configuration file.
from_regions(data, region_key[, region_names])Creates an
InSituExperimentobject from specified regions in the givenInSituData.get_n_cells([cells_layer])Get the total number of cells across all datasets.
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_cells()load_images([names, nuclei_type, ...])load_regions()load_transcripts([transcript_filename])plot_embedding(basis[, cells_layer, color, ...])Create a plot with embeddings of all datasets as subplots using scanpy's sc.pl.embedding function.
plot_overview(*args, **kwargs)plot_umaps([cells_layer, color, ...])Create a plot with UMAPs of all datasets as subplots using scanpy's pl.umap function.
query(criteria)Query the experiment based on metadata criteria.
read(path)Read an InSituExperiment object from a specified folder.
remove_history()remove_metadata_columns(columns)Remove specified columns from the internal metadata.
save([verbose, overwrite_metadata, ...])saveas(path[, overwrite, verbose])Save all datasets to a specified folder.
show(index[, verbose])Displays the dataset at the specified index.
show_modality(modality[, uid_column])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
annotationsDisplays a summary of the 'annotations' modality for all datasets.
cellsDisplays a summary of
cellsfor all datasets.colorsColor dictionaries created by
sync_colors().dataList of datasets as
InSituDataobjects.imagesDisplays a summary of the 'images' modality for all datasets.
metadataReturns a copy of the experiment-level metadata.
pathSave path of the InSituExperiment object.
regionsDisplays a summary of the 'regions' modality for all datasets.
transcriptsDisplays a summary of the 'transcripts' modality for all datasets.