harpy.io.xenium#
- harpy.io.xenium(path, to_coordinate_system='global', aligned_images=True, cells_labels=True, nucleus_labels=True, morphology_mip=False, morpholohy_focus=True, cells_table=True, filter_gene_names=None, imread_kwargs=mappingproxy({}), image_models_kwargs=mappingproxy({}), labels_models_kwargs=mappingproxy({}), instance_key='cell_ID', region_key='fov_labels', spatial_key='spatial', output=None)#
Read a 10X Genomics Xenium dataset into a
SpatialDataobject.Wrapper around
spatialdata_io.xenium()that adds some additional capabilities: (i) adding a micron-based coordinate system, and (ii) loading multiple samples into a single SpatialData object.This function reads images, transcripts, masks (cell and nuclei) and tables, so it can be used for analysis. The resulting
AnnDatatable will be annotated by a labels element.The micron coordinate system is added as ‘{to_coordinate_system}_micron’ and is available to all spatial elements within the resulting SpatialData object.
Cell and nuclear boundaries provided by Xenium will not be loaded, as these polygonal versions of the cell and nucleus labels are approximations. They can however be generated from the cell and nuclear labels using
harpy.sh.vectorize().This function reads the following files:
{xx.XENIUM_SPECS!r}: File containing specifications.{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.
See also
- 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 inpath.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 toFalseand use thexenium_aligned_imagefunction directly.cells_labels (
bool(default:True)) – 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:True)) – 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.morphology_mip (
bool(default:False)) – Whether to read the morphology mip image (available in versions < 2.0.0).morphology_focus – Whether to read the morphology focus image.
cells_table (
bool(default:True)) – Whether to read the cell annotations in theAnnDatatable. Will be added to thef"table_{to_coordinate_system}"slot insdata.tables, or f”table_{to_coordinate_system[i]}” ifto_coordinate_systemis a list. IfTrue, labels element annotating the table will also be added tosdata.filter_gene_names (
str|list[str] (default:None)) – Gene names that need to be filtered out (viastr.contains), mostly control genes that were added, and which you don’t want to use. Filtering is case insensitive. Also seeharpy.read_transcripts().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.instance_key (
str(default:'cell_ID')) – Instance key. The name of the column inAnnDatatable.obsthat will hold the instance ids. Ignored iftableisFalse.region_key (
str(default:'fov_labels')) – Region key. The name of the column inAnnDatatable.obsthat will hold the name of the elements that annotate the table. Ignored iftableisFalse.spatial_key (
str(default:'spatial')) – The key in theAnnDatatable.obsmthat will hold thexandycenter of the instances. Ignored iftableisFalse.output (
str|Path|None(default:None)) – The path where the resultingSpatialDataobject object will be backed. IfNone, it will not be backed to a Zarr store.
- Raises:
AssertionError – Raised when the number of elements in
pathandto_coordinate_systemare not the same.AssertionError – If elements in
to_coordinate_systemare not unique.AssertionError – If
cells_tableisTrue, but the labels element annotating the table is not found.
- Return type:
- Returns:
: A
SpatialDataobject object.