Luna Pathology¶
analysis
¶
Created on April 27, 2021
@author: pashaa@mskcc.org
ml
¶
BaseTorchClassifier
¶
Bases: Module
Source code in src/luna/pathology/analysis/ml.py
__init__(**kwargs)
¶
Initialize BaseTorchClassifier
A generic base class for a PyTorch classifier model. This serves as the base class inhereted for model training and inference.
Will run on cuda if available, on the device specified by the CUDA_VISIBLE_DEVICES environment variable
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs |
Keyward arguements passed onto the subclass method |
{}
|
Source code in src/luna/pathology/analysis/ml.py
setup(**kwargs)
¶
Set classifier modules
Template/abstract method where individual modules that make up the forward pass are configured
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs |
Keyword arguements passed onto the subclass method |
{}
|
Source code in src/luna/pathology/analysis/ml.py
BaseTorchTileClassifier
¶
Bases: BaseTorchClassifier
Source code in src/luna/pathology/analysis/ml.py
forward(index, tile_data)
¶
Forward pass for base classifier class
Loads a tile image from the tile manifest
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
list[str]
|
Tile address indicies with length B |
required |
tile_data |
tensor
|
Input tiles of shape (B, *) |
required |
Returns:
Type | Description |
---|---|
pd.DataFrame: Dataframe of output features |
Source code in src/luna/pathology/analysis/ml.py
predict(input_tiles)
¶
predict method
Loads a tile image from the tile manifest, must be manually implimented to pass the input tensor through the modules specified in setup()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_tiles |
tensor
|
Input tiles of shape (B, *) |
required |
Returns:
Type | Description |
---|---|
torch.tensor: 2D tensor with (B, C) where B is the batch dimension and C are output classes or features |
Source code in src/luna/pathology/analysis/ml.py
setup(**kwargs)
¶
Set classifier modules
Template/abstract method where individual modules that make up the forward pass are configured
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs |
Keyword arguements passed onto the subclass method |
{}
|
Source code in src/luna/pathology/analysis/ml.py
BaseTorchTileDataset
¶
Bases: Dataset
Base class for a tile dataset
Impliments the usual torch dataset methods, and additionally provides a decoding of the binary tile data. PIL images can be further preprocessed before becoming torch tensors via an abstract preprocess method
Will send the tensors to gpu if available, on the device specified by CUDA_VISIBLE_DEVICES="1"
Source code in src/luna/pathology/analysis/ml.py
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 |
|
__getitem__(idx)
¶
Tile accessor
Loads a tile image from the tile manifest. Returns a batch of the indices of the input dataframe, the tile data always. If label columns where specified, the 3rd position of the tuple is a tensor of the label data. If Ray is being used for model training, then only the image data and the label is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx |
int
|
Integer index |
required |
Returns:
Type | Description |
---|---|
optional str, torch.tensor, optional torch.tensor
|
tuple of the tile index and corresponding tile as a torch tensor, and metadata labels if specified |
Source code in src/luna/pathology/analysis/ml.py
__init__(tile_manifest=None, tile_urlpath='', label_cols=[], using_ray=False, storage_options={}, **kwargs)
¶
Initialize BaseTileDataset
Can accept either a tile dataframe or a path to tile data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tile_manifest |
DataFrame
|
Dataframe of tile data |
None
|
tile_path |
str
|
Base path of tile data |
required |
label_cols |
list[str]
|
(Optional) label columns to return as tensors, e.g. for training |
[]
|
using_ray |
bool
|
(Optional) Perform distributed dataloading with Ray for training |
False
|
Source code in src/luna/pathology/analysis/ml.py
preprocess(input_tile)
¶
Preprocessing method called for each tile patch
Loads a tile image from the tile manifest, must be manually implimented to accept a single PIL image and return a torch tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_tile |
Image
|
Integer index |
required |
Returns:
Type | Description |
---|---|
torch.tensor: Output tile as preprocessed tensor |
Source code in src/luna/pathology/analysis/ml.py
setup(**kwargs)
¶
Set additional attributes for dataset class
Template/abstract method where a dataset is configured
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs |
Keyword arguements passed onto the subclass method |
{}
|
Source code in src/luna/pathology/analysis/ml.py
HDF5Dataset
¶
Bases: Dataset
General dataset that uses a HDF5 manifest convention
Applies preprocessing steps per instance, returning aggregate batches of data. Useful for training and inference.
Source code in src/luna/pathology/analysis/ml.py
__getitem__(idx)
¶
Tile accessor
Loads a tile image from the tile manifest. Returns a batch of the indices of the input dataframe, the tile data always. If label columns where specified, the 3rd position of the tuple is a tensor of the label data. If Ray is being used for model training, then only the image data and the label is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx |
int
|
Integer index |
required |
Returns:
Type | Description |
---|---|
optional str, torch.tensor, optional torch.tensor
|
tuple of the tile index and corresponding tile as a torch tensor, and metadata labels if specified, else the index |
Source code in src/luna/pathology/analysis/ml.py
__init__(hdf5_manifest, preprocess=nn.Identity(), label_cols=[], using_ray=False, storage_options={})
¶
Initialize HD5FDataset
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hdf5_manifest |
DataFrame
|
Dataframe of H5 data |
required |
preprocess |
transform
|
Function to apply to every bit of data |
Identity()
|
label_cols |
list[str]
|
(Optional) label columns to return as tensors, e.g. for training |
[]
|
using_ray |
bool
|
(Optional) Perform distributed dataloading with Ray for training |
False
|
Source code in src/luna/pathology/analysis/ml.py
TorchTransformModel
¶
Source code in src/luna/pathology/analysis/ml.py
get_preprocess(**kwargs)
¶
The transform model's preprocessing code
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs |
Keyword arguements passed onto the subclass method |
{}
|
Source code in src/luna/pathology/analysis/ml.py
transform(X)
¶
Main transformer method, X -> X'
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
Tensor
|
input tensor |
required |
Returns:
Type | Description |
---|---|
torch.tensor: Output tile as preprocessed tensor |
Source code in src/luna/pathology/analysis/ml.py
get_group_stratified_sampler(df_nh, label_col, group_col, num_splits=5, random_seed=42)
¶
Generates sampler indices for torch DataLoader object that are stratified by a given group set (ie a column in a dataframe corresponding to patient identifiers), and balanced between target labels
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df_nh |
DataFrame
|
A non-hierarchical/non-multi-indexed/flat dataframe |
required |
label_col |
str
|
The column name for the classes to balance across training and validation splits. |
required |
group_col |
str
|
The column name used to stratify the data (ie patient ids). |
required |
num_splits |
int
|
(Optional) The number of folds, must at least be 2. |
5
|
Returns: Tuple(List, List): a tuple of indices that correspond to training and validation samplers
Source code in src/luna/pathology/analysis/ml.py
post_transform_to_2d(input)
¶
Convert input to a 2D numpy array on CPU
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
tensor
|
tensor input of shape [B, *] where B is the batch dimension |
required |
Source code in src/luna/pathology/analysis/ml.py
cli
¶
Created on April 27, 2021
@author: pashaa@mskcc.org
create_wide_shape_features_query
¶
cli(shape_features_urlpath, storage_options={})
¶
Prints wide shape features query for Dremio
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shape_features_urlpaths |
List[str]
|
URL/path to shape features parquet files |
required |
storage_options |
dict
|
storage options to pass to reading functions |
{}
|
Source code in src/luna/pathology/cli/create_wide_shape_features_query.py
create_wide_shape_features_query(shape_features_urlpath, storage_options={})
¶
Gets wide shape features query for dremio
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shape_features_urlpaths |
List[str]
|
URL/path to shape feature parquet files |
required |
storage_options |
dict
|
storage options to pass to reading functions |
{}
|
Source code in src/luna/pathology/cli/create_wide_shape_features_query.py
dsa_annotation_etl
¶
DsaAnnotationProcessor
¶
Source code in src/luna/pathology/cli/dsa_annotation_etl.py
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 |
|
build_proxy_repr_dsa(row)
¶
Build a proxy table slice given, primarily, a DSA itemId (slide_item_uuid)
Source code in src/luna/pathology/cli/dsa_annotation_etl.py
histomics_annotation_table_to_geojson(df, properties, shape_type_col='type', x_col='x_coords', y_col='y_coords')
¶
Takes a table generated by histomicstk (parse_slide_annotations_into_tables) and creates a geojson
Source code in src/luna/pathology/cli/dsa_annotation_etl.py
run(row)
¶
Run DsaAnnotationProcessor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row |
string
|
row of a DSA slide table |
required |
Returns:
Type | Description |
---|---|
pd.DataFrame: annotation metadata |
cli(dsa_endpoint='???', collection_name='???', annotation_name='???', username='${oc.env:DSA_USERNAME}', password='${oc.env:DSA_PASSWORD}', local_config='', output_urlpath='.', storage_options={})
¶
DSA annotation ETL Args: dsa_endpoint (str): path to input data collection_name (str): collection name in DSA annotation_name (str): annotation name username (str): DSA username (defaults to environment variable DSA_USERNAME) password (str): DSA password (defaults to environment variable DSA_PASSWORD) local_config (str): local config yaml url/path output_urlpath (str): output/working url/path prefix storage_options (dict): options to pass to reading/writing functions
Returns:
Type | Description |
---|---|
pd.DataFrame: metadata from function call |
Source code in src/luna/pathology/cli/dsa_annotation_etl.py
dsa_annotation_etl(dsa_endpoint, collection_name, annotation_name, username, password, output_urlpath, storage_options)
¶
DSA annotation ETL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dsa_endpoint |
str
|
path to input data |
required |
collection_name |
str
|
collection name in DSA |
required |
annotation_name |
str
|
annotation name |
required |
username |
str
|
DSA username |
required |
password |
str
|
DSA password |
required |
output_urlpath |
str
|
output/working url/path prefix |
required |
storage_options |
dict
|
options to pass to reading/writing functions |
required |
Returns:
Type | Description |
---|---|
pd.DataFrame: slide etl dataframe with annotation columns |
Source code in src/luna/pathology/cli/dsa_annotation_etl.py
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 |
|
dsa_upload
¶
__upload_annotation_to_dsa(gc, dsa_endpoint_url, annotation_file_urlpath, collection_name, image_filename, force=False, storage_options={})
¶
Upload annotation to DSA
Upload json annotation file as a new annotation to the image in the DSA collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dsa_endpoint_url |
string
|
DSA API endpoint e.g. http://localhost:8080/api/v1 |
required |
annotation_file_urlpath |
string
|
URL/path to a DSA annotation json file |
required |
collection_name |
string
|
name of the collection in DSA |
required |
image_filename |
string
|
name of the image file in DSA e.g. 123.svs |
required |
username |
string
|
DSA username |
required |
password |
string
|
DSA password |
required |
storage_options |
dict
|
options to pass to reading functions |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
item_uuid. None if item doesn't exist |
Source code in src/luna/pathology/cli/dsa_upload.py
cli(dsa_endpoint_url='???', annotation_file_urlpath='', annotation_file_list_urlpath='', collection_name='???', image_filename='', username='${oc.env:DSA_USERNAME}', password='${oc.env:DSA_PASSWORD}', force=False, insecure=False, storage_options={}, local_config='')
¶
Upload annotation to DSA
Upload json annotation file as a new annotation to the image in the DSA collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dsa_endpoint_url |
string
|
DSA API endpoint e.g. http://localhost:8080/api/v1 |
'???'
|
annotation_file_urlpath |
string
|
URL/path to a DSA annotation json file |
''
|
annotation_file_list_urlpath |
string
|
URL/path to a DSA annotation json file |
''
|
collection_name |
string
|
name of the collection in DSA |
'???'
|
image_filename |
string
|
name of the image file in DSA e.g. 123.svs. If not specified, infer from annotiaton_file_urpath |
''
|
username |
string
|
DSA username (defaults to environment variable DSA_USERNAME) |
'${oc.env:DSA_USERNAME}'
|
password |
string
|
DSA password (defaults to environment variable DSA_PASSWORD) |
'${oc.env:DSA_PASSWORD}'
|
force |
bool
|
upload even if annotation with same name exists for the slide |
False
|
insecure |
bool
|
insecure ssl |
False
|
storage_options |
dict
|
options to pass to reading functions |
{}
|
local_config |
string
|
local config yaml url/path |
''
|
Returns:
Name | Type | Description |
---|---|---|
dict |
metadata |
Source code in src/luna/pathology/cli/dsa_upload.py
upload_annotation_to_dsa(dsa_endpoint_url, slide_manifest, annotation_column, collection_name, image_filename, username, password, force=False, insecure=False, storage_options={})
¶
Upload annotation to DSA
Upload json annotation file as a new annotation to the image in the DSA collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dsa_endpoint_url |
string
|
DSA API endpoint e.g. http://localhost:8080/api/v1 |
required |
slide_manifest |
DataFrame[SlideSchema]
|
slide manifest from slide_etl |
required |
annotation_column |
string
|
annotation column of slide_manifest containing the dsa url |
required |
collection_name |
string
|
name of the collection in DSA |
required |
image_filename |
string
|
name of the image file in DSA e.g. 123.svs. If not specified, infer from annotiaton_file_urpath |
required |
username |
string
|
DSA username (defaults to environment variable DSA_USERNAME) |
required |
password |
string
|
DSA password (defaults to environment variable DSA_PASSWORD) |
required |
force |
bool
|
upload even if annotation with same name exists for the slide |
False
|
insecure |
bool
|
insecure ssl |
False
|
storage_options |
dict
|
options to pass to reading functions |
{}
|
Returns:
Type | Description |
---|---|
DataFrame[SlideSchema]: slide manifest |
Source code in src/luna/pathology/cli/dsa_upload.py
dsa_viz
¶
__bmp_polygon(input_urlpath, output_urlpath, image_filename, label_map, annotation_name, line_colors=None, fill_colors=None, scale_factor=1, storage_options={}, output_storage_options={})
¶
Build DSA annotation json from a BMP with multiple labels.
Vectorizes and simplifies contours per label.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_urlpath |
string
|
url/path to bmp file |
required |
label_map |
dict[int, str]
|
map of label number to label name |
required |
annotation_name |
string
|
name of the annotation to be displayed in DSA |
required |
line_colors |
dict[str, str]
|
line color map with {feature name:rgb values} |
None
|
fill_colors |
dict[str, str]
|
fill color map with {feature name:rgba values} |
None
|
scale_factor |
int
|
scale to match image DSA. |
1
|
storage_options |
dict
|
storage options to pass to read functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
DSA annotation |
Source code in src/luna/pathology/cli/dsa_viz.py
1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 |
|
__heatmap(input_urlpath, output_urlpath, image_filename, annotation_name, column, tile_size, scale_factor=None, fill_colors=None, line_colors=None, storage_options={}, output_storage_options={})
¶
Generate heatmap based on the tile scores
Creates a heatmap for the given column, using the color palette viridis
to set a fill value
- the color ranges from purple to yellow, for scores from 0 to 1.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_urlpath |
string
|
url/path to parquet with tile scores |
required |
annotation_name |
string
|
name of the annotation to be displayed in DSA |
required |
column |
list[string]
|
columns to visualize e.g. tile_score |
required |
tile_size |
int
|
size of tiles |
required |
scale_factor |
int
|
scale to match the image on DSA. |
None
|
fill_colors |
Optional[dict[str, str]]
|
fill color map with {feature name:rgba values} |
None
|
line_colors |
Optional[dict[str, str]]
|
line color map with {feature name:rgb values} |
None
|
storage_options |
dict
|
storage options to pass to read functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
DSA annotation |
Source code in src/luna/pathology/cli/dsa_viz.py
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 |
|
__qupath_polygon(input_urlpath, output_urlpath, image_filename, annotation_name, classes_to_include, line_colors=None, fill_colors=None, storage_options={}, output_storage_options={})
¶
Build DSA annotation json from Qupath polygon geojson
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_urlpath |
string
|
url/path of Qupath polygon geojson |
required |
annotation_name |
string
|
name of the annotation to be displayed in DSA |
required |
classes_to_include |
list
|
list of classification labels to visualize |
required |
line_colors |
map
|
line color map with {feature name:rgb values} |
None
|
fill_colors |
map
|
fill color map with {feature name:rgba values} |
None
|
storage_options |
dict
|
storage options to pass to read functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dsa annotation |
Source code in src/luna/pathology/cli/dsa_viz.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 |
|
__regional_polygon(input_urlpath, output_urlpath, image_filename, annotation_name, line_colors=None, fill_colors=None, storage_options={}, output_storage_options={})
¶
Build DSA annotation json from regional annotation geojson
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
string
|
path to regional annotation geojson |
required |
annotation_name |
string
|
name of the annotation to be displayed in DSA |
required |
line_colors |
dict
|
line color map with {feature name:rgb values} |
None
|
fill_colors |
dict
|
fill color map with {feature name:rgba values} |
None
|
storage_options |
dict
|
storage options to pass to read/write functions |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
DSA annotation |
Source code in src/luna/pathology/cli/dsa_viz.py
__stardist_cell(input_urlpath, output_urlpath, image_filename, annotation_name, line_colors=None, fill_colors=None, storage_options={}, output_storage_options={})
¶
Build DSA annotation json from TSV classification data generated by stardist
Processes a cell classification data generated by Qupath/stardist and adds the center coordinates of the cells as annotation elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_urlpath |
string
|
url/path to TSV classification data generated by stardist |
required |
annotation_name |
string
|
name of the annotation to be displayed in DSA |
required |
line_colors |
dict
|
line color map with {feature name:rgb values} |
None
|
fill_colors |
dict
|
fill color map with {feature name:rgba values} |
None
|
storage_options |
dict
|
storage options to pass to read/write functions |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dsa annotation |
Source code in src/luna/pathology/cli/dsa_viz.py
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 |
|
__stardist_polygon(input_urlpath, output_urlpath, image_filename, annotation_name, line_colors=None, fill_colors=None, storage_options={}, output_storage_options={})
¶
Build DSA annotation from stardist geojson classification results
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_urlpath |
string
|
URL/path to stardist geojson classification results |
required |
annotation_name |
string
|
name of the annotation to be displayed in DSA |
required |
line_colors |
dict[str, str]
|
user-provided line color map with {feature name:rgb values} |
None
|
fill_colors |
dict[str, str]
|
user-provided fill color map with {feature name:rgba values} |
None
|
Returns:
Type | Description |
---|---|
dict[str,str]: annotation file path |
Source code in src/luna/pathology/cli/dsa_viz.py
__stardist_polygon_tile(object_urlpath, tiles_urlpath, output_urlpath, image_filename, annotation_name_prefix, line_colors=None, fill_colors=None, storage_options={}, output_storage_options={})
¶
Build DSA annotation json from stardist geojson classification and labeled tiles
Parameters:
Name | Type | Description | Default |
---|---|---|---|
object_urlpath |
string
|
URL/path to stardist geojson classification results |
required |
tiles_urlpath |
string
|
URL/path to tiles manifest parquet |
required |
output_urlpath |
string
|
URL/path prefix to save annotations |
required |
image_filename |
string
|
name of the image file in DSA e.g. 123.svs |
required |
annotation_name_prefix |
string
|
name of the annotation to be displayed in DSA |
required |
line_colors |
dict
|
user-provided line color map with {feature name:rgb values} |
None
|
fill_colors |
dict
|
user-provided fill color map with {feature name:rgba values} |
None
|
storage_options |
dict
|
storage options to pass to read functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
DSA annotations |
Source code in src/luna/pathology/cli/dsa_viz.py
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 |
|
bitmask_polygon(input_map, output_urlpath, image_filename, annotation_name, line_colors=None, fill_colors=None, scale_factor=1, storage_options={}, output_storage_options={})
¶
Build DSA annotation json from bitmask PNGs
Vectorizes and simplifies contours from the bitmask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
map
|
map of {label:urlpath_to_bitmask_png} |
required |
annotation_name |
string
|
name of the annotation to be displayed in DSA |
required |
line_colors |
dict
|
line color map with {feature name:rgb values} |
None
|
fill_colors |
dict
|
fill color map with {feature name:rgba values} |
None
|
scale_factor |
int
|
scale to match the image on DSA. |
1
|
storage_options |
dict
|
storage options to pass to read/write functions |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
DSA annotation |
Source code in src/luna/pathology/cli/dsa_viz.py
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 |
|
bitmask_polygon_cli(input_map='???', output_urlpath='???', image_filename='???', annotation_name='???', line_colors=None, fill_colors=None, scale_factor=None, storage_options={}, output_storage_options={}, local_config='')
¶
Build DSA annotation json from bitmask PNGs
Vectorizes and simplifies contours from the bitmask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_map |
map
|
map of {label:path_to_bitmask_png} |
'???'
|
output_urlpath |
string
|
url/path to save the DSA compatible annotation |
'???'
|
image_filename |
string
|
name of the image file in DSA e.g. 123.svs |
'???'
|
annotation_name |
string
|
name of the annotation to be displayed in DSA |
'???'
|
line_colors |
dict
|
line color map with {feature name:rgb values} |
None
|
fill_colors |
dict
|
fill color map with {feature name:rgba values} |
None
|
scale_factor |
int
|
scale to match the image on DSA. |
None
|
storage_options |
dict
|
storage options to pass to read functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
local_config |
string
|
local config yaml file |
''
|
Returns:
Name | Type | Description |
---|---|---|
dict |
annotation file path |
Source code in src/luna/pathology/cli/dsa_viz.py
bmp_polygon(slide_manifest, output_urlpath, label_map, annotation_name, line_colors=None, fill_colors=None, scale_factor=1, storage_options={}, output_storage_options={}, annotation_column='bmp_polygon_url', output_column='bmp_polygon_dsa_url')
¶
Build DSA annotation json from a BMP with multiple labels.
Vectorizes and simplifies contours per label.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_manifest |
DataFrame[SlideSchema]
|
slide manifest from slide_etl |
required |
output_urlpath |
string
|
url/path prefix to save the DSA compatible annotation |
required |
label_map |
dict[int, str]
|
map of label number to label name |
required |
annotation_name |
string
|
name of the annotation to be displayed in DSA |
required |
line_colors |
dict[str, str]
|
line color map with {feature name:rgb values} |
None
|
fill_colors |
dict[str, str]
|
fill color map with {feature name:rgba values} |
None
|
scale_factor |
int
|
scale to match image DSA. |
1
|
storage_options |
dict
|
storage options to pass to read functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
annotation_column |
string
|
column containing url to BMP polygon |
'bmp_polygon_url'
|
output_column_suffix |
string
|
column suffix with result url to add to slide_manifest |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
annotation file path |
Source code in src/luna/pathology/cli/dsa_viz.py
bmp_polygon_cli(input_urlpath='???', output_urlpath='???', label_map='???', image_filename='???', annotation_name='???', line_colors=None, fill_colors=None, scale_factor=1, storage_options={}, output_storage_options={}, local_config='')
¶
Build DSA annotation json from a BMP with multiple labels.
Vectorizes and simplifies contours per label.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_urlpath |
string
|
url/path to bmp file |
'???'
|
output_urlpath |
string
|
url/path prefix to save the DSA compatible annotation |
'???'
|
label_map |
dict[int, str]
|
map of label number to label name |
'???'
|
image_filename |
string
|
name of the image file in DSA e.g. 123.svs |
'???'
|
annotation_name |
string
|
name of the annotation to be displayed in DSA |
'???'
|
line_colors |
dict[str, str]
|
line color map with {feature name:rgb values} |
None
|
fill_colors |
dict[str, str]
|
fill color map with {feature name:rgba values} |
None
|
scale_factor |
int
|
scale to match image DSA. |
1
|
storage_options |
dict
|
storage options to pass to read functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
annotation file path |
Source code in src/luna/pathology/cli/dsa_viz.py
check_filepaths_valid(urls, storage_options)
¶
Checks if all paths exist.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepaths |
list
|
file paths |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
True if all file paths exist, False otherwise |
Source code in src/luna/pathology/cli/dsa_viz.py
get_dsa_annotation(elements, annotation_name, description='')
¶
Helper function to get dsa annotation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elements |
list
|
list of annotation elements |
required |
annotation_name |
string
|
annotation name for HistomicsUI |
required |
image_filename |
string
|
name of the image in DSA e.g. 123.svs |
required |
Returns:
Name | Type | Description |
---|---|---|
string |
annotation file path. None if error in writing the file. |
Source code in src/luna/pathology/cli/dsa_viz.py
heatmap(slide_manifest, output_urlpath, annotation_name, column, tile_size, scale_factor=None, fill_colors=None, line_colors=None, output_column='', storage_options={}, output_storage_options={})
¶
Generate heatmap based on the tile scores
Creates a heatmap for the given column, using the color palette viridis
to set a fill value
- the color ranges from purple to yellow, for scores from 0 to 1.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_manifest |
DataFrame[SlideSchema]
|
slide manifest from slide_etl |
required |
output_urlpath |
string
|
URL/path prefix to save the DSA compatible annotation |
required |
annotation_name |
string
|
name of the annotation to be displayed in DSA |
required |
column |
string
|
column to visualize e.g. tile_score |
required |
tile_size |
int
|
size of tiles |
required |
scale_factor |
int
|
scale to match the image on DSA. |
None
|
line_colors |
dict
|
line color map with {feature name:rgb values} |
None
|
fill_colors |
dict
|
fill color map with {feature name:rgba values} |
None
|
storage_options |
dict
|
storage options to pass to read functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
annotation file path. None if error in writing the file. |
Source code in src/luna/pathology/cli/dsa_viz.py
1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 |
|
heatmap_cli(input_urlpath='???', output_urlpath='???', image_filename='???', annotation_name='???', column='???', tile_size='???', scale_factor=1, fill_colors=None, line_colors=None, storage_options={}, output_storage_options={}, local_config='')
¶
Generate heatmap based on the tile scores
Creates a heatmap for the given column, using the color palette viridis
to set a fill value
- the color ranges from purple to yellow, for scores from 0 to 1.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_urlpath |
string
|
URL/path to parquet with tile scores |
'???'
|
output_urlpath |
string
|
URL/path prefix to save the DSA compatible annotation |
'???'
|
image_filename |
string
|
name of the image file in DSA e.g. 123.svs |
'???'
|
annotation_name |
string
|
name of the annotation to be displayed in DSA |
'???'
|
column |
string
|
column to visualize e.g. tile_score |
'???'
|
tile_size |
int
|
size of tiles |
'???'
|
scale_factor |
int
|
scale to match the image on DSA. |
1
|
line_colors |
dict
|
line color map with {feature name:rgb values} |
None
|
fill_colors |
dict
|
fill color map with {feature name:rgba values} |
None
|
storage_options |
dict
|
storage options to pass to write functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
local_config |
string
|
local config yaml file |
''
|
Returns:
Name | Type | Description |
---|---|---|
dict |
annotation file path. None if error in writing the file. |
Source code in src/luna/pathology/cli/dsa_viz.py
qupath_polygon(slide_manifest, output_urlpath, image_filename, annotation_name, classes_to_include, line_colors=None, fill_colors=None, storage_options={}, output_storage_options={}, annotation_column='', output_column='')
¶
Build DSA annotation json from Qupath polygon geojson
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_manifest |
DataFrame[SlideSchema]
|
slide manifest from slide_etl |
required |
output_urlpath |
string
|
URL/path prefix for saving the DSA compatible annotation |
required |
image_filename |
string
|
name of the image file in DSA e.g. 123.svs |
required |
annotation_name |
string
|
name of the annotation to be displayed in DSA |
required |
classes_to_include |
list
|
list of classification labels to visualize |
required |
line_colors |
dict
|
line color map with {feature name:rgb values} |
None
|
fill_colors |
dict
|
fill color map with {feature name:rgba values} |
None
|
storage_options |
dict
|
storage options to pass to read functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
annotation_column |
string
|
column containing url to qupath geojson |
''
|
output_column_suffix |
string
|
column suffix with result url to add to slide_manifest |
required |
Returns:
Type | Description |
---|---|
DataFrame[SlideSchema]: slide manifest |
Source code in src/luna/pathology/cli/dsa_viz.py
qupath_polygon_cli(input_urlpath='???', output_urlpath='???', image_filename='???', annotation_name='???', classes_to_include='???', line_colors=None, fill_colors=None, storage_options={}, output_storage_options={}, local_config='')
¶
Build DSA annotation json from Qupath polygon geojson
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_urlpath |
string
|
URL/path of Qupath polygon geojson |
'???'
|
output_urlpath |
string
|
URL/path prefix for saving the DSA compatible annotation |
'???'
|
image_filename |
string
|
name of the image file in DSA e.g. 123.svs |
'???'
|
annotation_name |
string
|
name of the annotation to be displayed in DSA |
'???'
|
classes_to_include |
list
|
list of classification labels to visualize |
'???'
|
line_colors |
dict
|
line color map with {feature name:rgb values} |
None
|
fill_colors |
dict
|
fill color map with {feature name:rgba values} |
None
|
storage_options |
dict
|
storage options to pass to read functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
local_config |
string
|
local config yaml file |
''
|
Returns:
Name | Type | Description |
---|---|---|
dict |
annotation file path |
Source code in src/luna/pathology/cli/dsa_viz.py
regional_polygon(slide_manifest, output_urlpath, annotation_name, line_colors=None, fill_colors=None, storage_options={}, output_storage_options={}, annotation_column='', output_column='')
¶
Build DSA annotation json from regional annotation geojson
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_manifest |
DataFrame[SlideSchema]
|
slide manifest |
required |
output_urlpath |
string
|
URL/path prefix for saving dsa annotation json |
required |
annotation_name |
string
|
name of the annotation to be displayed in DSA |
required |
line_colors |
dict
|
line color map with {feature name:rgb values} |
None
|
fill_colors |
dict
|
fill color map with {feature name:rgba values} |
None
|
storage_options |
dict
|
storage options to pass to read functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
annotation_column |
string
|
column containing url to regional geojson |
''
|
output_column_suffix |
string
|
column suffix with result url to add to slide_manifest |
required |
Returns:
Type | Description |
---|---|
DataFrame[SlideSchema]: slide schema |
Source code in src/luna/pathology/cli/dsa_viz.py
regional_polygon_cli(input_urlpath='???', output_urlpath='???', image_filename='???', annotation_name='???', line_colors=None, fill_colors=None, storage_options={}, output_storage_options={}, local_config='')
¶
Build DSA annotation json from regional annotation geojson
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_urlpath |
string
|
URL/path of to regional annotation geojson |
'???'
|
output_urlpath |
string
|
URL/path prefix for saving dsa annotation json |
'???'
|
annotation_name |
string
|
name of the annotation to be displayed in DSA |
'???'
|
line_colors |
dict
|
line color map with {feature name:rgb values} |
None
|
fill_colors |
dict
|
fill color map with {feature name:rgba values} |
None
|
storage_options |
dict
|
storage options to pass to read functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
local_config |
string
|
local config yaml file |
''
|
Returns:
Name | Type | Description |
---|---|---|
dict |
annotation file path |
Source code in src/luna/pathology/cli/dsa_viz.py
save_dsa_annotation(dsa_annotation, output_urlpath, image_filename, storage_options={})
¶
Helper function to save annotation elements to a json file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dsa_annotation |
dict
|
DSA annotations |
required |
output_urlpath |
string
|
url/path to a directory to save the annotation file |
required |
image_filename |
string
|
name of the image in DSA e.g. 123.svs |
required |
storage_options |
dict
|
options for storage functions |
{}
|
Returns:
Name | Type | Description |
---|---|---|
string |
annotation file path. None if error in writing the file. |
Source code in src/luna/pathology/cli/dsa_viz.py
stardist_cell(slide_manifest, output_urlpath, annotation_name, line_colors=None, fill_colors=None, storage_options={}, output_storage_options={}, annotation_column='', output_column='')
¶
Build DSA annotation json from TSV classification data generated by stardist
Processes a cell classification data generated by Qupath/stardist and adds the center coordinates of the cells as annotation elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_urlpath |
string
|
URL/path to TSV classification data generated by stardist |
required |
output_urlpath |
string
|
URL/path prefix for saving dsa annotation json |
required |
annotation_name |
string
|
name of the annotation to be displayed in DSA |
required |
line_colors |
dict
|
line color map with {feature name:rgb values} |
None
|
fill_colors |
dict
|
fill color map with {feature name:rgba values} |
None
|
storage_options |
dict
|
storage options to pass to read functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
annotation_column |
string
|
column containing url to stardist polygon geojson |
''
|
output_column_suffix |
string
|
column suffix with result url to add to slide_manifest |
required |
Returns:
Type | Description |
---|---|
DataFrame[SlideSchema]: slide manifest |
Source code in src/luna/pathology/cli/dsa_viz.py
stardist_cell_cli(input_urlpath='???', output_urlpath='???', image_filename='???', annotation_name='???', line_colors=None, fill_colors=None, storage_options={}, output_storage_options={}, local_config='')
¶
Build DSA annotation json from TSV classification data generated by stardist
Processes a cell classification data generated by Qupath/stardist and adds the center coordinates of the cells as annotation elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_urlpath |
string
|
URL/path to TSV classification data generated by stardist |
'???'
|
output_urlpath |
string
|
URL/path prefix for saving dsa annotation json |
'???'
|
image_filename |
string
|
name of the image file in DSA e.g. 123.svs |
'???'
|
annotation_name |
string
|
name of the annotation to be displayed in DSA |
'???'
|
line_colors |
dict
|
line color map with {feature name:rgb values} |
None
|
fill_colors |
dict
|
fill color map with {feature name:rgba values} |
None
|
storage_options |
dict
|
storage options to pass to read functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
local_config |
string
|
local config YAML file |
''
|
Returns:
Type | Description |
---|---|
dict[str,str]: annotation file path |
Source code in src/luna/pathology/cli/dsa_viz.py
stardist_polygon(slide_manifest, output_urlpath, annotation_name, line_colors=None, fill_colors=None, storage_options={}, output_storage_options={}, annotation_column='', output_column='')
¶
Build DSA annotation json from stardist geojson classification results
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_manifest |
DataFrame[SlideSchema]
|
slide manifest from slide_etl |
required |
output_urlpath |
string
|
URL/path prefix to save annotations |
required |
annotation_name |
string
|
name of the annotation to be displayed in DSA |
required |
line_colors |
dict
|
user-provided line color map with {feature name:rgb values} |
None
|
fill_colors |
dict
|
user-provided fill color map with {feature name:rgba values} |
None
|
storage_options |
dict
|
storage options to pass to read functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
annotation_column |
string
|
column containing url to stardist polygon geojson |
''
|
output_column |
string
|
column with result url to add to slide_manifest |
''
|
Returns:
Type | Description |
---|---|
DataFrame[SlideSchema]: slide manifest |
Source code in src/luna/pathology/cli/dsa_viz.py
stardist_polygon_cli(input_urlpath='???', image_filename='???', annotation_name='???', output_urlpath='???', line_colors=None, fill_colors=None, storage_options={}, output_storage_options={}, local_config='')
¶
Build DSA annotation json from stardist geojson classification results
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_urlpath |
string
|
URL/path to stardist geojson classification results json |
'???'
|
image_filename |
string
|
name of the image file in DSA e.g. 123.svs |
'???'
|
annotation_name |
string
|
name of the annotation to be displayed in DSA |
'???'
|
output_urlpath |
string
|
URL/path prefix to save annotations |
'???'
|
line_colors |
dict
|
user-provided line color map with {feature name:rgb values} |
None
|
fill_colors |
dict
|
user-provided fill color map with {feature name:rgba values} |
None
|
storage_options |
dict
|
storage options to pass to read/write functions |
{}
|
local_config |
string
|
local config YAML file |
''
|
Returns:
Type | Description |
---|---|
dict[str,str]: annotation file path |
Source code in src/luna/pathology/cli/dsa_viz.py
stardist_polygon_tile(slide_manifest, output_urlpath, annotation_name_prefix, line_colors=None, fill_colors=None, storage_options={}, output_storage_options={}, annotation_column='', output_column_suffix='')
¶
Build DSA annotation json from stardist geojson classification and labeled tiles
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_manifest |
DataFrame[SlideSchema]
|
slide manifest |
required |
annotation_name_prefix |
string
|
name of the annotation to be displayed in DSA |
required |
output_urlpath |
string
|
URL/path prefix to save annotations |
required |
line_colors |
dict
|
user-provided line color map with {feature name:rgb values} |
None
|
fill_colors |
dict
|
user-provided fill color map with {feature name:rgba values} |
None
|
storage_options |
dict
|
storage options to pass to read functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
annotation_column |
string
|
column containing url to stardist polygon geojson |
''
|
output_column_suffix |
string
|
column suffix with result url to add to slide_manifest |
''
|
Returns:
Type | Description |
---|---|
dict[str,str]: annotation file path |
Source code in src/luna/pathology/cli/dsa_viz.py
stardist_polygon_tile_cli(object_urlpath='???', tiles_urlpath='???', image_filename='???', annotation_name_prefix='???', output_urlpath='???', line_colors=None, fill_colors=None, storage_options={}, output_storage_options={}, local_config='')
¶
Build DSA annotation json from stardist geojson classification and labeled tiles
Parameters:
Name | Type | Description | Default |
---|---|---|---|
object_urlpath |
string
|
URL/path to object geojson classification results |
'???'
|
tiles_urlpath |
string
|
URL/path to tiles manifest parquet |
'???'
|
image_filename |
string
|
name of the image file in DSA e.g. 123.svs |
'???'
|
annotation_name_prefix |
string
|
name of the annotation to be displayed in DSA |
'???'
|
output_urlpath |
string
|
URL/path prefix to save annotations |
'???'
|
line_colors |
dict
|
user-provided line color map with {feature name:rgb values} |
None
|
fill_colors |
dict
|
user-provided fill color map with {feature name:rgba values} |
None
|
storage_options |
dict
|
storage options to pass to read functions |
{}
|
output_storage_options |
dict
|
storage options to pass to write functions |
{}
|
local_config |
string
|
local config YAML file |
''
|
Returns:
Type | Description |
---|---|
dict[str,str]: annotation file path |
Source code in src/luna/pathology/cli/dsa_viz.py
extract_kfunction_statistics
¶
cli(input_cell_objects_urlpath='???', tile_size='???', intensity_label='???', tile_stride='???', radius='???', output_urlpath='.', storage_options={}, output_storage_options={}, local_config='')
¶
Run k function using a sliding window approach, where the k-function is computed locally in a smaller window, and aggregated across the entire slide.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_cell_objects_urlpath |
str
|
url/path to cell objects (.csv) |
'???'
|
tile_size |
int
|
size of tiles to use (at the requested magnification) |
'???'
|
tile_stride |
int
|
spacing between tiles |
'???'
|
intensity_label |
str
|
Columns of cell object to use for intensity calculations (for I-K function - spatial + some scalar value clustering) |
'???'
|
radius |
float
|
the radius to consider |
'???'
|
output_urlpath |
str
|
output URL/path prefix |
'.'
|
storage_options |
dict
|
storage options for reading the cell objects |
{}
|
Returns:
Type | Description |
---|---|
pd.DataFrame: metadata about function call |
Source code in src/luna/pathology/cli/extract_kfunction_statistics.py
extract_kfunction(input_cell_objects_urlpath, tile_size, intensity_label, tile_stride, radius, storage_options={})
¶
Run k function using a sliding window approach, where the k-function is computed locally in a smaller window, and aggregated across the entire slide.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_cell_objects |
str
|
URL/path to cell objects (.csv) |
required |
tile_size |
int
|
size of tiles to use (at the requested magnification) |
required |
intensity_label |
str
|
Columns of cell object to use for intensity calculations (for I-K function - spatial + some scalar value clustering) |
required |
tile_stride |
int
|
spacing between tiles |
required |
radius |
float
|
the radius to consider |
required |
storage_options |
dict
|
storage options for reading the cell objects |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
metadata about function call |
Source code in src/luna/pathology/cli/extract_kfunction_statistics.py
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 |
|
extract_shape_features
¶
cli(slide_mask_urlpath='???', label_cols='???', output_urlpath='???', include_smaller_regions=False, storage_options={}, output_storage_options={}, local_config='')
¶
Extracts shape and spatial features (HIF features) from a slide mask. This CLI extracts two sets of features. The first set are 'whole slide features', where the entire mask label is considred as a single region and features are extracted. These features are useful for determining things like total area of x tissue.
The second set of features are 'regional features', where each label is split up according to their connectivity and features are extracted from these smaller regions. These features are useful for determining things like solidity of the top ten largest regions of tissue y. Pixel intensity values from the WSI are unused. In order to generate connected regions, skimage generates a mask itself where different values coorespond to different regions, which removes the tissue type information from the original mask. So, the original mask is passed as an intensity image to ensure that each region can be associated with a tissue type.
Args: slide_mask_urlpath (str): URL/path to slide mask (*.tif) label_cols (List[str]): list of labels that coorespond to those in slide_mask_urlpath output_urlpath (str): output URL/path prefix include_smaller_regions (bool): include the smaller regions (not just larget) storage_options (dict): storage options to pass to read functions output_storage_options (dict): storage options to pass to write functions local_config (str): local config YAML file
Returns:
Name | Type | Description |
---|---|---|
dict |
output .tif path and the number of shapes for which features were generated |
Source code in src/luna/pathology/cli/extract_shape_features.py
extract_shape_features(mask, mask_values, include_smaller_regions=False, properties=['area', 'bbox', 'bbox_area', 'centroid', 'convex_area', 'convex_image', 'coords', 'eccentricity', 'equivalent_diameter', 'euler_number', 'extent', 'filled_area', 'filled_image', 'image', 'inertia_tensor', 'inertia_tensor_eigvals', 'label', 'local_centroid', 'major_axis_length', 'minor_axis_length', 'moments', 'moments_central', 'moments_hu', 'moments_normalized', 'orientation', 'perimeter', 'slice', 'solidity'])
¶
Extracts shape and spatial features (HIF features) from a slide mask
Args: slide_mask_urlpath (str): url/path to slide mask (*.tif) label_cols (List[str]): list of labels that coorespond to those in slide_mask_urlpath
Returns:
Type | Description |
---|---|
pd.DataFrame: shape and spatial features |
Source code in src/luna/pathology/cli/extract_shape_features.py
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 |
|
extract_stain_texture
¶
cli(slide_image_urlpath='???', slide_mask_urlpath='???', stain_sample_factor='???', stain_channel='???', tile_size='???', output_urlpath='.', storage_options={}, output_storage_options={}, local_config='')
¶
Compute GLCM texture features on a de-convolved slide image
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_image_urlpath |
str
|
url/path to slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...) |
'???'
|
slide_mask_urlpath |
str
|
url/path to slide mask (.tif) |
'???'
|
stain_sample_factor |
float
|
downsample factor to use for stain vector estimation |
'???'
|
stain_channel |
int
|
which channel of the deconvovled image to use for texture analysis |
'???'
|
tile_size |
int
|
size of tiles to use (at the requested magnification) (500-1000 recommended) |
'???'
|
output_urlpath |
str
|
output/working directory |
'.'
|
Returns:
Name | Type | Description |
---|---|---|
dict |
metadata about function call |
Source code in src/luna/pathology/cli/extract_stain_texture.py
extract_stain_texture(slide_image_urlpath, slide_mask_urlpath, stain_sample_factor, stain_channel, tile_size, output_urlpath, storage_options, output_storage_options)
¶
Compute GLCM texture after automatically deconvolving the image into stain channels, using tile-based processing
Runs statistics on distribution.
Save a feature csv file at the output directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_image_urlpath |
str
|
url/path to slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...) |
required |
slide_mask_urlpath |
str
|
url/path to slide mask (.tif) |
required |
stain_sample_factor |
float
|
downsample factor to use for stain vector estimation |
required |
stain_channel |
int
|
which channel of the deconvovled image to use for texture analysis |
required |
tile_size |
int
|
size of tiles to use (at the requested magnification) (500-1000 recommended) |
required |
output_urlpath |
str
|
output/working URL/path prefix |
required |
storage_options |
dict
|
storage options to pass to reading functions |
required |
output_storage_options |
dict
|
storage options to pass to writing functions |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
metadata about function call |
Source code in src/luna/pathology/cli/extract_stain_texture.py
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 |
|
extract_tile_shape_features
¶
__extract_tile_shape_features(objects_urlpath, tiles_urlpath, slide_urlpath, output_urlpath, resize_factor=16, detection_probability_threshold=None, slide_id='', statistical_descriptors=StatisticalDescriptors.ALL, cellular_features=CellularFeatures.ALL, property_type=PropertyType.ALL, include_smaller_regions=False, label_cols=None, storage_options={}, output_storage_options={}, properties=['area', 'convex_area', 'eccentricity', 'equivalent_diameter', 'euler_number', 'extent', 'label', 'major_axis_length', 'minor_axis_length', 'perimeter', 'solidity'])
¶
Extracts shape and spatial features (HIF features) from a slide mask.
Args: objects_urlpath (str): URL/path to object file (geopandas supported formats) tiles_urlpath (str): URL/path to tiles manifest (parquet) slide_urlpath (str): URL/path to slide (tiffslide supported formats) output_urlpath (str): output URL/path resize_factor (int): factor to downsample slide image detection_probability_threshold (Optional[float]): detection probability threshold slide_id (str): Slide ID to add to dataframes statistical_descriptors (StatisticalDescriptors): statistical descriptors to calculate cellular_features (CellularFeatures): cellular features to include property_type (PropertyType): properties to include include_smaller_regions (bool): include smaller regions label_cols (List[str]): list of score columns to use for the classification. Tile is classified as the column with the max score storage_options (dict): storage options to pass to reading functions output_storage_options (dict): storage options to pass to writing functions properties (List[str]): list of whole slide image properties to extract. Needs to be parquet compatible (numeric). Returns: dict: output paths and the number of features generated
Source code in src/luna/pathology/cli/extract_tile_shape_features.py
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 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
|
cli(slide_urlpath='???', object_urlpath='???', tiles_urlpath='???', output_urlpath='.', resize_factor=16, detection_probability_threshold=None, statistical_descriptors=StatisticalDescriptors.ALL, cellular_features=CellularFeatures.ALL, property_type=PropertyType.ALL, include_smaller_regions=False, label_cols=None, storage_options={}, output_storage_options={}, local_config='')
¶
Extracts shape and spatial features (HIF features) from a slide mask.
Args: slide_urlpath (str): URL/path to slide (tiffslide supported formats) object_urlpath (str): URL/path to object file (geopandas supported formats) tiles_urlpath (str): URL/path to tiles manifest (parquet) output_urlpath (str): URL/path to output parquet file resize_factor (int): factor to downsample slide image detection_probability_threshold (Optional[float]): detection probability threshold statistical_descriptors (str): statistical descriptors to calculate. One of All, Quantiles, Stats, or Density cellular_features (str): cellular features to include. One of All, Nucleus, Cell, Cytoplasm, and Membrane property_type (str): properties to include. One of All, Geometric, or Stain include_smaller_regions (bool): include smaller regions in output label_cols (List[str]): list of score columns to use for the classification. Tile is classified as the column with the max score storage_options (dict): storage options to pass to reading functions output_storage_options (dict): storage options to pass to writing functions local_config (str): local config yaml file
Returns:
Name | Type | Description |
---|---|---|
dict |
output paths and the number of features generated |
Source code in src/luna/pathology/cli/extract_tile_shape_features.py
extract_tile_shape_features(slide_manifest, output_urlpath, resize_factor=16, detection_probability_threshold=None, statistical_descriptors=StatisticalDescriptors.ALL, cellular_features=CellularFeatures.ALL, property_type=PropertyType.ALL, include_smaller_regions=False, label_cols=None, storage_options={}, output_storage_options={}, objects_column='stardist_geojson_url', annotation_column='tile_shape_features_url', properties=['area', 'convex_area', 'eccentricity', 'equivalent_diameter', 'euler_number', 'extent', 'label', 'major_axis_length', 'minor_axis_length', 'perimeter', 'solidity'])
¶
Extracts shape and spatial features (HIF features) from a slide mask.
Args: slide_manifest (DataFrame[SlideSchema]): slide manifest from slide_etl output_urlpath (str): output URL/path resize_factor (int): factor to downsample slide image detection_probability_threshold (Optional[float]): detection probability threshold statistical_descriptors (str): statistical descriptors to calculate. One of All, Quantiles, Stats, or Density cellular_features (str): cellular features to include. One of All, Nucleus, Cell, Cytoplasm, and Membrane property_type (str): properties to include. One of All, Geometric, or Stain include_smaller_regions (bool): include smaller regions in output label_cols (List[str]): list of score columns to use for the classification. Tile is classified as the column with the max score storage_options (dict): storage options to pass to reading functions output_storage_options (dict): storage options to pass to writing functions local_config (str): local config yaml file objects_column (str): slide manifest column name with stardist geoJSON URLs annotation_column (str): column to add to slide manifest with url to extracted features properties (List[str]): properties to extract
Returns:
Type | Description |
---|---|
DataFrame[SlideSchema]: slide manifest |
Source code in src/luna/pathology/cli/extract_tile_shape_features.py
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 |
|
extract_tile_statistics
¶
cli(tiles_urlpath='???', output_urlpath='???', storage_options={}, output_storage_options={}, local_config='')
¶
Extracts statistics over tiles
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tiles_urlpath |
str
|
Tiles parquet file for slide(s). Absolute or relative filepath. Prefix with protocol to read from alternative filesystems |
'???'
|
output_urlpath |
str
|
Output prefix. Absolute or relative filepath. Prefix with protocol to write to alternative filesystems |
'???'
|
storage_options |
dict
|
extra options that make sense for reading from a particular storage connection |
{}
|
output_storage_options |
dict
|
extra options that make sense for writing to a particular storage connection |
{}
|
local_config |
str
|
local config yaml file |
''
|
Source code in src/luna/pathology/cli/extract_tile_statistics.py
extract_tile_statistics(tiles_urlpath, storage_options)
¶
Extracts statistics over tiles
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tiles_urlpath |
str
|
Tiles parquet file for slide(s). Absolute or relative filepath. Prefix with protocol to read from alternative filesystems |
required |
output_urlpath |
str
|
Output prefix. Absolute or relative filepath. Prefix with protocol to write to alternative filesystems |
required |
storage_options |
dict
|
extra options that make sense for reading from a particular storage connection |
required |
output_storage_options |
dict
|
extra options that make sense for writing to a particular storage connection |
required |
Returns:
Type | Description |
---|---|
pd.DataFrame: metadata about function call |
Source code in src/luna/pathology/cli/extract_tile_statistics.py
generate_mask
¶
cli(slide_urlpath='???', roi_urlpath='???', output_urlpath='???', annotation_name='???', storage_options={}, output_storage_options={}, local_config='')
¶
Generate a full resolution mask image (.tif) from vector annotations (polygons, shapes)
Inputs: input_slide_image: slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...) input_slide_roi: roi containing vector shapes (.annotations, .json) Outputs: slide_mask Example: generate_mask ./slides/10001.svs ./halo/10001.job18484.annotations -an Tumor -o ./masks/10001/
Source code in src/luna/pathology/cli/generate_mask.py
generate_mask(slide_urlpath, roi_urlpath, output_urlpath, annotation_name, storage_options, output_storage_options)
¶
Generate a full resolution mask image (.tif) from vector annotations (polygons, shapes)
Take into account positive and negative spaces. Essentially rasterizes a polygon file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_urlpath |
str
|
slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...) absolute or relative path. prefix with scheme to use alternative file systems. |
required |
roi_urlpath |
str
|
halo or other polygonal annotation file (.xml, .geojson) absolute or relative path. prefix with scheme to use alternative file systems. |
required |
output_urlpath |
str
|
output/working absolute or relative path. prefix with scheme to use alternative file systems. |
required |
annotation_name |
str
|
name of annotation layer to use |
required |
storage_options |
dict
|
storage options that make sense for the file storage used |
required |
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
mask properties |
Source code in src/luna/pathology/cli/generate_mask.py
generate_tile_labels
¶
cli(annotation_urlpath='???', tiles_urlpath='???', slide_id='???', output_urlpath='???', storage_options={}, output_storage_options={}, local_config='')
¶
Queries the dataset at input_slide_annotation_dataset for a slide_id matching input_slide_tiles
Adds regional_label, intersection_area columns to slide tiles, where the former is the annotation label, and the latter the fraction of intersecting area between the tile and annotation regions
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotation_urlpath |
str
|
url/path to parquet annotation dataset |
'???'
|
tiles_urlpath |
str
|
url/path to a slide-tile manifest file (.tiles.parquet) |
'???'
|
slide_id |
str
|
slide ID |
'???'
|
output_urlpath |
str
|
output url/path prefix |
'???'
|
storage_options |
dict
|
options to pass to reading functions |
{}
|
output_storage_options |
dict
|
options to pass to writing functions |
{}
|
local_config |
str
|
url/path to local config YAML file |
''
|
Returns: dict: metadata
Source code in src/luna/pathology/cli/generate_tile_labels.py
generate_tile_labels(annotation_urlpath, tiles_urlpath, slide_id, storage_options={})
¶
Queries the dataset at input_slide_annotation_dataset for a slide_id matching input_slide_tiles
Adds regional_label, intersection_area columns to slide tiles, where the former is the annotation label, and the latter the fraction of intersecting area between the tile and annotation regions
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotation_urlpath |
str
|
url/path to parquet annotation dataset |
required |
tiles_urlpath |
str
|
url/path to a slide-tile manifest file (.tiles.parquet) |
required |
slide_id |
str
|
slide ID |
required |
storage_options |
dict
|
options to pass to reading functions |
{}
|
Returns: pd.DataFrame: tile dataframe with regional_label, and intersection_area columns
Source code in src/luna/pathology/cli/generate_tile_labels.py
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 |
|
generate_tile_mask
¶
cli(slide_urlpath='???', tiles_urlpath='', label_cols='???', output_urlpath='.', storage_options={}, output_storage_options={})
¶
Converts categorical tile labels to a slide image mask. This mask can be used for feature extraction and spatial analysis.
Args: slide_urlpath (str): url/path to slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...) tiles_urlpath (str): url/path to valid SlideTiles table label_cols (List[str]): list of label columns in the input_slide_tiles table to generate the mask with output_urlpath (str): output url/path prefix storage_options (dict): storage options to pass to reading functions output_storage_options (dict): storage options to pass to writing functions
Returns:
Name | Type | Description |
---|---|---|
dict |
output properties |
Source code in src/luna/pathology/cli/generate_tile_mask.py
convert_tiles_to_mask(tiles_df, slide_width, slide_height, label_cols, output_urlpath='', output_storage_options={})
¶
Converts categorical tile labels to a slide image mask. This mask can be used for feature extraction and spatial analysis.
Args: tiles_df (pd.DataFrame): url/path to slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...) slide_width (int): slide width slide_height (int): slide height label_cols (Union[str, List[str]]): column with labels or list of label columns in the tiles_urlpath table to generate the mask with
Returns:
Type | Description |
---|---|
np.ndarray, Dict[int, str]: image mask, mask value mapping |
Source code in src/luna/pathology/cli/generate_tile_mask.py
generate_tiles
¶
__generate_tiles(slide_urlpath, tile_size, output_urlpath, force, requested_magnification=None, storage_options={}, output_storage_options={})
¶
Rasterize a slide into smaller tiles
Tiles addresses and arrays are saved as key-value pairs in (tiles.h5), and the corresponding manifest/header file (tiles.csv) is also generated
Necessary data for the manifest file are: address, tile_image_file, full_resolution_tile_size, tile_image_size_xy
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_urlpath |
str
|
slide url/path |
required |
tile_size |
int
|
size of tiles to use (at the requested magnification) |
required |
requested_magnification |
float
|
Magnification scale at which to perform computation |
None
|
Returns:
Type | Description |
---|---|
dict
|
DataFrame[TileSchema]: tile manifest |
Source code in src/luna/pathology/cli/generate_tiles.py
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 |
|
cli(slide_urlpath='???', tile_size='???', requested_magnification=None, storage_options={}, output_storage_options={}, dask_options={}, local_config='', output_urlpath='.', force=False)
¶
Rasterize a slide into smaller tiles, saving tile metadata as rows in a csv file
Necessary data for the manifest file are: address, x_coord, y_coord, xy_extent, tile_size, tile_units
Inputs: input_slide_image: slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...) Outputs: slide_tiles Example: generate_tiles 10001.svs -rts 244 -rmg 10 -o 10001/tiles
Source code in src/luna/pathology/cli/generate_tiles.py
infer_tile_labels
¶
__infer_tile_labels(tiles_urlpath, slide_id, output_urlpath, force, torch_model_repo_or_dir, model_name, num_cores, batch_size, kwargs, use_gpu, insecure, storage_options, output_storage_options)
¶
Run inference using a model and transform definition (either local or using torch.hub)
Decorates existing slide_tiles with additional columns corresponding to class prediction/scores from the model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tiles_urlpath |
str
|
path to a slide-tile manifest file (.tiles.parquet) |
required |
slide_id |
str
|
slide ID |
required |
output_urlpath |
str
|
output/working directory |
required |
torch_model_repo_or_dir |
str
|
repository root name like (namespace/repo) at github.com to serve torch.hub models. Or path to a local model (e.g. msk-mind/luna-ml) |
required |
model_name |
str
|
torch hub model name (a nn.Module at the repo repo_name) |
required |
num_cores |
int
|
Number of cores to use for CPU parallelization |
required |
batch_size |
int
|
size in batch dimension to chuck inference (8-256 recommended, depending on memory usage) |
required |
kwargs |
dict
|
additional keywords to pass to model initialization |
required |
use_gpu |
bool
|
use GPU if available |
required |
insecure |
bool
|
insecure SSL |
required |
storage_options |
dict
|
storage options to pass to reading functions |
required |
output_storage_options |
dict
|
storage options to pass to writing functions |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
metadata |
Source code in src/luna/pathology/cli/infer_tile_labels.py
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 |
|
cli(slide_urlpath='', tiles_urlpath='', tile_size=None, filter_query='', requested_magnification=None, torch_model_repo_or_dir='???', model_name='???', num_cores=4, batch_size=8, output_urlpath='.', force=False, kwargs={}, use_gpu=False, dask_options={}, insecure=False, storage_options={}, output_storage_options={})
¶
Run inference using a model and transform definition (either local or using torch.hub)
Decorates existing slide_tiles with additional columns corresponding to class prediction/scores from the model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_urlpath |
str
|
url/path to slide image (virtual slide formats compatible with TiffSlide, .svs, .tif, .scn, ...) |
''
|
tiles_urlpath |
str
|
path to a slide-tile manifest file (.tiles.csv) |
''
|
tile_size |
Optional[int]
|
size of tiles to use (at the requested magnification) |
None
|
filter_query |
str
|
pandas query by which to filter tiles based on their various tissue detection scores |
''
|
requested_magnification |
Optional[int]
|
Magnification scale at which to perform computation |
None
|
torch_model_repo_or_dir |
str
|
repository root name like (namespace/repo) at github.com to serve torch.hub models. Or path to a local model (e.g. msk-mind/luna-ml) |
'???'
|
model_name |
str
|
torch hub model name (a nn.Module at the repo repo_name) |
'???'
|
num_cores |
int
|
Number of cores to use for CPU parallelization |
4
|
batch_size |
int
|
size in batch dimension to chuck inference (8-256 recommended, depending on memory usage) |
8
|
output_urlpath |
str
|
output/working directory |
'.'
|
force |
bool
|
overwrite outputs if they exist |
False
|
kwargs |
dict
|
additional keywords to pass to model initialization |
{}
|
use_gpu |
bool
|
use GPU if available |
False
|
dask_options |
dict
|
options to pass to dask client |
{}
|
insecure |
bool
|
insecure SSL |
False
|
storage_options |
dict
|
storage options to pass to reading functions |
{}
|
output_storage_options |
dict
|
storage options to pass to writing functions |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
metadata |
Source code in src/luna/pathology/cli/infer_tile_labels.py
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 |
|
infer_tile_labels(slide_manifest, tile_size=None, filter_query='', thumbnail_magnification=None, tile_magnification=None, torch_model_repo_or_dir='', model_name='', num_cores=1, batch_size=2000, output_urlpath='.', force=True, kwargs={}, use_gpu=False, insecure=False, storage_options={}, output_storage_options={})
¶
Run inference using a model and transform definition (either local or using torch.hub)
Decorates existing tiles manifests with additional columns corresponding to class prediction/scores from the model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_manifest |
DataFrame
|
slide manifest from slide_etl |
required |
tile_size |
Optional[int]
|
size of tiles to use (at the requested magnification) |
None
|
filter_query |
str
|
pandas query by which to filter tiles based on their various tissue detection scores |
''
|
thumbnail_magnification |
Optional[int]
|
Magnification scale at which to detect tissue |
None
|
tile_magnification |
Optional[int]
|
Magnification scale at which to generate tiles |
None
|
torch_model_repo_or_dir |
str
|
repository root name like (namespace/repo) at github.com to serve torch.hub models. Or path to a local model (e.g. msk-mind/luna-ml) |
''
|
model_name |
str
|
torch hub model name (a nn.Module at the repo repo_name) |
''
|
num_cores |
int
|
Number of cores to use for CPU parallelization |
1
|
batch_size |
int
|
size in batch dimension to chuck inference (8-256 recommended, depending on memory usage) |
2000
|
output_urlpath |
str
|
output/working directory |
'.'
|
force |
bool
|
overwrite outputs if they exist |
True
|
kwargs |
dict
|
additional keywords to pass to model initialization |
{}
|
use_gpu |
bool
|
use GPU if available |
False
|
insecure |
bool
|
insecure SSL |
False
|
storage_options |
dict
|
storage options to pass to reading functions |
{}
|
output_storage_options |
dict
|
storage options to pass to writing functions |
{}
|
Returns:
Type | Description |
---|---|
DataFrame[SlideSchema]
|
pd.DataFrame: slide manifest |
Source code in src/luna/pathology/cli/infer_tile_labels.py
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 |
|
merge_shape_features
¶
cli(shape_features_urlpaths='???', output_urlpath='.', flatten_index=True, fraction_not_null=0.5, storage_options={}, output_storage_options={}, local_config='')
¶
Merges shape features dataframes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shape_features_urlpaths |
List[str]
|
URL/paths to shape featurs parquet files |
'???'
|
output_urlpath |
str
|
URL/path to output parquet file |
'.'
|
fraction_not_null |
float
|
fraction not null to keep column to keep in wide format |
0.5
|
storage_options |
dict
|
storage options to pass to reading functions |
{}
|
output_storage_options |
dict
|
storage options to pass to writing functions |
{}
|
local_config |
str
|
local config yaml file |
''
|
Returns:
Name | Type | Description |
---|---|---|
dict |
output paths and the number of features generated |
Source code in src/luna/pathology/cli/merge_shape_features.py
run_stardist_cell_detection
¶
__stardist_cell_lymphocyte(slide_urlpath, output_urlpath, slide_id, num_cores, use_gpu=False, image='mskmind/qupath-stardist:0.4.3', use_singularity=False, max_heap_size='64G', storage_options={}, output_storage_options={})
¶
Run stardist using qupath CLI
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_urlpath |
str
|
url/path to slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...) |
required |
output_urlpath |
str
|
output url/path |
required |
num_cores |
int
|
Number of cores to use for CPU parallelization |
required |
use_gpu |
bool
|
use GPU |
False
|
image |
str
|
docker/singularity image |
'mskmind/qupath-stardist:0.4.3'
|
use_singularity |
bool
|
use singularity instead of docker |
False
|
max_heap_size |
str
|
maximum heap size to pass to java options |
'64G'
|
storage_options |
dict
|
storage options to pass to reading functions |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
run metadata |
Source code in src/luna/pathology/cli/run_stardist_cell_detection.py
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 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
|
__stardist_simple(slide_urlpath, cell_expansion_size, image_type, output_urlpath, debug_opts, num_cores, image, use_singularity, max_heap_size, storage_options, output_storage_options)
¶
Run stardist using qupath CLI on slides in a slide manifest from slide_etl. URIs to resulting GeoJSON will be stored in a specified column of the returned slide manifest.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_urlpath |
str
|
path to slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...) |
required |
cell_expansion_size |
float
|
size in pixels to expand cell cytoplasm |
required |
num_cores |
int
|
Number of cores to use for CPU parallelization |
required |
image_type |
str
|
qupath image type (BRIGHTFIELD_H_DAB) |
required |
output_urlpath |
str
|
output url/path |
required |
debug_opts |
str
|
debug options passed as arguments to groovy script |
required |
image |
str
|
docker/singularity image |
required |
use_singularity |
bool
|
use singularity instead of docker |
required |
max_heap_size |
str
|
maximum heap size to pass to java options |
required |
storage_options |
dict
|
storage options to pass to reading functions |
required |
output_storage_options |
dict
|
storage options to pass to writing functions |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
run metadata |
Source code in src/luna/pathology/cli/run_stardist_cell_detection.py
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 |
|
stardist_cell_lymphocyte(slide_manifest, output_urlpath, num_cores, use_gpu=False, image='mskmind/qupath-stardist:0.4.3', use_singularity=False, max_heap_size='64G', storage_options={}, output_storage_options={}, annotation_column='lymphocyte_geojson_url')
¶
Run stardist using qupath CLI
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_manifest |
DataFrame[SlideSchema]
|
slide manifest from slide_etl |
required |
output_urlpath |
str
|
output url/path |
required |
num_cores |
int
|
Number of cores to use for CPU parallelization |
required |
use_gpu |
bool
|
use GPU |
False
|
image |
str
|
docker/singularity image |
'mskmind/qupath-stardist:0.4.3'
|
use_singularity |
bool
|
use singularity instead of docker |
False
|
max_heap_size |
str
|
maximum heap size to pass to java options |
'64G'
|
storage_options |
dict
|
storage options to pass to reading functions |
{}
|
output_storage_options |
dict
|
storage options to pass to writing functions |
{}
|
annotation_column |
str
|
name of column in resulting slide manifest to store GeoJson URIs |
'lymphocyte_geojson_url'
|
Returns:
Type | Description |
---|---|
DataFrame[SlideSchema]
|
DataFrame[SlideSchema]: slide manifest |
Source code in src/luna/pathology/cli/run_stardist_cell_detection.py
stardist_cell_lymphocyte_cli(slide_urlpath='???', output_urlpath='.', num_cores=1, use_gpu=False, image='mskmind/qupath-stardist:0.4.3', use_singularity=False, max_heap_size='64G', storage_options={}, output_storage_options={})
¶
Run stardist using qupath CLI
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_urlpath |
str
|
url/path to slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...) |
'???'
|
output_urlpath |
str
|
output url/path |
'.'
|
num_cores |
int
|
Number of cores to use for CPU parallelization |
1
|
use_gpu |
bool
|
use GPU |
False
|
image |
str
|
docker/singularity image |
'mskmind/qupath-stardist:0.4.3'
|
use_singularity |
bool
|
use singularity instead of docker |
False
|
max_heap_size |
str
|
maximum heap size to pass to java options |
'64G'
|
storage_options |
dict
|
storage options to pass to reading functions |
{}
|
output_storage_options |
dict
|
storage options to pass to writing functions |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
run metadata |
Source code in src/luna/pathology/cli/run_stardist_cell_detection.py
stardist_simple(slide_manifest, cell_expansion_size, image_type, output_urlpath, debug_opts, num_cores, image, use_singularity, max_heap_size, storage_options, output_storage_options, annotation_column='stardist_geojson_url')
¶
Run stardist using qupath CLI on slides in a slide manifest from slide_etl. URIs to resulting GeoJSON will be stored in a specified column of the returned slide manifest.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_manifest |
DataFrame[SlideSchema]
|
slide manifest from slide_etl |
required |
cell_expansion_size |
float
|
size in pixels to expand cell cytoplasm |
required |
image_type |
str
|
qupath image type (BRIGHTFIELD_H_DAB) |
required |
output_urlpath |
str
|
output url/path |
required |
debug_opts |
str
|
debug options passed as arguments to groovy script |
required |
num_cores |
int
|
Number of cores to use for CPU parallelization |
required |
image |
str
|
docker/singularity image |
required |
use_singularity |
bool
|
use singularity instead of docker |
required |
max_heap_size |
str
|
maximum heap size to pass to java options |
required |
storage_options |
dict
|
storage options to pass to reading functions |
required |
output_storage_options |
dict
|
storage options to pass to writing functions |
required |
annotation_column |
str
|
name of column in resulting slide manifest to store GeoJson URIs |
'stardist_geojson_url'
|
Returns:
Type | Description |
---|---|
DataFrame[SlideSchema]
|
DataFrame[SlideSchema]: slide manifest |
Source code in src/luna/pathology/cli/run_stardist_cell_detection.py
stardist_simple_cli(slide_urlpath='???', cell_expansion_size='???', image_type='???', output_urlpath='.', debug_opts='', num_cores=1, image='mskmind/qupath-stardist:0.4.3', use_singularity=False, max_heap_size='64G', storage_options={}, output_storage_options={}, local_config='')
¶
Run stardist using qupath CLI
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_slide_image |
str
|
path to slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...) |
required |
cell_expansion_size |
float
|
size in pixels to expand cell cytoplasm |
'???'
|
num_cores |
int
|
Number of cores to use for CPU parallelization |
1
|
image_type |
str
|
qupath image type (BRIGHTFIELD_H_DAB) |
'???'
|
output_urlpath |
str
|
output url/path |
'.'
|
debug_opts |
str
|
debug options passed as arguments to groovy script |
''
|
image |
str
|
docker/singularity image |
'mskmind/qupath-stardist:0.4.3'
|
use_singularity |
bool
|
use singularity instead of docker |
False
|
max_heap_size |
str
|
maximum heap size to pass to java options |
'64G'
|
storage_options |
dict
|
storage options to pass to reading functions |
{}
|
output_storage_options |
dict
|
storage options to pass to writing functions |
{}
|
local_config |
str
|
local config yaml file |
''
|
Returns:
Name | Type | Description |
---|---|---|
dict |
metadata about function call |
Source code in src/luna/pathology/cli/run_stardist_cell_detection.py
run_tissue_detection
¶
cli(slide_urlpath='???', tiles_urlpath='', filter_query='???', tile_size=None, thumbnail_magnification=None, tile_magnification=None, batch_size=2000, output_urlpath='.', force=False, dask_options={}, storage_options={}, output_storage_options={}, local_config='')
¶
Run simple/deterministic tissue detection algorithms based on a filter query, to reduce tiles to those (likely) to contain actual tissue Args: slide_urlpath (str): url/path to slide image (virtual slide formats compatible with pyvips, .svs, .tif, .scn, ...) tiles_urlpath (str): url/path to tiles manifest (parquet) filter_query (str): pandas query by which to filter tiles based on their various tissue detection scores tile_size (int): size of tiles to use (at the requested magnification) thumbnail_magnification (Optional[int]): Magnification scale at which to create thumbnail for tissue detection tile_magnification (Optional[int]): Magnification scale at which to generate tiles batch_size (int): batch size for processing output_urlpath (str): Output url/path force (bool): overwrite outputs if they exist dask_options (dict): dask options storage_options (dict): storage options to pass to reading functions output_storage_options (dict): storage options to pass to writing functions local_config (str): local config file Returns: dict: metadata about cli function call
Source code in src/luna/pathology/cli/run_tissue_detection.py
compute_otsu_score(tile, slide_path, otsu_threshold)
¶
Return otsu score for the tile. Args: row (pd.Series): row with tile metadata slide_path (str): path to slide otsu_threshold (float): otsu threshold value
Source code in src/luna/pathology/cli/run_tissue_detection.py
compute_purple_score(tile, slide_path)
¶
Return purple score for the tile. Args: row (pd.Series): row with tile metadata slide_url (str): path to slide
Source code in src/luna/pathology/cli/run_tissue_detection.py
compute_stain_score(tile, slide_path, vectors, channel, stain_threshold)
¶
Returns stain score for the tile Args: row (pd.Series): row with tile metadata slide_url (str): path to slide vectors (np.ndarray): stain vectors channel (int): stain channel stain_threshold (float): stain threshold value
Source code in src/luna/pathology/cli/run_tissue_detection.py
detect_tissue(slide_manifest, tile_size=None, thumbnail_magnification=None, tile_magnification=None, filter_query='', batch_size=2000, force=True, storage_options={}, output_urlpath='.', output_storage_options={})
¶
Run simple/deterministic tissue detection algorithms based on a filter query, to reduce tiles to those (likely) to contain actual tissue Args: slide_manifest (DataFrame[SlideSchema]): slide manifest from slide_etl tile_size (int): size of tiles to use (at the requested magnification) thumbnail_magnification (Optional[int]): Magnification scale at which to create thumbnail for tissue detection tile_magnification (Optional[int]): Magnification scale at which to generate tiles filter_query (str): pandas query by which to filter tiles based on their various tissue detection scores batch_size (int): batch size for processing force (bool): overwite outputs if they exist storage_options (dict): storage options to pass to reading functions output_urlpath (str): Output url/path output_storage_options (dict): storage options to pass to writing functions Returns: DataFrame[SlideSchema]: slide manifest
Source code in src/luna/pathology/cli/run_tissue_detection.py
save_tiles
¶
__save_tiles(tiles_urlpath, slide_urlpath, output_h5_path, batch_size=2000, storage_options={}, output_storage_options={})
¶
Saves tiles to disk
Tiles addresses and arrays are saved as key-value pairs in (tiles.h5), and the corresponding manifest/header file (tiles.parquet) is also generated
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tiles_urlpath |
str
|
tile manifest |
required |
slide_urlpath |
str
|
url/path to slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...) |
required |
output_urlpath |
str
|
output url/path |
required |
batch_size |
int
|
size in batch dimension to chuck jobs |
2000
|
output_storage_options |
dict
|
storage options to writing functions |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
metadata about function call |
Source code in src/luna/pathology/cli/save_tiles.py
cli(slide_urlpath='???', tiles_urlpath='???', batch_size=2000, output_urlpath='.', force=False, storage_options={}, output_storage_options={}, dask_options={}, local_config='')
¶
Saves tiles to disk
Tiles addresses and arrays are saved as key-value pairs in (tiles.h5), and the corresponding manifest/header file (tiles.parquet) is also generated
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_urlpath |
str
|
url/path to slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...) |
'???'
|
tiles_urlpath |
str
|
url/path to tile manifest (.parquet) |
'???'
|
batch_size |
int
|
size in batch dimension to chuck jobs |
2000
|
output_urlpath |
str
|
output url/path prefix |
'.'
|
force |
bool
|
overwrite outputs if they exist |
False
|
storage_options |
dict
|
storage options to reading functions |
{}
|
output_storage_options |
dict
|
storage options to writing functions |
{}
|
dask_options |
dict
|
dask options |
{}
|
local_config |
str
|
url/path to local config yaml file |
''
|
Returns:
Name | Type | Description |
---|---|---|
dict |
metadata about function call |
Source code in src/luna/pathology/cli/save_tiles.py
save_tiles(slide_manifest, output_urlpath, force=True, batch_size=2000, storage_options={}, output_storage_options={})
¶
Saves tiles to disk
Tiles addresses and arrays are saved as key-value pairs in (tiles.h5), and the corresponding manifest/header file (tiles.parquet) is also generated
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_manifest |
DataFrame[SlideSchema]
|
slide manifest from slide_etl |
required |
output_urlpath |
str
|
output url/path prefix |
required |
force |
bool
|
overwrite outputs if they exist |
True
|
batch_size |
int
|
size in batch dimension to chuck jobs |
2000
|
storage_options |
dict
|
storage options to reading functions |
{}
|
output_storage_options |
dict
|
storage options to writing functions |
{}
|
Returns:
Type | Description |
---|---|
DataFrame[SlideSchema]
|
DataFrame[SlideSchema]: slide manifest |
Source code in src/luna/pathology/cli/save_tiles.py
slide_etl
¶
SlideBuilder
¶
Source code in src/luna/pathology/cli/slide_etl.py
get_slide(url, project_name='', comment='')
¶
Extract openslide properties and write slide to storage location
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
string
|
path to slide image |
required |
Returns:
Name | Type | Description |
---|---|---|
slide |
Slide
|
slide object |
Source code in src/luna/pathology/cli/slide_etl.py
cli(slide_urlpath='???', project_name='', comment='', subset_csv_urlpath='', debug_limit=0, output_urlpath='', storage_options={}, output_storage_options={}, local_config='', no_copy=False, metadata_extension='parquet')
¶
Ingest slide by adding them to a file or s3 based storage location and generating metadata about them
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_urlpath |
str
|
path to slide image |
'???'
|
project_name |
str
|
project name underwhich the slides should reside |
''
|
comment |
str
|
comment and description of dataset |
''
|
subset_csv_urlpath |
str
|
url/path to subset csv |
''
|
debug_limit |
int
|
limit number of slides |
0
|
output_urlpath |
str
|
url/path to output table |
''
|
storage_options |
dict
|
storage options to pass to reading functions |
{}
|
output_storage_options |
dict
|
storage options to pass to writing functions |
{}
|
local_config |
str
|
url/path to YAML config file |
''
|
no_copy |
bool
|
determines whether we copy slides to output_urlpath |
False
|
metadata_extension(str) |
file extension of generated metadata file (either 'csv' or 'parquet') |
required |
Source code in src/luna/pathology/cli/slide_etl.py
slide_etl(slide_urls, project_name, comment='', storage_options={}, output_urlpath='', output_storage_options={}, no_copy=False)
¶
Ingest slides by adding them to a file or s3 based storage location and generating metadata about them
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_urls |
Union[str, List[str]
|
path to slide image(s) |
required |
project_name |
str
|
project name underwhich the slides should reside |
required |
comment |
str
|
comment and description of dataset |
''
|
storage_options |
dict
|
storage options to pass to reading functions |
{}
|
output_urlpath |
str
|
url/path to output table |
''
|
output_storage_options |
dict
|
storage options to pass to writing functions |
{}
|
no_copy |
bool
|
do not copy slides to output path |
False
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame[SlideSchema]: dataframe containing the metadata of all the slides |
Source code in src/luna/pathology/cli/slide_etl.py
visualize_tile_labels_png
¶
cli(slide_urlpath='???', tiles_urlpath='', mpp_units=False, plot_labels='???', output_urlpath='.', requested_magnification=None, tile_size=None, storage_options={}, output_storage_options={}, local_config='')
¶
Generate nice tile markup images with continuous or discrete tile scores
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_urlpath |
str
|
url/path to slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...) |
'???'
|
tiles_urlpath |
str
|
url/path to a slide-tile manifest file (.tiles.csv) |
''
|
mpp_units |
bool
|
if true, additional rescaling is applied to match micro-meter and pixel coordinate systems |
False
|
plot_labels |
List[str]
|
labels to plot |
'???'
|
output_urlpath |
str
|
output url/path prefix |
'.'
|
requested_magnification |
int
|
Magnification scale at which to perform computation |
None
|
tile_size |
int
|
tile size |
None
|
storage_options |
dict
|
storage options to pass to reading functions |
{}
|
output_storage_options |
dict
|
storage options to pass to writing functions |
{}
|
local_config |
str
|
url/path to local config YAML file |
''
|
Returns:
Name | Type | Description |
---|---|---|
dict |
metadata about function call |
Source code in src/luna/pathology/cli/visualize_tile_labels_png.py
visualize_tiles(slide_urlpath, tiles_urlpath, mpp_units, plot_labels, requested_magnification=None, tile_size=None, storage_options={})
¶
Generate nice tile markup images with continuous or discrete tile scores
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_urlpath |
str
|
url/path to slide image (virtual slide formats compatible with openslide, .svs, .tif, .scn, ...) |
required |
tiles_urlpath |
str
|
url/path to a slide-tile manifest file (.tiles.csv) |
required |
mpp_units |
bool
|
if true, additional rescaling is applied to match micro-meter and pixel coordinate systems |
required |
plot_labels |
List[str]
|
labels to plot |
required |
requested_magnification |
int
|
Magnification scale at which to perform computation |
None
|
tile_size |
int
|
tile size |
None
|
storage_options |
dict
|
storage options to pass to reading functions |
{}
|
Returns:
Type | Description |
---|---|
dict[str,np.ndarray]: score type to numpy array representation of overlayed thumbnail |
Source code in src/luna/pathology/cli/visualize_tile_labels_png.py
common
¶
annotation_utils
¶
check_slideviewer_and_download_bmp(sv_project_id, slideviewer_path, slide_id, users, SLIDE_BMP_DIR, SLIDEVIEWER_API_URL, TMP_ZIP_DIR)
¶
download bitmap annotation from slideviwer
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sv_project_id |
str
|
slideviewer project id |
required |
slideviewer_path |
str
|
filepath to the input slide |
required |
slide_id |
str
|
slide id |
required |
users |
List[str]
|
list of users who provided annotations |
required |
SLIDE_BMP_DIR |
str
|
output folder to save bitmap to |
required |
SLIDEVIEWER_API_URL |
str
|
API url for slide viewer |
required |
Returns:
Type | Description |
---|---|
Union[None, List]
|
Union[None, List]: returns none if there are no annotations to process, or returns a list containing output parameters |
Source code in src/luna/pathology/common/annotation_utils.py
convert_bmp_to_npy(bmp_file, output_folder)
¶
convert bitmap to numpy
Reads a bmp file and creates friendly numpy ndarray file in the uint8 format in the output directory specified, with extention .annot.npy
Troubleshooting
Make sure Pillow is upgraded to version 8.0.0 if getting an Unsupported BMP Size OS Error
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bmp_file |
str
|
path to .bmp image |
required |
output_folder |
str
|
path to output folder |
required |
Returns str: filepath to file containing numpy array
Source code in src/luna/pathology/common/annotation_utils.py
convert_slide_bitmap_to_geojson(outputs, all_labelsets, contour_level, SLIDE_NPY_DIR, slide_store_dir)
¶
convert slide bitmap to geoJSON
Parameters:
Name | Type | Description | Default |
---|---|---|---|
outputs |
List[dict]
|
list of output parameter dict |
required |
all_labelsets |
List[dict]
|
a list of dictionaries containing label sets |
required |
contour_level |
float
|
value along which to find contours |
required |
SLIDE_NPY_DIR |
str
|
directory containing the slide saved as a .npy |
required |
slide_store_dir |
str
|
directory of the datastore |
required |
Returns:
Type | Description |
---|---|
Tuple[str, List]
|
Tuple[str, List]: a pair of slide id and output geojson tables |
Source code in src/luna/pathology/common/annotation_utils.py
get_slide_bitmap(full_filename, user, slide_id, SLIDE_BMP_DIR, SLIDEVIEWER_API_URL, TMP_ZIP_DIR, sv_project_id)
¶
get slide bitmap
Parameters:
Name | Type | Description | Default |
---|---|---|---|
full_filename |
str
|
filename of input slide |
required |
user |
str
|
name of pathologist/annotater who labled the input slide |
required |
SLIDE_BMP_DIR |
str
|
output folder to save bitmap to |
required |
SLIDEVIEWER_API_URL |
str
|
API url for slide viewer |
required |
sv_project_id |
str
|
slide viewer project id |
required |
Returns:
Type | Description |
---|---|
Tuple[str, str]
|
Tuple[str, str]: a tuple of the bitmap record uuid and filepath to saved bitmap |
Source code in src/luna/pathology/common/annotation_utils.py
build_geojson
¶
add_contours_for_label(annotation_geojson, annotation, label_num, mappings, contour_level)
¶
creates geoJSON feature dictionary for labels
Finds the contours for a label mask, builds a polygon and then converts the polygon to geoJSON feature dictionary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotation_geojson |
dict[str, any]
|
geoJSON result to populate |
required |
annotation |
ndarray
|
npy array of bitmap |
required |
label_num |
int
|
the integer cooresponding to the annotated label |
required |
mappings |
dict
|
label map for specified label set |
required |
contour_level |
float
|
value along which to find contours in the array |
required |
Returns:
Type | Description |
---|---|
Dict[str, any]
|
dict[str, any]: geoJSON with label countours |
Source code in src/luna/pathology/common/build_geojson.py
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 |
|
build_all_geojsons_from_default(default_annotation_geojson, all_labelsets, contour_level)
¶
builds geoJSON objects from a set of labels
wraps build_labelset_specific_geojson with logic to generate annotations from multiple labelsets
Parameters:
Name | Type | Description | Default |
---|---|---|---|
default_annotation_geojson |
dict[str, any]
|
input geoJSON |
required |
all_labelsets |
list[dict]
|
a list of dictionaries containing label sets |
required |
contour_level |
float
|
value along which to find contours |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
a dictionary with labelset name and cooresponding geoJSON as key, value |
dict
|
pairs |
Source code in src/luna/pathology/common/build_geojson.py
build_default_geojson_from_annotation(annotation_npy_filepath, all_labelsets, contour_level)
¶
builds geoJSONS from numpy annotation with default label set
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotation_npy_filepath |
str
|
string to numpy annotation |
required |
all_labelsets |
dict
|
a dictionary of label sets |
required |
contour_level |
float
|
value along which to find contours |
required |
Returns:
Type | Description |
---|---|
dict[str, any]: the default geoJSON annotation |
Source code in src/luna/pathology/common/build_geojson.py
build_geojson_from_annotation(df)
¶
Builds geoJSON for all annotation labels in the specified labelset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
input regional annotation table |
required |
Returns:
Name | Type | Description |
---|---|---|
pandasDataFrame |
DataFrame
|
dataframe with geoJSON field poopulated |
Source code in src/luna/pathology/common/build_geojson.py
build_geojson_from_pointclick_json(labelsets, labelset, sv_json)
¶
Build geoJSON m slideviewer JSON
This method extracts point annotations from a slideviwer json object and converts them to a standardized geoJSON format
Parameters:
Name | Type | Description | Default |
---|---|---|---|
labelsets |
dict
|
dictionary of label set as string (e.g. {labelset: {label_number: label_name}}) |
required |
labelset |
str
|
the name of the labelset e.g. default_labels |
required |
sv_json |
list[dict]
|
annotatations from slideviwer in the form of a list of dictionaries |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
a list of geoJSON annotation objects |
Source code in src/luna/pathology/common/build_geojson.py
build_labelset_specific_geojson(default_annotation_geojson, labelset)
¶
builds geoJSON for labelset
Instead of working with a large geJSON object, you can extact polygons that coorspond to specific labels into a smaller object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
default_annotation_geojson |
dict[str, any]
|
geoJSON annotation file |
required |
labelset |
dict
|
label set dictionary |
required |
Returns:
Type | Description |
---|---|
Dict[str, any]
|
dict[str, any]: geoJSON with only polygons from provided labelset |
Source code in src/luna/pathology/common/build_geojson.py
concatenate_regional_geojsons(geojson_list)
¶
concatenate regional annotations
Concatenates geojsons if there are more than one annotations for the labelset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geojson_list |
list[dict[str, any]]
|
list of geoJSON strings |
required |
Returns:
Type | Description |
---|---|
Dict[str, any]
|
dict[str, any]: a single concatenated geoJSON |
Source code in src/luna/pathology/common/build_geojson.py
find_parents(polygons)
¶
determines of parent child relationships of polygons
Returns a list of size n (where n is the number of input polygons in the input list polygons) where the value at index n cooresponds to the nth polygon's parent. In the case of no parent, -1 is used. for example, parent_nums[0] = 2 means that polygon 0's parent is polygon 2
Parameters:
Name | Type | Description | Default |
---|---|---|---|
polygons |
list
|
a list of shapely polygon objects |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
a list of parent-child relationships for the polygon objects |
Source code in src/luna/pathology/common/build_geojson.py
handler(signum, frame)
¶
signal handler for geojson
Parameters:
Name | Type | Description | Default |
---|---|---|---|
signum |
str
|
signal number |
required |
fname |
str
|
filename for which exception occurred |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in src/luna/pathology/common/build_geojson.py
deepzoom
¶
DeepZoomGenerator
¶
Source code in src/luna/pathology/common/deepzoom.py
10 11 12 13 14 15 16 17 18 19 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 198 199 200 201 202 203 204 205 |
|
level_count
property
¶
The number of Deep Zoom levels in the image.
level_dimensions
property
¶
A list of (pixels_x, pixels_y) tuples for each Deep Zoom level.
level_tiles
property
¶
A list of (tiles_x, tiles_y) tuples for each Deep Zoom level.
tile_count
property
¶
The total number of Deep Zoom tiles in the image.
get_tile(level, address)
¶
Return an RGB PIL.Image for a tile.
level: the Deep Zoom level. address: the address of the tile within the level as a (col, row) tuple.
Source code in src/luna/pathology/common/deepzoom.py
schemas
¶
SlideTiles
¶
Source code in src/luna/pathology/common/schemas.py
check(slide_tiles)
classmethod
¶
Returns True if the given path is readable as "SlideTiles
Source code in src/luna/pathology/common/schemas.py
slideviewer_client
¶
Created on January 31, 2021
@author: pashaa@mskcc.org
Functions for downloading annotations from SlideViewer
download_sv_point_annotation(url)
¶
download slideviwer point annotation
Calls slideviewer API with the given url
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
slide viewer api to call |
required |
Returns:
Type | Description |
---|---|
Dict[str, any]
|
dict[str, any]: json response |
Source code in src/luna/pathology/common/slideviewer_client.py
download_zip(url, dest_path, chunk_size=128)
¶
Download zip file
Downloads zip from the specified URL and saves it to the specified file path. see https://stackoverflow.com/questions/9419162/download-returned-zip-file-from-url
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
slideviewer url to download zip from |
required |
dest_path |
str
|
file path where zipfile should be saved |
required |
chunk_size |
int
|
size in bytes of chunks to batch out during download |
128
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if zipfile downloaded and saved successfully, else false |
Source code in src/luna/pathology/common/slideviewer_client.py
fetch_slide_ids(url, project_id, dest_dir, csv_file=None)
¶
get slide ids
Fetch the list of slide ids from the slideviewer server for the project with the specified project id. Alternately, a slideviewer csv file may be provided to override download from server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str or None
|
slideviewer url. url may be None if csv_file is specified. |
required |
project_id |
int
|
slideviewer project id from which to fetch slide ids |
required |
dest_dir |
str
|
directory where csv file should be downloaded |
required |
csv_file |
str
|
slideviewer csv file may be provided to override the need |
None
|
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
list of (slideviewer_path, slide_id, sv_project_id) |
Source code in src/luna/pathology/common/slideviewer_client.py
get_slide_id(full_filename)
¶
get slide id
Get slide id from the slideviewer full file name. The full_filename in the slideview csv is of the format: year;HOBS_ID;slide_id.svs for example: 2013;HobS13-283072057510;1435197.svs
Parameters:
Name | Type | Description | Default |
---|---|---|---|
full_filename |
str
|
full filename of slide |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
numeric slide id |
Source code in src/luna/pathology/common/slideviewer_client.py
unzip(zipfile_path)
¶
unzip zip file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
zipfile_path |
str
|
path of zipfile to unzip |
required |
Returns:
Type | Description |
---|---|
any
|
readfile pointer to unzippped file if successfully unzippped, else None |
Source code in src/luna/pathology/common/slideviewer_client.py
utils
¶
address_to_coord(s)
¶
converts address into coordinates
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s |
str
|
a string consisting of an x_y_z address |
required |
Returns:
Type | Description |
---|---|
Optional[Tuple[int, int]]
|
Tuple[int, int]: a tuple consisting of an x, y pair |
Source code in src/luna/pathology/common/utils.py
convert_halo_xml_to_roi(xml_fn)
¶
get roi from halo XML file
Read the rectangle ROI of a halo XML annotation file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml_fn |
str
|
file path to input halo XML file |
required |
Returns:
Type | Description |
---|---|
Optional[Tuple[List, List]]
|
Tuple[list, list]: returns a tuple of x, y coordinates of the recangular roi |
Source code in src/luna/pathology/common/utils.py
convert_xml_to_mask(xml_urlpath, shape, annotation_name, storage_options={})
¶
convert xml to bitmask
Converts a sparse halo XML annotation file (polygons) to a dense bitmask
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml_urlpath |
str
|
file path to input halo XML file |
required |
shape |
list
|
desired polygon shape |
required |
annotation_name |
str
|
name of annotation |
required |
Returns:
Type | Description |
---|---|
Optional[Tuple[ndarray, Dict[str, Any]]]
|
Optional[Tuple[np.ndarray, Dict[str, Any]]]: annotation bitmask of specified shape |
Source code in src/luna/pathology/common/utils.py
coord_to_address(s, magnification)
¶
converts coordinate to address
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s |
tuple[int, int]
|
coordinate consisting of an (x, y) tuple |
required |
magnification |
int
|
magnification factor |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
a string consisting of an x_y_z address |
Source code in src/luna/pathology/common/utils.py
extract_patch_texture_features(image_patch, mask_patch, stain_vectors, stain_channel, plot=False)
¶
extact patch texture features
Runs patch-wise extraction from an image_patch, mask_patch pair given a stain vector and stain channel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_patch |
ndarray
|
input image patch |
required |
mask_patch |
ndarray
|
input image mask |
required |
stain_vectors |
ndarray
|
stain vectors extacted from the image patch |
required |
stain_channel |
int
|
stain channel |
required |
plot |
(Optional, bool)
|
unused? |
False
|
Returns:
Type | Description |
---|---|
Optional[Dict[str, ndarray]]
|
Optional[Dict[str, np.ndarray]]: texture features from image patch |
Source code in src/luna/pathology/common/utils.py
get_downscaled_thumbnail(slide, scale_factor)
¶
get downscaled thumbnail
yields a thumbnail image of a whole slide rescaled by a specified scale factor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide |
TiffSlide
|
slide object |
required |
scale_factor |
int
|
integer scaling factor to resize the whole slide by |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: downsized whole slie thumbnail |
Source code in src/luna/pathology/common/utils.py
get_full_resolution_generator(slide_urlpath, tile_size, storage_options={})
¶
Return MinimalComputeAperioDZGenerator and generator level
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_urlpath |
str
|
slide urlpath |
required |
Returns:
Type | Description |
---|---|
Tuple[DeepZoomGenerator, int]
|
Tuple[MinimalComputeAperioDZGenerator, int] |
Source code in src/luna/pathology/common/utils.py
get_layer_names(xml_urlpath, storage_options={})
¶
get available layer names
Finds all possible annotation layer names from a Halo generated xml ROI file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml_urlpath |
str
|
absolute or relativefile path to input halo XML file. prefix scheme to use alternative filesystems. |
required |
Returns:
Name | Type | Description |
---|---|---|
set |
Available region names |
Source code in src/luna/pathology/common/utils.py
get_scale_factor_at_magnification(slide, requested_magnification)
¶
get scale factor at magnification
Return a scale factor if slide scanned magnification and requested magnification are different.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide |
TiffSlide
|
slide object |
required |
requested_magnification |
Optional[int]
|
requested magnification |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
float
|
scale factor required to achieve requested magnification |
Source code in src/luna/pathology/common/utils.py
get_stain_vectors_macenko(sample)
¶
get_stain_vectors
Uses the staintools MacenkoStainExtractor to extract stain vectors
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
ndarray
|
input patch |
required |
Returns: np.ndarray: the stain matrix
Source code in src/luna/pathology/common/utils.py
get_tile_array(row, storage_options={})
¶
Returns a tile image as a numpy array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row |
DataFrame
|
row with address and tile_image_file columns |
required |
Source code in src/luna/pathology/common/utils.py
get_tile_arrays(indices, input_slide_urlpath, tile_size, storage_options={})
¶
Get tile arrays for the tile indices
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indices |
List[int]
|
list of integers to return as tiles |
required |
input_slide_image |
str
|
path to WSI |
required |
tile_size |
int
|
width, height of generated tile |
required |
Returns:
Type | Description |
---|---|
List[Tuple[int, ndarray]]
|
a list of tuples (index, tile array) for given indices |
Source code in src/luna/pathology/common/utils.py
get_tile_color(score)
¶
get tile color
uses deafult color palette to return color of tile based on score
Parameters:
Name | Type | Description | Default |
---|---|---|---|
score |
Union[str, float]
|
a value between [0,1] such as the Otsu threshold, puple score, a model output, etc. |
required |
Returns: Union[float, None]: returns the color is the input is of valid type else None
Source code in src/luna/pathology/common/utils.py
pull_stain_channel(patch, vectors, channel=None)
¶
pull stain channel
adds 'stain channel' to the image patch
Parameters:
Name | Type | Description | Default |
---|---|---|---|
patch |
ndarray
|
input image patch |
required |
vectors |
ndarray
|
stain vectors |
required |
channel |
int
|
stain channel |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: the input image patch with an added stain channel |
Source code in src/luna/pathology/common/utils.py
visualize_tiling_scores(df, thumbnail_img, scale_factor, score_type_to_visualize, normalize=True)
¶
visualize tile scores
draws colored boxes around tiles to indicate the value of the score
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
input dataframe |
required |
thumbnail_img |
ndarray
|
input tile |
required |
tile_size |
int
|
tile width/length |
required |
score_type_to_visualize |
str
|
column name from data frame |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: new thumbnail image with boxes around tiles passing indicating the |
ndarray
|
value of the score |
Source code in src/luna/pathology/common/utils.py
dsa
¶
dsa_api_handler
¶
copy_item(gc, item_id, destination_id)
¶
Copies the item to the destination.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gc |
girder_client |
required | |
item_id |
string
|
uuid of the item to be copied |
required |
destination_id |
string
|
uuid of the destination folder |
required |
Source code in src/luna/pathology/dsa/dsa_api_handler.py
create_collection(gc, collection_name)
¶
Creates a dsa collection and returns a collection uuid from the created collection on successful creation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gc |
girder client |
required | |
collection_name |
string
|
name of the collection |
required |
Returns:
Name | Type | Description |
---|---|---|
string |
Optional[str]
|
DSA collection uuid. Or an error in the post request. |
Source code in src/luna/pathology/dsa/dsa_api_handler.py
create_folder(gc, folder_name, parent_type, parent_id)
¶
Creates a dsa folder and returns a folder uuid from the created folder on successful creation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gc |
girder client |
required | |
folder_name |
string
|
name of the folder in DSA |
required |
parent_type |
string
|
type of the parent container (ie. folder, collection) |
required |
parent_id |
string
|
uuid of the parent container |
required |
Returns:
Name | Type | Description |
---|---|---|
string |
Optional[str]
|
DSA folder uuid. Or an error in the post request. |
Source code in src/luna/pathology/dsa/dsa_api_handler.py
create_s3_assetstore(gc, name, bucket, access, secret, service)
¶
Creates a s3 assetstore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gc |
girder client |
required | |
bucket |
string
|
name of the folder in DSA |
required |
access |
string
|
s3 access ID |
required |
secret |
string
|
s3 password |
required |
service |
string)
|
url of the s3 host |
required |
Returns:
Name | Type | Description |
---|---|---|
string |
Optional[str]
|
DSA assetstore uuid. Or an error in the post request. |
Source code in src/luna/pathology/dsa/dsa_api_handler.py
dsa_authenticate(gc, username, password)
¶
Authenticate girder client
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gc |
girder client |
required | |
username |
str
|
DSA username |
required |
password |
str
|
DSA password |
required |
Source code in src/luna/pathology/dsa/dsa_api_handler.py
get_annotation_df(gc, annotation_uuid)
¶
Return annotation metadata (regions) for a given annotation as a dataframe
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gc |
girder client |
required | |
annotation_uuid |
str
|
DSA annotation uuid |
required |
Returns: pd.DataFrame: annotation/region metadata, with slide_item_uuid as additional indicies
Source code in src/luna/pathology/dsa/dsa_api_handler.py
get_assetstore_uuid(gc, assetstore_name)
¶
Returns the DSA assetstore uuid from the provided assetstore_name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gc |
girder client |
required | |
assetstore_name |
string
|
name of the assetstore in DSA |
required |
Returns:
Name | Type | Description |
---|---|---|
string |
Optional[str]
|
DSA assetstore uuid. None if nothing matches the assetstore name or an error in the get request |
Source code in src/luna/pathology/dsa/dsa_api_handler.py
get_collection_metadata(collection_name, gc)
¶
A function used to get the stylehseet associated with a DSA collection. The stylesheet can store the labels used in the annotation process
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name |
str
|
name of DSA collection used to store the slides |
required |
gc |
girder client |
required |
Returns: Optional[Tuple[str, Dict[str, any]]]: a tuple consisting of the collection uuid and thei stylesheet in JSON format or None if no stylesheet is associated with the provided collection
Source code in src/luna/pathology/dsa/dsa_api_handler.py
get_collection_uuid(gc, collection_name)
¶
Returns the DSA collection uuid from the provided collection_name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gc |
girder client |
required | |
collection_name |
string
|
name of the collection in DSA |
required |
Returns:
Name | Type | Description |
---|---|---|
string |
Optional[str]
|
DSA collection uuid. None if nothing matches the collection name or an error in the get request |
Source code in src/luna/pathology/dsa/dsa_api_handler.py
get_folder_uuid(gc, folder_name, parent_type, parent_id)
¶
Returns the DSA folder uuid from the provided folder_name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gc |
girder client |
required | |
folder_name |
string
|
name of the folder in DSA |
required |
parent_type |
string
|
type of the parent container (ie. folder, collection) |
required |
parent_id |
string
|
uuid of the parent container |
required |
Returns:
Name | Type | Description |
---|---|---|
string |
Optional[str]
|
DSA folder uuid. None if nothing matches the collection name or an error in the get request |
Source code in src/luna/pathology/dsa/dsa_api_handler.py
get_item_uuid(gc, image_name, collection_name)
¶
Returns the DSA item uuid from the provided image_name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_name |
string
|
name of the image in DSA e.g. 123.svs |
required |
collection_name |
str
|
name of DSA collection |
required |
gc |
girder client |
required |
Returns:
Name | Type | Description |
---|---|---|
string |
Optional[str]
|
DSA item uuid. None if nothing matches the collection/image name. |
Source code in src/luna/pathology/dsa/dsa_api_handler.py
get_item_uuid_by_folder(gc, image_name, folder_uuid)
¶
Returns the DSA item uuid from the provided folder
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gc |
girder client |
required | |
image_name |
string
|
name of the image in DSA e.g. 123.svs |
required |
folder_uuid |
string
|
uuid of parent DSA folder |
required |
Returns:
Name | Type | Description |
---|---|---|
string |
Optional[str]
|
DSA item uuid. None if nothing matches the folder uuid / image name. |
Source code in src/luna/pathology/dsa/dsa_api_handler.py
get_slide_annotation(slide_id, annotation_name, collection_name, gc)
¶
A helper function that pulls json annotations along with metadata for a particular slide from DSA. Used for both point and regional annotation types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_id |
str
|
image name of WSI on DSA. |
required |
annotation_name |
str
|
name of annotation, or label, created on DSA |
required |
collection_name |
str
|
name of DSA collection the WSI belongs to |
required |
gc |
girder client |
required |
Returns:
Type | Description |
---|---|
Optional[Tuple[str, Dict[str, any], Dict[str, any]]]
|
Optional[Tuple[str, dict[str, any], dict[str, any]. A tuple consisting of the slide id, a json formatted annotation from slideviweer and slide metadata or None if the annotation can't be found (ie if image_id, annotation_name or collection_name are mis-specified) |
Source code in src/luna/pathology/dsa/dsa_api_handler.py
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 |
|
get_slide_df(gc, collection_uuid)
¶
Return slide metadata (largeImage items) for a given colleciton as a dataframe
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gc |
girder client |
required | |
collection_uuid |
str
|
DSA collection uuid |
required |
Returns: pd.DataFrame: slide metadata, with slide_id and slide_item_uuid as additional indicies
Source code in src/luna/pathology/dsa/dsa_api_handler.py
import_assetstore_to_folder(gc, assetstore_uuid, destination_uuid)
¶
Imports the assetstore to the specified destination folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gc |
girder client |
required | |
assetstore_uuid |
string
|
uuid of the assetstore |
required |
destination_uuid |
string
|
uuid of the destination folder |
required |
Returns:
Type | Description |
---|---|
Optional[str]
|
None, raises error if post request fails |
Source code in src/luna/pathology/dsa/dsa_api_handler.py
push_annotation_to_dsa_image(item_uuid, annotation_file_urlpath, uri, gc, storage_options={})
¶
Pushes annotation to DSA, adding given item_uuid (slide-specific id)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item_uuid |
str
|
DSA item uuid to be tied to the annotation |
required |
dsa_annotation_json |
Dict[str, any]
|
annotation JSON in DSA compatable format |
required |
uri |
str
|
DSA scheme://host:port e.g. http://localhost:8080 |
required |
gc |
GirderClient
|
girder client |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
0 for successful upload, 1 otherwise |
Source code in src/luna/pathology/dsa/dsa_api_handler.py
system_check(gc)
¶
Check DSA connection with the girder client
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gc |
girder client |
required |
Returns: int: 0 for successful connection, 1 otherwise
Source code in src/luna/pathology/dsa/dsa_api_handler.py
utils
¶
get_color(name, line_colors={}, fill_colors={}, alpha=100)
¶
Get colors for cells/regions based on discrete categories.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
string
|
feature name e.g. Stroma, Tumor |
required |
line_colors |
dict
|
line color map with {feature name:rgb values} |
{}
|
fill_colors |
dict
|
fill color map with {feature name:rgba values} |
{}
|
alpha |
int
|
alpha value for the fill color. 100 by default |
100
|
Returns:
Name | Type | Description |
---|---|---|
string |
RGBA values for line and fill colors |
Source code in src/luna/pathology/dsa/utils.py
get_continuous_color(value, outline_color='same_as_fill', alpha=100)
¶
Get RGBA line and fill colors for value.
Use color palette viridis
to set a fill value - the color ranges from purple to yellow,
for the values from 0 to 1. This function is used in generating a heatmap.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
float
|
continuous value in [0,1] |
required |
outline_color |
string
|
manages the color used to outline the border of the annotation. by default, uses the same color as fill_color. |
'same_as_fill'
|
alpha |
int
|
alpha value for the fill color. 100 by default |
100
|
Returns:
Name | Type | Description |
---|---|---|
string |
Tuple[str, str]
|
RGBA line and fill colors |
Source code in src/luna/pathology/dsa/utils.py
vectorize_np_array_bitmask_by_pixel_value(bitmask_np, label_num=255, polygon_tolerance=1, contour_level=0.5, scale_factor=1)
¶
Get simplified contours from the bitmask
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bitmask_np |
array
|
a numpy bitmask |
required |
label_num |
int
|
numeric value to filter the numpy array |
255
|
polygon_tolerance |
float
|
Maximum distance from original points of polygon to approximated polygonal chain. If tolerance is 0, the original coordinate array is returned. |
1
|
contour_level |
float
|
Value along which to find contours in the array. 0.5 by default |
0.5
|
scale_factor |
int
|
scale to match image. default 1 |
1
|
Returns:
Name | Type | Description |
---|---|---|
list |
simplified approximated contours |
Source code in src/luna/pathology/dsa/utils.py
slideviewer
¶
regional_annotation
¶
dask_generate
¶
cli(data_config_file, app_config_file)
¶
This module generates parquets with regional annotation pathology data
INPUT PARAMETERS
app_config_file - path to yaml file containing application runtime parameters. See config.yaml.template
data_config_file - path to yaml file containing data input and output parameters. See dask_data_config.yaml.template
TABLE SCHEMA
-
sv_project_id: project number in slide viewer
-
slideviewer_path: slide path based on slideviewer organization
-
slide_id: slide id. synonymous with image_id
-
user: username of the annotator for a given annotation. For all slides, we combine multiple annotations from different users for a slide. In this case, user is set to 'CONCAT' and bmp_filepath, npy_filepath are null.
-
bmp_filepath: file path to downloaded bmp annotation file
-
npy_filepath: file path to npy annotation file converted from bmp
-
geojson_path: file path to geojson file converted from numpy
-
date: creation date
-
labelset:
Source code in src/luna/pathology/slideviewer/regional_annotation/dask_generate.py
create_geojson_table()
¶
Vectorizes npy array annotation file into polygons and builds GeoJson with the polygon features. Creates a geojson file per labelset. Combines multiple annotations from different users for a slide.
Returns:
Name | Type | Description |
---|---|---|
list |
list of slide ids that failed |
Source code in src/luna/pathology/slideviewer/regional_annotation/dask_generate.py
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 |
|
spatial
¶
stats
¶
Kfunction(p1XY, p2XY, radius, ls=False, count=True, intensity=[], distance=False, distance_scale=10.0)
¶
Computes the Counting, Intensity, and experimental Intensity-Distance K functions
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p1XY |
ndarray
|
An Nx2 array representing the (X,Y) coordinates of cells with phenotype 1 |
required |
p2XY |
ndarray
|
Same as p1XY but for phenotype 2 cells |
required |
radius |
(float, list[float])
|
The radius (or list of radii) to consider |
required |
ls |
bool
|
If True, returns an |radius|x|p1XY| 2D array representing the K function for each phenotype 1 cell for each radius. If False, returns the mean for each radius |
False
|
count |
bool
|
By default, this function only computes the Counting K function. Can be disabled with count=False. |
True
|
intensity |
ndarray
|
An array of length |p2XY| representing the intensity of each phenotype 2 cell. When passed in, this method will also compute the Intensity K function |
[]
|
distance (bool): If an intensity array is passed in, then setting distance=True
will compute the experimental Intensity-Distance K function
distance_scale (float): Characteristic distance scale (usually approx. 1 cell length in the given units)
Returns:
dict: a dictionary with keys ["count", "intensity", "distance"] and values corresponding to the result of each K function
Source code in src/luna/pathology/spatial/stats.py
transforms
¶
Higher-level transformation functions
generate_k_function_statistics(cell_paths, method_data, main_index=None)
¶
Compute K-function spatial statistics on given cell-data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cell_paths |
str or list[str]
|
paths to a single or multiple FOV regions |
required |
method_data |
dict
|
Configuration: "index": (str, optional) Column containting the patient/desired ID, if available (overrides main_index) "phenotype1" : { "name" : (str) Column name to query 'value' : (str) Phenotype string to match (e.g. CD68) }, "phenotype2" : { "name" : (str) Column name to query 'value' : (str) Phenotype string to match (e.g. panCK) }, "count" : (bool) Flag to compute counting stats. "radius" : (float) Radius cutoff "intensity" : (str, optional) Column containing intensity information "distance" : (bool) Flag to compute intensity-distance stats. |
required |
Returns:
Type | Description |
---|---|
pd.DataFrame: spatial statistics aggregated over FOVs |
Source code in src/luna/pathology/spatial/transforms.py
12 13 14 15 16 17 18 19 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 |
|