harpy.io.merscope#
- harpy.io.merscope(path, to_coordinate_system='global', z_layers=3, backend=None, transcripts=True, cell_boundaries=True, rasterize_cell_boundaries=True, table=True, mosaic_images=True, do_3D=False, z_projection=False, imread_kwargs=mappingproxy({}), image_models_kwargs=mappingproxy({}), filter_gene_names=None, instance_key='cell_ID', region_key='fov_labels', spatial_key='spatial', cell_index_name='cells', output=None)#
Read MERSCOPE data from Vizgen.
A wrapper around
spatialdata_io.merscope()that adds some additional capabilities: (i) loading data in full 3D (z, y, x) or applying a z-projection, (ii) loading both the unprocessed and processedAnnDatatable (with leiden clusters) provided by Vizgen, (iii) rasterizing cell boundaries, (iv) adding a micron-based coordinate system, and (v) loading multiple samples into a single SpatialData object.The micron coordinate system is added as ‘{to_coordinate_system}_micron’ and is available to all spatial elements within the resulting SpatialData object.
This function reads the following files:
{ms.TRANSCRIPTS_FILE!r}: Transcript file.mosaic_**_z*.tifimages inside the{ms.IMAGES_DIR!r}directory.
- Parameters:
path (
str|Path|list[str] |list[Path]) – Path to the region/root directory containing the Merscope files (e.g.,detected_transcripts.csv). 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 elements 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. A micron coordinate system will be added at ‘{to_coordinate_system}_micron’.z_layers (
int|list[int] |None(default:3)) – Indices of the z-layers to consider. Either oneintindex, or a list ofintindices. IfNone, then no image is loaded. By default, only the middle layer is considered (that is, layer 3).backend (
Optional[Literal['dask_image','rioxarray']] (default:None)) – Either"dask_image"or"rioxarray"(the latter uses less RAM, but requiresrioxarrayto be installed). By default, uses"rioxarray"if and only if therioxarraylibrary is installed.transcripts (
bool(default:True)) – Whether to read transcripts.cell_boundaries (
bool(default:True)) – Whether to read cell boundaries (polygons).rasterize_cell_boundaries (
bool(default:True)) – Whether to rasterize the cell boundaries (i.e. create a labels element from polygons). We useharpy.im.rasterize()to rasterize the cell boundaries. Ignored ifcell_boundariesisFalse, or ifmosaic_imagesisFalse.table (
bool(default:True)) – Whether to read in theAnnDatatable. The table will be annotated by a labels element. Iftableis set toTruethencell_boundaries,rasterize_cell_boundariesandmosaic_imagesmust also be set toTrue.mosaic_images (
bool(default:True)) – Whether to read the mosaic images.do_3D (
bool(default:False)) – Read the mosaic images and the transcripts as 3D.z_projection (
bool(default:False)) – Perform a z projection (maximum intensity along the z-stacks) on z-stacks of mosaic images. Ignored ifmosaic_imagesisFalse.imread_kwargs (
Mapping[str,Any] (default:mappingproxy({}))) – Keyword arguments to pass to the image reader. Ignored ifmosaic_imagesisFalse.image_models_kwargs (
Mapping[str,Any] (default:mappingproxy({}))) – Keyword arguments to pass to the image models. Ignored ifmosaic_imagesisFalse.filter_gene_names (
str|list[str] (default:None)) – Gene names that need to be filtered out (viastr.contains) from the resulting points element (transcripts), mostly control genes that were added, and which you don’t want to use. Filtering is case insensitive. Also seeharpy.read_transcripts(). Ignored iftranscriptsisFalse.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 are annotated by the table. Ignored iftableisFalse.spatial_key (
str(default:'spatial')) – The key in theAnnDatatable.obsmthat will hold thexandycenter of the instances. Ignored iftableisFalse.cell_index_name (
str(default:'cells')) – The name of the index of the resultingAnnDatatable. Ignored iftableisFalse.output (
str|Path|None(default:None)) – The path where the resultingSpatialDataobject will be backed. IfNone, it will not be backed to a zarr store.
- Raises:
AssertionError – If the number of elements in
pathandto_coordinate_systemare not the same.AssertionError – If elements in
to_coordinate_systemare not unique.ValueError – If both
do_3Dandz_projectionare set toTrue.ValueError – If
tableisTrue, andrasterize_cell_boundariesormosaic_imagesis notTrue.ValueError – If
tableisTrueandcell_boundariesisFalse.
- Return type:
- Returns:
: A SpatialData object.
See also
harpy.io.read_transcriptsread transcripts.
harpy.im.rasterizerasterize cell boundaries.