insitupy.io.read_xenium

Contents

insitupy.io.read_xenium#

insitupy.io.read_xenium(path, nuclei_type='focus', load_cell_segmentation_images=False, load_background_images=False, verbose=True, transcript_mode='dask', restructure_transcripts=False, slide_id='slide_id', sample_id='sample_id', backend='insitupy')#

Reads Xenium In Situ data from the specified directory.

Parameters:
  • path (Union[str, PathLike, Path]) – Path to the Xenium data bundle.

  • nuclei_type (Literal['focus', 'mip', ''] (default: 'focus')) – Type of nuclei image to load. Defaults to “focus”. If “mip” is unavailable, “focus” will be used as a fallback.

  • load_cell_segmentation_images (bool (default: False)) – Whether to load cell segmentation images. Defaults to False.

  • load_background_images (bool (default: False)) – Whether to load background images. Defaults to False.

  • verbose (bool (default: True)) – Whether to print progress messages. Defaults to True.

  • transcript_mode (Literal['pandas', 'dask'] (default: 'dask')) – Mode to load transcript data. Defaults to “dask”. - “pandas”: Loads the data into a pandas DataFrame. - “dask”: Loads the data into a Dask DataFrame for larger datasets.

  • restructure_transcripts (bool (default: False)) – Whether to restructure the transcript data. Defaults to False.

  • slide_id (str (default: 'slide_id')) – Identifier for the slide. Defaults to “slide_id”. Only used with spatialdata backend.

  • sample_id (str (default: 'sample_id')) – Identifier for the sample. Defaults to “sample_id”. Only used with spatialdata backend.

  • backend (Literal['insitupy', 'spatialdata'] (default: 'insitupy')) – Backend to use for loading data. Defaults to “insitupy”. - “insitupy”: Uses the native InSituPy loader. - “spatialdata”: Uses spatialdata-io to load the data and converts to InSituData format.

Returns:

An object containing the processed Xenium experiment data, including metadata, cells, images, and transcripts.

Return type:

InSituData

Raises:
  • InvalidXeniumDirectory – If the specified directory does not contain the required Xenium metadata file.

  • FileNotFoundError – If the specified directory does not exist.

  • ValueError – If an invalid value is provided for transcript_mode or backend.

Notes

  • The function initializes an InSituData object with metadata and loads cell data, images, and transcripts.

  • For Xenium versions <2.0, the “mip” image is used if available; otherwise, the “focus” image is loaded.

  • Cell segmentation images are loaded if available and load_cell_segmentation_images is True.

  • Background images are loaded if available and load_background_images is True.

  • Transcript data can be loaded using either pandas or Dask, depending on the transcript_mode parameter.

  • The spatialdata backend provides interoperability with the SpatialData ecosystem.