spatialdata_io.xenium

Contents

spatialdata_io.xenium#

spatialdata_io.xenium(path, *, cells_boundaries=True, nucleus_boundaries=True, cells_as_circles=False, cells_labels=True, nucleus_labels=True, transcripts=True, morphology_mip=True, morphology_focus=True, aligned_images=True, cells_table=True, n_jobs=None, gex_only=True, imread_kwargs=mappingproxy({}), image_models_kwargs=mappingproxy({}), labels_models_kwargs=mappingproxy({}))#

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

This function reads the following files:

  • 'experiment.xenium': File containing specifications.

  • 'nucleus_boundaries.parquet': Polygons of nucleus boundaries.

  • 'cell_boundaries.parquet': Polygons of cell boundaries.

  • 'transcripts.parquet': File containing transcripts.

  • 'cell_feature_matrix.h5': File containing cell feature matrix.

  • 'cells.parquet': File containing cell metadata.

  • 'morphology_mip.ome.tif': File containing morphology mip.

  • 'morphology_focus.ome.tif': File containing morphology focus.

Parameters:
  • path (str | Path) – Path to the dataset.

  • cells_boundaries (bool (default: True)) – Whether to read cell boundaries (polygons).

  • nucleus_boundaries (bool (default: True)) – Whether to read nucleus boundaries (polygons).

  • cells_as_circles (bool (default: False)) – Whether to read cells also as circles (the center and the radius of each circle is computed from the corresponding labels cell).

  • cells_labels (bool (default: True)) – Whether to read cell labels (raster). 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: True)) – Whether to read nucleus labels (raster). The polygonal version of the nucleus labels are simplified for visualization purposes, and using the raster version is recommended for analysis.

  • transcripts (bool (default: True)) – Whether to read transcripts.

  • morphology_mip (bool (default: True)) – Whether to read the morphology mip image (available in versions < 2.0.0).

  • morphology_focus (bool (default: True)) – Whether to read the morphology focus image.

  • 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_table (bool (default: True)) – Whether to read the cell annotations in the AnnData table.

  • n_jobs (int | None (default: None)) –

    Deprecated since version ``n_jobs``: is not used anymore and will be removed in a future release. The reading time of shapes is now greatly improved and does not require parallelization.

  • gex_only (bool (default: True)) – Whether to load only the “Gene Expression” feature type.

  • imread_kwargs (Mapping[str, Any] (default: mappingproxy({}))) – Keyword arguments to pass to the image reader.

  • image_models_kwargs (Mapping[str, Any] (default: mappingproxy({}))) – Keyword arguments to pass to the image models.

  • labels_models_kwargs (Mapping[str, Any] (default: mappingproxy({}))) – Keyword arguments to pass to the labels models.

Return type:

SpatialData

Returns:

: spatialdata.SpatialData

Notes

Old versions. Until spatialdata-io v0.6.0: cells_as_circles was True by default; the table was associated to the circles when cells_as_circles was True, and the table was associated to the polygons when cells_as_circles was False; the radii of the circles were computed form the nuclei instead of the cells.

Performance. You can improve visualization performance (at the cost of accuracy) by setting cells_as_circles to True.

Examples

This code shows how to change the annotation target of the table from the cell circles to the cell labels. >>> from spatialdata_io import xenium >>> sdata = xenium(“path/to/raw/data”, cells_as_circles=True) >>> sdata[“table”].obs[“region”] = “cell_labels” >>> sdata.set_table_annotates_spatialelement( … table_name=”table”, region=”cell_labels”, region_key=”region”, instance_key=”cell_labels” … ) >>> sdata.write(“path/to/data.zarr”)