API#

Import SPArrOW as:

import sparrow as sp

IO#

I/O.

io.create_sdata(input[, output_path, ...])

Convert input images or arrays into a SpatialData object with the image added as an image layer with name img_layer.

io.read_transcripts(sdata, path_count_matrix)

Reads transcript information from a file with each row listing the x and y coordinates, along with the gene name.

io.read_resolve_transcripts(sdata, ...[, ...])

Reads and adds Resolve transcript information to a SpatialData object.

io.read_vizgen_transcripts(sdata, ...[, ...])

Reads and adds Vizgen transcript information to a SpatialData object.

io.read_stereoseq_transcripts(sdata, ...[, ...])

Reads and adds Stereoseq transcript information to a SpatialData object.

Image#

Operations on image and labels layers.

im.add_image_layer(sdata, arr, output_layer)

Add an image layer to a SpatialData object.

im.add_labels_layer(sdata, arr, output_layer)

Add a labels layer to a SpatialData object.

im.map_channels_zstacks(sdata, img_layer, ...)

Apply a specified function to an image layer of a SpatialData object.

im.tiling_correction(sdata[, img_layer, ...])

Function corrects for the tiling effect that occurs in some image data (e.g. resolve data).

im.enhance_contrast(sdata[, img_layer, ...])

Enhance the contrast of an image in a SpatialData object.

im.normalize(sdata, img_layer, output_layer)

Normalize the intensity of an image layer in a SpatialData object using specified percentiles.

im.min_max_filtering(sdata[, img_layer, ...])

Apply min max filtering to an image in a SpatialData object using dask (using dask_image.ndfilters.maximum_filter and dask_image.ndfilters.minimum_filter).

im.gaussian_filtering(sdata[, img_layer, ...])

Apply Gaussian filtering to an image in a SpatialData object using dask.

im.transcript_density(sdata[, img_layer, ...])

Calculate the transcript density using gaussian filter and add it to the provided spatial data.

im.combine(sdata, img_layer, output_layer[, ...])

Combines specific channels within an image layer of a SpatialData object.

im.segment(sdata, img_layer[, model, ...])

Segment images using a provided model and add segmentation results (labels layer and shapes layer) to the SpatialData object.

im.segment_points(sdata, labels_layer, ...)

Segment images using a points_layer and a prior (labels_layer) and add segmentation results (labels layer and shapes layer) to the SpatialData object.

im.add_grid_labels_layer(sdata, shape, size, ...)

Adds a grid-based labels layer to the SpatialData object using either a hexagonal or square grid.

im.expand_labels_layer(sdata, labels_layer)

Expand cells in labels layer labels_layer of Spatialdata object with distance, using skimage.segmentation.expand_labels.

im.align_labels_layers(sdata, ...[, depth, ...])

Align two labels layers.

im.apply_labels_layers(sdata, func, ...[, ...])

Apply a specified function to a labels layer in a SpatialData object.

im.filter_labels_layer(sdata, labels_layer)

Filter labels in labels layer labels_layer of Spatialdata object that have a size less than min_size or size greater than max_size.

im.merge_labels_layers(sdata, ...[, ...])

Merges two labels layers within a SpatialData object based on a specified threshold.

im.merge_labels_layers_nuclei(sdata, ...[, ...])

Merge labels layers using nuclei segmentation.

im.rasterize(sdata, shapes_layer, output_layer)

Given a shapes layer in a SpatialData object, corresponding masks are created, and added as a labels layer to the SpatialData object.

im.mask_to_original(sdata, labels_layer, ...)

Map to original.

im.pixel_clustering_preprocess(sdata, ...[, ...])

Preprocess image layers specified in img_layer.

im.flowsom(sdata, img_layer, ...[, ...])

Applies flowsom clustering on image layer(s) of a SpatialData object.

Shape#

Operations on shapes (polygons) layers.

sh.add_shapes_layer(sdata, input, output_layer)

Add a shapes layer to a SpatialData object.

sh.filter_shapes_layer(sdata, table_layer, ...)

Filter shapes in a SpatialData object.

sh.create_voronoi_boundaries(sdata[, ...])

Create Voronoi boundaries from the shapes layer of the provided SpatialData object.

Table#

Operations on table (AnnData object) layers.

tb.add_table_layer(sdata, adata, ...[, ...])

Add a table layer to a SpatialData object.

tb.allocate(sdata, labels_layer[, ...])

Allocates transcripts to cells via provided labels_layer and points_layer and returns updated SpatialData object with a table layer (sdata.tables[output_layer]) holding the AnnData object with cell counts.

tb.allocate_intensity(sdata[, img_layer, ...])

Allocates intensity values from a specified image layer to corresponding cells in a SpatialData object and returns an updated SpatialData object augmented with a table layer (sdata.tables[output_layer]) AnnData object with intensity values for each cell and each (specified) channel.

tb.preprocess_transcriptomics(sdata, ...[, ...])

Preprocess a table (AnnData) attribute of a SpatialData object for transcriptomics data.

tb.preprocess_proteomics(sdata, ...[, ...])

Preprocess a table (AnnData) attribute of a SpatialData object for proteomics data.

tb.filter_on_size(sdata, labels_layer, ...)

Returns the updated SpatialData object.

tb.leiden(sdata, labels_layer, table_layer, ...)

Applies leiden clustering on the table_layer of the SpatialData object with optional UMAP calculation and gene ranking.

