sopa.segmentation.patching
sopa.segmentation.Patches2D
Compute 2D-patches with overlaps. This can be done on an image or a DataFrame.
Attributes:
Name | Type | Description |
---|---|---|
polygons |
list[Polygon]
|
List of |
bboxes |
ndarray
|
Array of shape |
ilocs |
ndarray
|
Array of shape |
Source code in sopa/patches/patches.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
__init__(sdata, element_name, patch_width, patch_overlap=50)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sdata |
SpatialData
|
A |
required |
element_name |
str
|
Name of the element on with patches will be made (image or points) |
required |
patch_width |
float | int
|
Width of the patches (in the unit of the coordinate system of the element) |
required |
patch_overlap |
float | int
|
Overlap width between the patches |
50
|
Source code in sopa/patches/patches.py
__len__()
patchify_transcripts(temp_dir, cell_key=None, unassigned_value=None, use_prior=False, config={}, config_path=None, config_name=SopaFiles.TOML_CONFIG_FILE, csv_name=SopaFiles.TRANSCRIPTS_FILE, min_transcripts_per_patch=4000, shapes_key=SopaKeys.CELLPOSE_BOUNDARIES)
Creation of patches for the transcripts.
Prior segmentation usage
To save assign a prior segmentation to each transcript, you can either use cell_key
or use_prior
:
- If a segmentation has already been performed (for example an existing 10X-Genomics segmentation), use
cell_key
to denote the column of the transcript dataframe containing the cell IDs (and optionalyunassigned_value
). - If you have already run Cellpose with Sopa, use
use_prior
(no need to providecell_key
andunassigned_value
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
temp_dir |
str
|
Temporary directory where each patch will be stored. Note that each patch will have its own subdirectory. |
required |
cell_key |
str
|
Optional key of the transcript dataframe containing the cell IDs. This is useful if a prior segmentation has been run, assigning each transcript to a cell. |
None
|
unassigned_value |
int | str
|
If |
None
|
use_prior |
bool
|
Whether to use Cellpose as a prior segmentation. If |
False
|
config |
dict
|
Dictionnary of segmentation parameters |
{}
|
config_path |
str | None
|
Path to the segmentation config file (you can also directly provide the argument via the |
None
|
config_name |
str
|
Name of the config file to be saved in each patch subdirectory |
TOML_CONFIG_FILE
|
csv_name |
str
|
Name of the CSV file to be saved in each patch subdirectory |
TRANSCRIPTS_FILE
|
min_transcripts_per_patch |
int
|
Minimum number of transcripts for a patch to be considered for segmentation |
4000
|
Returns:
Type | Description |
---|---|
list[int]
|
A list of patches indices. Each index correspond to the name of a subdirectory inside |
Source code in sopa/patches/patches.py
write(overwrite=True, shapes_key=None)
Save patches in sdata.shapes["sopa_patches"]
(or by the key specified)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
overwrite |
bool
|
Whether to overwrite patches if existing |
True
|
shapes_key |
str | None
|
Optional name of the shapes to be saved. By default, uses "sopa_patches". |
None
|
Returns:
Type | Description |
---|---|
GeoDataFrame
|
The saved GeoDataFrame |