omicverse.io.read_xenium#
- omicverse.io.read_xenium(path, *, library_id=None, load_image=True, image_key='morphology_focus', image_max_dim=4096, load_boundaries=True, cache_file=None)[source]#
Read a 10x Xenium
outsdirectory into an AnnData object.Handles the standard flat layout shipped by Xenium Onboard Analysis:
outs/ cell_feature_matrix.h5 # gene × cell sparse matrix cells.csv.gz (or cells.parquet)# per-cell metadata incl. centroids experiment.xenium # run / panel metadata (JSON) morphology_focus.ome.tif # V1 focused morphology image (optional) morphology_focus/ # V2 / Prime morphology folder (optional) morphology_focus_0000.ome.tif # DAPI morphology_focus_0001.ome.tif # boundary stain morphology_focus_0002.ome.tif # interior stain morphology_focus_0003.ome.tif # 4th channel (Prime panels)- Parameters:
path (
Union[str,Path]) – The Xeniumoutsdirectory (or any directory containing the files above).library_id (
Optional[str] (default:None)) – Identifier used as the key underadata.uns['spatial']. Defaults toexperiment.xenium’sregion_name/run_nameif present, else the directory name.load_image (
bool(default:True)) – WhenTrueandtifffileis installed, loads the morphology image soomicverse.pl.spatial()can overlay it. The morphology TIFF is large (hundreds of MB); passFalsefor lightweight tutorials that only need the centroid scatter.image_key (
str(default:'morphology_focus')) –Which morphology image to load. Accepts:
'morphology_focus'/'morphology_mip'— V1 layout files at the outs root; falls back to the first V2 channel (_0000, DAPI) when V1 files are absent.'morphology_focus_NNNN'— pick a specific V2 / Prime channel (_0000DAPI,_0001boundary,_0002interior,_0003alternative) frommorphology_focus/. If the requested channel is missing, the reader falls back to the other available channels rather than returning no image.
image_max_dim (
int(default:4096)) – Xenium OME-TIFFs are multi-resolution pyramids; this is the maximum pixel extent along either axis that we will load. The highest-resolution pyramid level fitting under this cap is used. Default 4096 keeps the in-memory array small while remaining usable for overlay. Pass a larger value (e.g. 8192) for closer crops.load_boundaries (
bool(default:True)) – WhenTrueandcell_boundaries.parquet/.csv.gzis present, converts per-cell polygon vertices to WKT strings stored inobs['geometry']— required byomicverse.pl.spatialseg().cache_file (
Union[str,Path,None] (default:None)) – Optional path to an.h5adcache. When set and the file exists, we read it back instead of re-parsing the outs directory (skipping the 10x HDF5 matrix, CSV metadata, and polygon-to-WKT construction). When set and the file does not exist, it is written after the load completes so subsequent calls are fast. PassNoneto skip caching.
- Returns:
X: CSR sparse,int32counts (cells × genes)obs: cell metadata fromcells.csv.gzobsm['spatial']:(n_obs, 2)cell centroids in micronsvar: gene panel metadatauns['spatial'][library_id]:'images'['hires']: morphology image (if loaded)'scalefactors'['tissue_hires_scalef']:1 / pixel_size— mapping micron coords to image pixels'scalefactors'['spot_diameter_fullres']: mean cell diameter in fullres (image) pixels, for default spot sizing'metadata': contents ofexperiment.xenium
- Return type:
AnnData