API Reference
SubDomain
Analyse domains based on labels in a 2D grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label_map
|
ndarray | Array
|
An integer array where all positive values correspond to a specific cell type and negative values are background. |
required |
label_name
|
str
|
Name of the labels. |
'celltype'
|
labels
|
Iterable[str] | None
|
Names corresponding to each label in |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the length of |
Attributes:
| Name | Type | Description |
|---|---|---|
SubDomain.label_map |
ndarray | Array
|
2D labeled grid. |
SubDomain.n_labels |
int
|
Number of different categories in |
SubDomain.label_name |
str
|
Name of the labels. |
SubDomain.labels |
str
|
Names corresponding to each label in |
SubDomain.neighborhoods |
Array
|
The consolidated neighborhoods after binning. |
SubDomain.binsize |
int
|
Size of each domain bin. |
SubDomain.domains |
ndarray
|
The assigned domain for each bin. |
SubDomain.n_domains |
int
|
Number of domains. |
Source code in subdomain/_domaindetection.py
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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
calculate_neighborhoods(binsize, radius, *, normalize=True)
Calculate the neighborhoods.
The label map is binned and subsequently the neighborhood in terms of frequency per label calculated for each bin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binsize
|
int
|
Size to bin the labeled grid by. |
required |
radius
|
int
|
Radius for the neighborhood aggregation. The size of the neighborhood will be
|
required |
normalize
|
bool
|
Whether to normalize the neighborhood of each bin (L1-norm). |
True
|
Source code in subdomain/_domaindetection.py
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 | |
cluster_neighborhoods(n_clusters, *, gpu=False, random_state=1, **kwargs)
Cluster the aggregated neighborhoods.
Assigns a domain (cluster) to each bin in the calculated neighborhoods (requires to first run subdomain.SubDomain.calculate_neighborhoods).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_clusters
|
int
|
Number of clusters. |
required |
gpu
|
bool
|
Whether to use the GPU for KMeans clustering. |
False
|
random_state
|
int
|
Random state for reproducibility. |
1
|
kwargs
|
Other keyword arguments will be passed to sklearn.cluster.KMeans or cuml.cluster.KMeans. |
{}
|
Source code in subdomain/_domaindetection.py
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 | |
domain_composition()
Label composition of each domain.
Returns:
| Type | Description |
|---|---|
DataFrame
|
Label composition. |
Source code in subdomain/_domaindetection.py
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 281 282 283 | |
domain_neighborhoods()
Average neighborhood of the domains.
Returns:
| Type | Description |
|---|---|
DataFrame
|
Average neighborhood. |
Source code in subdomain/_domaindetection.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
identify_domains(binsize=8, radius=10, n_clusters=10, *, gpu=False, random_state=1, **kwargs)
Identify domains from labeled grid.
This is a wrapper around subdomain.SubDomain.calculate_neighborhoods and subdomain.SubDomain.cluster_neighborhoods.
If the neighborhood has already been calculated (and the parameters do not need to be changed) it is more efficient to just cluster the domains rather than recalculating the neighborhoods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binsize
|
int
|
Size to bin the labeled grid by. |
8
|
radius
|
int
|
Radius for the neighborhood aggregation. The size of the neighborhood will be
|
10
|
n_clusters
|
int
|
Number of clusters for k-means. |
10
|
gpu
|
bool
|
Whether to use the GPU for KMeans clustering. The neighborhood aggregation will run by default on GPU if available. |
False
|
random_state
|
int
|
Random state for reproducibility. |
1
|
kwargs
|
Other keyword arguments will be passed to sklearn.cluster.KMeans or cuml.cluster.KMeans. |
{}
|
Source code in subdomain/_domaindetection.py
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 | |
plot_domains(domain_palette=cc.glasbey_dark, label_palette=cc.glasbey_light, *, scale=None, **kwargs)
Spatial plot of domains and labeled grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain_palette
|
Palette to use for the domain plot. Must be a valid argument for seaborn.color_palette] |
glasbey_dark
|
|
label_palette
|
Palette to use for the labeled grid plot. Must be a valid argument for seaborn.color_palette] |
glasbey_light
|
|
scale
|
tuple[float, str] | None
|
Size of a pixel in the original labeled grid as a tuple of the value and
the unit (must be one of nm, um, ...) e.g. |
None
|
kwargs
|
Other keyword arguments are passed to |
{}
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Source code in subdomain/_domaindetection.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
plot_neighborhood_heatmap(*, palette=cc.glasbey_dark, **kwargs)
Heatmap of the label enrichment of the domains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
palette
|
str
|
A valid argument for seaborn.color_palette |
glasbey_dark
|
kwargs
|
Other keyword arguments are passed to seaborn.clustermap |
{}
|
Returns:
| Type | Description |
|---|---|
ClusterGrid
|
Heatmap returned from seaborn.clustermap |
Source code in subdomain/_domaindetection.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
rescale_domain_map()
Rescale domain map to original labeled grid size i.e. prior to binning.
Source code in subdomain/_domaindetection.py
285 286 287 288 289 290 | |