sparrow.io.xenium

Contents

sparrow.io.xenium#

sparrow.io.xenium(path, to_coordinate_system='global', aligned_images=True, cells_labels=False, nucleus_labels=False, cells_table=False, filter_gene_names=None, output=None)#

Read a 10X Genomics Xenium dataset into a SpatialData object.

Wrapper around spatialdata_io.xenium, but with support for reading multiple samples into one spatialdata object. This function reads images, transcripts, masks (cell and nuclei) and tables, so it can be used for analysis.

This function reads the following files:

  • {xx.XENIUM_SPECS!r}: File containing specifications.

  • {xx.NUCLEUS_BOUNDARIES_FILE!r}: Polygons of nucleus boundaries.

  • {xx.CELL_BOUNDARIES_FILE!r}: Polygons of cell boundaries.

  • {xx.TRANSCRIPTS_FILE!r}: File containing transcripts.

  • {xx.CELL_FEATURE_MATRIX_FILE!r}: File containing cell feature matrix.

  • {xx.CELL_METADATA_FILE!r}: File containing cell metadata.

  • {xx.MORPHOLOGY_MIP_FILE!r}: File containing morphology mip.

  • {xx.MORPHOLOGY_FOCUS_FILE!r}: File containing morphology focus.

Parameters:
  • path (str | Path | list[str] | list[Path]) – Specifies the location of the dataset. This can either be a single path or a list of paths, where each path corresponds to a different experiment/roi.

  • to_coordinate_system (str | list[str] (default: 'global')) – The coordinate system to which the images, segmentation masks and transcripts will be added for each item in path. If provided as a list, its length should be equal to the number of paths specified in path.

  • aligned_images (bool (default: True)) – Whether to also parse, when available, additional H&E or IF aligned images. For more control over the aligned images being read, in particular, to specify the axes of the aligned images, please set this parameter to False and use the xenium_aligned_image function directly.

  • cells_labels (bool (default: False)) – Whether to read cell labels (raster) provided by Xenium. The polygonal version of the cell labels are simplified for visualization purposes, and using the raster version is recommended for analysis.

  • nucleus_labels (bool (default: False)) – Whether to read nucleus labels (raster) provided by Xenium. The polygonal version of the nucleus labels are simplified for visualization purposes, and using the raster version is recommended for analysis.

  • cells_table (bool (default: False)) – Whether to read the cell annotations in the AnnData table. Will be added to the f"table_{to_coordinate_system}" slot in sdata.tables, or f”table_{to_coordinate_system[i]}” if to_coordinate_system is a list. If True, labels layer annotating the table will also be added to sdata.

  • filter_gene_names (str | list[str] (default: None)) – Gene names that need to be filtered out (via str.contains), mostly control genes that were added, and which you don’t want to use. Filtering is case insensitive. Also see sparrow.read_transcripts.

  • output (str | Path | None (default: None)) – The path where the resulting SpatialData object will be backed. If None, it will not be backed to a zarr store.

Raises:
  • AssertionError – Raised when the number of elements in path and to_coordinate_system are not the same.

  • AssertionError – If elements in to_coordinate_system are not unique.

  • AssertionError – If cells_table is True, but the labels layer annotating the table is not found.

Return type:

SpatialData

Returns:

: A SpatialData object.