Readers
The readers below are used to read your raw spatial data into a SpatialData
object. Choose the right function below, according to your technology of interest.
Warning
Due to many updates in the data format provided by the different companies, you might have issues loading your data. In this case, consider opening an issue detailing the version of the machine you used and the error log, as well as an example of file names that you are trying to read.
sopa.io.xenium(path, image_models_kwargs=None, imread_kwargs=None, cells_boundaries=False, cells_table=False, **kwargs)
Read Xenium data as a SpatialData
object. For more information, refer to spatialdata-io.
This function reads the following files
transcripts.parquet
: transcripts locations and namesexperiment.xenium
: metadata filemorphology_focus.ome.tif
: morphology image (or a directory, for recent versions of the Xenium)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str | Path
|
Path to the Xenium directory containing all the experiment files |
required |
image_models_kwargs
|
dict | None
|
Keyword arguments passed to |
None
|
imread_kwargs
|
dict | None
|
Keyword arguments passed to |
None
|
Returns:
Type | Description |
---|---|
SpatialData
|
A |
Source code in sopa/io/reader/xenium.py
sopa.io.merscope(path, backend=None, z_layers=3, region_name=None, slide_name=None, image_models_kwargs=None, imread_kwargs=None, **kwargs)
Read MERSCOPE data as a SpatialData
object. For more information, refer to spatialdata-io.
This function reads the following files
detected_transcripts.csv
: transcripts locations and names- all the images under the
images
directory images/micron_to_mosaic_pixel_transform.csv
: affine transformation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str | Path
|
Path to the MERSCOPE directory containing all the experiment files |
required |
backend
|
Literal['dask_image', 'rioxarray'] | None
|
Either |
None
|
z_layers
|
int | list[int] | None
|
Indices of the z-layers to consider. Either one |
3
|
region_name
|
str | None
|
Name of the region of interest, e.g., |
None
|
slide_name
|
str | None
|
Name of the slide/run. If |
None
|
image_models_kwargs
|
dict | None
|
Keyword arguments passed to |
None
|
imread_kwargs
|
dict | None
|
Keyword arguments passed to |
None
|
Returns:
Type | Description |
---|---|
SpatialData
|
A |
Source code in sopa/io/reader/merscope.py
sopa.io.cosmx(path, dataset_id=None, fov=None, read_proteins=False, image_models_kwargs=None, imread_kwargs=None)
Read Cosmx Nanostring data. The fields of view are stitched together, except if fov
is provided.
This function reads the following files
*_fov_positions_file.csv
or*_fov_positions_file.csv.gz
: FOV locationsMorphology2D
directory: all the FOVs morphology imagesMorphology_ChannelID_Dictionary.txt
: Morphology channels names*_tx_file.csv.gz
or*_tx_file.csv
: Transcripts location and names- If
read_proteins
isTrue
, all the images under the nestedProteinImages
directories will be read
These files must be exported as flat files in AtomX. That is: within a study, click on "Export" and then select files from the "Flat CSV Files" section (transcripts flat and FOV position flat).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str | Path
|
Path to the root directory containing Nanostring files. |
required |
dataset_id
|
Optional[str]
|
Optional name of the dataset (needs to be provided if not infered). |
None
|
fov
|
int | str | None
|
Name or number of one single field of view to be read. If a string is provided, an example of correct syntax is "F008". By default, reads all FOVs. |
None
|
read_proteins
|
bool
|
Whether to read the proteins or the transcripts. |
False
|
image_models_kwargs
|
dict | None
|
Keyword arguments passed to |
None
|
imread_kwargs
|
dict | None
|
Keyword arguments passed to |
None
|
Returns:
Type | Description |
---|---|
SpatialData
|
A |
Source code in sopa/io/reader/cosmx.py
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 |
|
sopa.io.macsima(path, **kwargs)
Read MACSIMA data as a SpatialData
object
Notes
For all dulicated name, their index will be added in brackets after, for instance you may find DAPI (1)
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
Path to the directory containing the MACSIMA |
required |
kwargs
|
int
|
Kwargs for the |
{}
|
Returns:
Type | Description |
---|---|
SpatialData
|
A |
Source code in sopa/io/reader/macsima.py
sopa.io.phenocycler(path, channels_renaming=None, image_models_kwargs=None)
Read Phenocycler data as a SpatialData
object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str | Path
|
Path to a |
required |
channels_renaming
|
dict | None
|
A dictionnary whose keys correspond to channels and values to their corresponding new name. Not all channels need to be renamed. |
None
|
image_models_kwargs
|
dict | None
|
Keyword arguments passed to |
None
|
Returns:
Type | Description |
---|---|
SpatialData
|
A |
Source code in sopa/io/reader/phenocycler.py
sopa.io.hyperion(path, image_models_kwargs=None, imread_kwargs=None)
Read Hyperion data as a SpatialData
object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
Path to the directory containing the Hyperion |
required |
image_models_kwargs
|
dict | None
|
Keyword arguments passed to |
None
|
imread_kwargs
|
dict | None
|
Keyword arguments passed to |
None
|
Returns:
Type | Description |
---|---|
SpatialData
|
A |
Source code in sopa/io/reader/hyperion.py
sopa.io.aicsimageio(path, z_stack=0, image_models_kwargs=None, aics_kwargs=None)
Read an image using AICSImageIO. It supports special formats such as ND2
, CZI
, LIF
, or DV
.
Extra dependencies
To use this reader, you'll need the aicsimageio
dependency (pip install aicsimageio
). To read .czi
images, you'll also need to install aicspylibczi
(for instance pip install aicspylibczi
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
Path to the image file |
required |
z_stack
|
int
|
(Only for 3D images) Index of the stack in the z-axis to use. |
0
|
image_models_kwargs
|
dict | None
|
Keyword arguments passed to |
None
|
aics_kwargs
|
dict | None
|
Keyword arguments passed to |
None
|
Returns:
Type | Description |
---|---|
SpatialData
|
A |
Source code in sopa/io/reader/aics.py
sopa.io.ome_tif(path, as_image=False)
Read an .ome.tif
image. This image should be a 2D image (with possibly multiple channels).
Typically, this function can be used to open Xenium IF images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
Path to the |
required |
as_image
|
bool
|
If |
False
|
Returns:
Type | Description |
---|---|
DataArray | SpatialData
|
A |
Source code in sopa/io/reader/utils.py
sopa.io.wsi(path, chunks=(3, 256, 256), as_image=False, backend='tiffslide')
Read a WSI into a SpatialData
object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str | Path
|
Path to the WSI |
required |
chunks
|
tuple[int, int, int]
|
Tuple representing the chunksize for the dimensions |
(3, 256, 256)
|
as_image
|
bool
|
If |
False
|
backend
|
str
|
The library to use as a backend in order to load the WSI. One of: |
'tiffslide'
|
Returns:
Type | Description |
---|---|
SpatialData | DataTree
|
A |
Source code in sopa/io/reader/wsi.py
sopa.io.toy_dataset(*_, length=2048, cell_density=0.0001, n_points_per_cell=100, c_coords=['DAPI', 'CK', 'CD3', 'CD20'], genes=['EPCAM', 'CD3E', 'CD20', 'CXCL4', 'CXCL10'], sigma_factor=0.05, pixel_size=0.1, seed=0, include_vertices=False, include_image=True, include_he_image=True, apply_blur=True, as_output=False, transcript_cell_id_as_merscope=False, add_nan_gene_name=False)
Generate a dummy dataset composed of cells generated uniformly in a square. It also has transcripts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
length
|
int
|
Size of the square, in pixels |
2048
|
cell_density
|
float
|
Density of cells per pixel^2 |
0.0001
|
n_points_per_cell
|
int
|
Mean number of transcripts per cell |
100
|
c_coords
|
list[str]
|
Channel names |
['DAPI', 'CK', 'CD3', 'CD20']
|
genes
|
int | list[str]
|
Number of different genes, or list of gene names |
['EPCAM', 'CD3E', 'CD20', 'CXCL4', 'CXCL10']
|
sigma_factor
|
float
|
Factor used to determine |
0.05
|
pixel_size
|
float
|
Number of microns in one pixel. |
0.1
|
seed
|
int
|
Numpy random seed |
0
|
include_vertices
|
bool
|
Whether to include the vertices of the cells (as points) in the spatialdata object |
False
|
include_image
|
bool
|
Whether to include the image in the spatialdata object |
True
|
apply_blur
|
bool
|
Whether to apply gaussian blur on the image (without blur, cells are just one pixel) |
True
|
as_output
|
bool
|
If |
False
|
Returns:
Type | Description |
---|---|
SpatialData
|
A SpatialData object with a 2D image ( |
Source code in sopa/utils/data.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 |
|