Api
spatialdata_xenium_explorer.write(path, sdata, image_key=None, shapes_key=None, points_key=None, gene_column=None, pixel_size=0.2125, spot=False, layer=None, polygon_max_vertices=13, lazy=True, ram_threshold_gb=4, mode=None)
Transform a SpatialData object into inputs for the Xenium Explorer.
After running this function, double-click on the experiment.xenium
file to open it.
Software download
Make sure you have the latest version of the Xenium Explorer
Note
This function will create up to 6 files, depending on the SpatialData
object and the arguments:
-
experiment.xenium
contains some experiment metadata. Double-click on this file to open the Xenium Explorer. This file can also be created withwrite_metadata
. -
morphology.ome.tif
is the primary image. This file can also be created withwrite_image
. Add more images withalign
. -
analysis.zarr.zip
contains the cells categories (or clusters), i.e.adata.obs
. This file can also be created withwrite_cell_categories
. -
cell_feature_matrix.zarr.zip
contains the cell-by-gene counts. This file can also be created withwrite_gene_counts
. -
cells.zarr.zip
contains the cells polygon boundaries. This file can also be created withwrite_polygons
. -
transcripts.zarr.zip
contains transcripts locations. This file can also be created withwrite_transcripts
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
Path to the directory where files will be saved. |
required |
sdata |
SpatialData
|
A |
required |
image_key |
str | None
|
Name of the image of interest (key of |
None
|
shapes_key |
str | None
|
Name of the cell shapes (key of |
None
|
points_key |
str | None
|
Name of the transcripts (key of |
None
|
gene_column |
str | None
|
Column name of the points dataframe containing the gene names. |
None
|
pixel_size |
float
|
Number of microns in a pixel. Invalid value can lead to inconsistent scales in the Explorer. |
0.2125
|
spot |
bool
|
Whether the technology is based on spots |
False
|
layer |
str | None
|
Layer of |
None
|
polygon_max_vertices |
int
|
Maximum number of vertices for the cell polygons. A higher value will display smoother cells. |
13
|
lazy |
bool
|
If |
True
|
ram_threshold_gb |
int | None
|
Threshold (in gygabytes) from which image can be loaded in memory. If |
4
|
mode |
str
|
string that indicated which files should be created. "-ib" means everything except images and boundaries, while "+tocm" means only transcripts/observations/counts/metadata (each letter corresponds to one explorer file). By default, keeps everything. |
None
|
Source code in spatialdata_xenium_explorer/converter.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
spatialdata_xenium_explorer.write_image(path, image, lazy=True, tile_width=1024, n_subscales=5, pixel_size=0.2125, ram_threshold_gb=4, is_dir=True)
Convert an image into a morphology.ome.tif
file that can be read by the Xenium Explorer
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
Path to the Xenium Explorer directory where the image will be written |
required |
image |
SpatialImage | ndarray
|
Image of shape |
required |
lazy |
bool
|
If |
True
|
tile_width |
int
|
Xenium tile width (do not update). |
1024
|
n_subscales |
int
|
Number of sub-scales in the pyramidal image. |
5
|
pixel_size |
float
|
Xenium pixel size (do not update). |
0.2125
|
ram_threshold_gb |
int | None
|
If an image (of any level of the pyramid) is below this threshold, it will be loaded in-memory. |
4
|
is_dir |
bool
|
If |
True
|
Source code in spatialdata_xenium_explorer/core/images.py
spatialdata_xenium_explorer.write_cell_categories(path, adata, is_dir=True)
Write a analysis.zarr.zip
file containing the cell categories/clusters (i.e., from adata.obs
)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
Path to the Xenium Explorer directory where the cell-categories file will be written |
required |
adata |
AnnData
|
An |
required |
is_dir |
bool
|
If |
True
|
Source code in spatialdata_xenium_explorer/core/table.py
spatialdata_xenium_explorer.write_transcripts(path, df, gene='gene', max_levels=15, is_dir=True, pixel_size=0.2125)
Write a transcripts.zarr.zip
file containing pyramidal transcript locations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
Path to the Xenium Explorer directory where the transcript file will be written |
required |
df |
DataFrame
|
DataFrame representing the transcripts, with |
required |
gene |
str
|
Column of |
'gene'
|
max_levels |
int
|
Maximum number of levels in the pyramid. |
15
|
is_dir |
bool
|
If |
True
|
pixel_size |
float
|
Number of microns in a pixel. Invalid value can lead to inconsistent scales in the Explorer. |
0.2125
|
Source code in spatialdata_xenium_explorer/core/points.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
spatialdata_xenium_explorer.write_gene_counts(path, adata, layer=None, is_dir=True)
Write a cell_feature_matrix.zarr.zip
file containing the cell-by-gene transcript counts (i.e., from adata.X
)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
Path to the Xenium Explorer directory where the cell-by-gene file will be written |
required |
adata |
AnnData
|
An |
required |
layer |
str | None
|
If not |
None
|
is_dir |
bool
|
If |
True
|
Source code in spatialdata_xenium_explorer/core/table.py
spatialdata_xenium_explorer.write_polygons(path, polygons, max_vertices, is_dir=True, pixel_size=0.2125)
Write a cells.zarr.zip
file containing the cell polygonal boundaries
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
Path to the Xenium Explorer directory where the transcript file will be written |
required |
polygons |
Iterable[Polygon]
|
A list of |
required |
max_vertices |
int
|
The number of vertices per polygon (they will be transformed to have the right number of vertices) |
required |
is_dir |
bool
|
If |
True
|
pixel_size |
float
|
Number of microns in a pixel. Invalid value can lead to inconsistent scales in the Explorer. |
0.2125
|
Source code in spatialdata_xenium_explorer/core/shapes.py
spatialdata_xenium_explorer.write_metadata(path, image_key='NA', shapes_key='NA', n_obs=0, is_dir=True, pixel_size=0.2125)
Create an experiment.xenium
file that can be open by the Xenium Explorer.
Note
This function alone is not enough to actually open an experiment. You will need at least to wrun write_image
, or create all the outputs with write_explorer
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
Path to the Xenium Explorer directory where the metadata file will be written |
required |
image_key |
str
|
Key of |
'NA'
|
shapes_key |
str
|
Key of |
'NA'
|
n_obs |
int
|
Number of cells |
0
|
is_dir |
bool
|
If |
True
|
pixel_size |
float
|
Number of microns in a pixel. Invalid value can lead to inconsistent scales in the Explorer. |
0.2125
|
Source code in spatialdata_xenium_explorer/converter.py
spatialdata_xenium_explorer.int_cell_id(explorer_cell_id)
Transforms an alphabetical cell id from the Xenium Explorer to an integer ID
E.g., int_cell_id('aaaachba-1') = 10000
Source code in spatialdata_xenium_explorer/utils.py
spatialdata_xenium_explorer.str_cell_id(cell_id)
Transforms an integer cell ID into an Xenium Explorer alphabetical cell id
E.g., str_cell_id(10000) = 'aaaachba-1'
Source code in spatialdata_xenium_explorer/utils.py
spatialdata_xenium_explorer.align(sdata, image, transformation_matrix_path, image_key=None, image_models_kwargs=None, overwrite=False)
Add an image to the SpatialData
object after alignment with the Xenium Explorer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sdata |
SpatialData
|
A |
required |
image |
SpatialImage
|
A |
required |
transformation_matrix_path |
str
|
Path to the |
required |
image_key |
str
|
Optional name of the image on which it has been aligned. Required if multiple images in the |
None
|
image_models_kwargs |
dict | None
|
Kwargs to the |
None
|
overwrite |
bool
|
Whether to overwrite the image, if already existing. |
False
|
Source code in spatialdata_xenium_explorer/core/images.py
spatialdata_xenium_explorer.save_column_csv(path, adata, key)
Save one column of the AnnData object as a CSV that can be open interactively in the explorer, under the "cell" panel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
Path where to write the CSV that will be open in the Xenium Explorer |
required |
adata |
AnnData
|
An |
required |
key |
str
|
Key of |
required |