sopa.segmentation.aggregate
sopa.segmentation.aggregation.overlay_segmentation(sdata, shapes_key, gene_column=None, area_ratio_threshold=0.25, image_key=None, save_table=False)
Overlay a segmentation on top of an existing segmentation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sdata |
SpatialData
|
A |
required |
shapes_key |
str
|
The key of the new shapes to be added |
required |
gene_column |
str | None
|
Key of the points dataframe containing the genes names |
None
|
area_ratio_threshold |
float
|
Threshold between 0 and 1. For each original cell overlapping with a new cell, we compute the overlap-area/cell-area, if above the threshold the cell is removed. |
0.25
|
image_key |
str | None
|
Optional key of the original image |
None
|
save_table |
bool
|
Whether to save the new table on-disk or not |
False
|
Source code in sopa/segmentation/aggregation.py
sopa.segmentation.aggregation.average_channels(sdata, image_key=None, shapes_key=None, expand_radius_ratio=0)
Average channel intensities per cell.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sdata |
SpatialData
|
A |
required |
image_key |
str
|
Key of |
None
|
shapes_key |
str
|
Key of |
None
|
expand_radius_ratio |
float
|
Cells polygons will be expanded by |
0
|
Returns:
Type | Description |
---|---|
ndarray
|
A numpy |
Source code in sopa/segmentation/aggregation.py
sopa.segmentation.aggregation._average_channels_aligned(image, geo_df)
Average channel intensities per cell. The image and cells have to be aligned, i.e. be on the same coordinate system.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
DataArray
|
A |
required |
geo_df |
GeoDataFrame | list[Polygon]
|
A |
required |
Returns:
Type | Description |
---|---|
ndarray
|
A numpy |
Source code in sopa/segmentation/aggregation.py
sopa.segmentation.aggregation.count_transcripts(sdata, gene_column, shapes_key=None, points_key=None, geo_df=None)
Counts transcripts per cell.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sdata |
SpatialData
|
A |
required |
gene_column |
str
|
Column of the transcript dataframe containing the gene names |
required |
shapes_key |
str
|
Key of |
None
|
points_key |
str
|
Key of |
None
|
geo_df |
GeoDataFrame | None
|
If the cell boundaries are not yet in |
None
|
Returns:
Type | Description |
---|---|
AnnData
|
An |
Source code in sopa/segmentation/aggregation.py
sopa.segmentation.aggregation._count_transcripts_aligned(geo_df, points, value_key)
Count transcripts per cell. The cells and points have to be aligned (i.e., in the same coordinate system)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geo_df |
GeoDataFrame
|
Cells geometries |
required |
points |
DataFrame
|
Transcripts dataframe |
required |
value_key |
str
|
Key of |
required |
Returns:
Type | Description |
---|---|
AnnData
|
An |
Source code in sopa/segmentation/aggregation.py
sopa.segmentation.aggregation.Aggregator
Perform transcript count and channel averaging over a SpatialData
object
Source code in sopa/segmentation/aggregation.py
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 |
|
__init__(sdata, overwrite=True, image_key=None, shapes_key=None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sdata |
SpatialData
|
A |
required |
overwrite |
bool
|
If |
True
|
image_key |
str | None
|
Key of |
None
|
shapes_key |
str | None
|
Key of |
None
|
Source code in sopa/segmentation/aggregation.py
compute_table(gene_column=None, average_intensities=True, expand_radius_ratio=0, min_transcripts=0, min_intensity_ratio=0, save_table=True)
Perform aggregation and update the spatialdata table
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gene_column |
str | None
|
Column key of the transcript dataframe containing the gene names |
None
|
average_intensities |
bool
|
Whether to average the channels intensities inside cells polygons |
True
|
expand_radius_ratio |
float
|
Cells polygons will be expanded by |
0
|
min_transcripts |
int
|
Minimum amount of transcript to keep a cell |
0
|
min_intensity_ratio |
float
|
Cells whose mean channel intensity is less than |
0
|
save_table |
bool
|
Whether the table should be saved on disk or not |
True
|