tb.kmeans(sdata, labels_layer, table_layer, ...)

Applies KMeans clustering on the table_layer of the SpatialData object with optional UMAP calculation and gene ranking.

tb.score_genes(sdata, labels_layer, ...[, ...])

The function loads marker genes from a CSV file and scores cells for each cell type using those markers using scanpy's sc.tl.score_genes function.

tb.score_genes_iter(sdata, labels_layer, ...)

Iterative annotation algorithm.

tb.correct_marker_genes(sdata, labels_layer, ...)

Correct celltype expression in sdata.tables[table_layer] using celltype_correction_dict.

tb.cluster_cleanliness(sdata, labels_layer, ...)

Re-calculates annotations, potentially following corrections to the list of celltypes, or after a manual update of the assigned scores per cell type via e.g. correct_marker_genes.

tb.nhood_enrichment(sdata, labels_layer, ...)

Calculate the nhood enrichment using squidpy via sq.gr.spatial_neighbors and sq.gr.nhood_enrichment.

tb.add_regionprop_features(sdata[, ...])

Enhances a SpatialData object with region property features calculated from the specified labels layer, updating its table attribute (sdata.tables[table_layer]) with these computed cellular properties.

tb.cluster_intensity(sdata, mapping, ...[, ...])

Calculates average intensity of each channel in img_layer per SOM cluster as available in the labels_layer, and saves it as a table layer in sdata as output_layer.

tb.cell_clustering_preprocess(sdata, ...[, ...])

Preprocesses spatial data for cell clustering.

tb.flowsom(sdata, labels_layer_cells, ...[, ...])

Prepares the data obtained from pixel clustering for cell clustering (see docstring of sp.tb.cell_clustering_preprocess) and then executes the FlowSOM clustering algorithm on the resulting table layer (output_layer) of the SpatialData object.

tb.weighted_channel_expression(sdata, ...[, ...])

Calculation of weighted channel expression in the context of cell clustering.

Points#

Operations on points (Dask DataFrame object) layers.

pt.add_points_layer(sdata, ddf, ...[, ...])

Add a points layer to a SpatialData object.

Plotting#

Plotting functions.

General plots#

pl.plot_image(sdata[, img_layer, channel, ...])

Plot an image based on given parameters.

pl.plot_shapes(sdata[, img_layer, ...])

Plot shapes and/or images/labels from a SpatialData object.

pl.plot_labels(sdata[, labels_layer, ...])

Plot a labels layer (masks) based on given parameters.

pl.tiling_correction(sdata[, img_layer, ...])

Visualizes the effect of tiling correction.

pl.flatfield(flatfield[, output])

Visualize the correction performed per tile using a flatfield image.

pl.segment(sdata[, img_layer, shapes_layer, ...])

Visualize obtained shapes layer (i.e. segmentation mask boundaries) from a SpatialData object.

Proteomics plots#

pl.snr_ratio(sdata[, ax, loglog, color, groupby])

Plot the signal to noise ratio.

pl.group_snr_ratio(sdata, groupby[, ax, ...])

Plot the signal to noise ratio.

pl.snr_clustermap(sdata[, signal_threshold, ...])

pl.signal_clustermap(sdata[, ...])

pl.clustermap(*args, **kwargs)

pl.segmentation_coverage(sdata[, ax])

pl.segmentation_size_boxplot(sdata[, ...])

pl.segments_per_area(sdata[, ax])

Transcriptomics plots#

pl.sanity_plot_transcripts_matrix(sdata[, ...])

Produce a sanity plot to visualize spatial transcriptomics data on top of an image.

pl.analyse_genes_left_out(sdata, ...[, ...])

Analyse and visualize the proportion of genes that could not be assigned to a cell during allocation step.

pl.transcript_density(sdata[, img_layer, ...])

Visualize the transcript density layer.

pl.preprocess_transcriptomics(sdata[, ...])

Function plots the size of the nucleus/cell related to the counts.

pl.cluster(sdata, table_layer[, key_added, ...])

Visualize clusters.

pl.score_genes(sdata, table_layer, celltypes)

Function generates following plots:

pl.cluster_cleanliness(sdata, table_layer[, ...])

Generate plots that allow assessing the "cleanliness" or accuracy of the cell clustering:

pl.nhood_enrichment(sdata, table_layer[, ...])

Plot the neighborhood enrichment across cell-type annotations.

Utils#

Utility functions.

utils.bounding_box_query(sdata, ...[, ...])

Query the labels layers of a SpatialData object and the corresponding instances it annotates in sdata.tables via a bounding box query.

Datasets#

Dataset loaders.

datasets.cluster_blobs([shape, ...])

Differs from spatialdata.datasets.make_blobs in that it generates cells with multiple image channels and known ground truth cell types.

datasets.multisample_blobs([n_samples, prefix])

Multisample blobs.

datasets.pixie_example([fovs, ...])

Example pixie dataset.

datasets.macsima_example()

Example proteomics dataset

datasets.mibi_example()

Example proteomics dataset

datasets.vectra_example()

Example proteomics dataset LuCa-7color_[13860,52919]_1x1 from Perkin Elmer

datasets.resolve_example()

Example transcriptomics dataset

datasets.get_registry([path])

Get the Pooch registry

datasets.get_spatialdata_registry([path])

Get the Pooch SpatialData registry