pyluna-pathology.luna.pathology.cli.dsa package¶
Submodules¶
pyluna-pathology.luna.pathology.cli.dsa.dsa_api_handler module¶
- luna.pathology.cli.dsa.dsa_api_handler.get_collection_uuid(uri, token, collection_name)[source]¶
Returns the DSA collection uuid from the provided collection_name
- Parameters
uri (string) – DSA host:port e.g. localhost:8080
token (string) – DSA token from /token/current HistomicsUI API
collection_name (string) – name of the collection in DSA
- Returns
DSA collection uuid. None if nothing matches the collection name.
- Return type
string
- luna.pathology.cli.dsa.dsa_api_handler.get_item_uuid(image_name, uri, token, collection_name)[source]¶
Returns the DSA item uuid from the provided image_name
- Parameters
image_name (string) – name of the image in DSA e.g. 123.svs
uri (string) – DSA host:port e.g. localhost:8080
token (string) – DSA token from /token/current HistomicsUI API
collection_name (string) – name of the collection in DSA
- Returns
DSA item uuid. None if nothing matches the collection/image name.
- Return type
string
- luna.pathology.cli.dsa.dsa_api_handler.push_annotation_to_dsa_image(item_uuid, dsa_annotation_json, uri, token)[source]¶
Pushes annotation to DSA, adding given item_uuid (slide-specific id)
- Parameters
item_uuid (string) – DSA item uuid to be tied to the annotation
dsa_annotation_json (string) –
uri (string) – DSA host:port e.g. localhost:8080
token (string) – DSA token from /token/current HistomicsUI API
- Returns
0 for successful upload, 1 otherwise
- Return type
int
- luna.pathology.cli.dsa.dsa_api_handler.system_check(uri, token)[source]¶
Check DSA connection with the given host/token
- Parameters
uri (string) – DSA host:port e.g. localhost:8080
token (string) – DSA token from /token/current HistomicsUI API
- Returns
0 for successful connection, 1 otherwise
- Return type
int
pyluna-pathology.luna.pathology.cli.dsa.dsa_upload module¶
- luna.pathology.cli.dsa.dsa_upload.upload_annotation_to_dsa(annotation_filepath, image_filename, collection_name, uri, token)[source]¶
Upload annotation to DSA
Upload json annotation file as a new annotation to the image in the DSA collection.
- Parameters
annotation_filepath (string) – path to a DSA compatible annotation json file
image_filename (string) – name of the image file in DSA e.g. 123.svs
collection_name (string) – name of the collection in DSA
uri (string) – DSA host:port e.g. localhost:8080
token (string) – DSA token from /token/current HistomicsUI API
- Returns
None
pyluna-pathology.luna.pathology.cli.dsa.dsa_viz module¶
- luna.pathology.cli.dsa.dsa_viz.bitmask_polygon(data_config)[source]¶
Build DSA annotation json from bitmask PNGs
Vectorizes and simplifies contours from the bitmask.
- Parameters
data_config (string) – path to your data config file that includes input/output parameters.
input (map) – map of {label:path_to_bitmask_png}
output_folder (string) – directory where the DSA compatible annotation json file will be saved
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 (map, optional) – line color map with {feature name:rgb values}
fill_colors (map, optional) – fill color map with {feature name:rgba values}
- Returns
annotation file path. None if error in writing the file.
- Return type
string
- luna.pathology.cli.dsa.dsa_viz.check_filepaths_valid(filepaths)[source]¶
Checks if all paths exist.
- Parameters
filepaths (list) – file paths
- Returns
True if all file paths exist, False otherwise
- Return type
bool
- luna.pathology.cli.dsa.dsa_viz.heatmap(data_config)[source]¶
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
data_config (string) – path to your data config file that includes input/output parameters.
input (string) – path to CSV with tile scores
output_folder (string) – directory where the DSA compatible annotation json file will be saved
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, optional) – scale to match the image on DSA. By default, 1.
- Returns
annotation file path. None if error in writing the file.
- Return type
string
- luna.pathology.cli.dsa.dsa_viz.qupath_polygon(data_config)[source]¶
Build DSA annotation json from Qupath polygon geojson
- Parameters
data_config (string) – path to your data config file that includes input/output parameters.
input (string) – path to Qupath polygon geojson
output_folder (string) – directory where the DSA compatible annotation json file will be saved
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 e.g. [“Tumor”, “Stroma”, …]
line_colors (map, optional) – line color map with {feature name:rgb values}
fill_colors (map, optional) – fill color map with {feature name:rgba values}
- Returns
annotation file path. None if error in writing the file.
- Return type
string
- luna.pathology.cli.dsa.dsa_viz.regional_polygon(data_config)[source]¶
Build DSA annotation json from regional annotation geojson
- Parameters
data_config (string) – path to your data config file that includes input/output parameters.
input (string) – path to regional annotation geojson
output_folder (string) – directory where the DSA compatible annotation json file will be saved
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 (map, optional) – line color map with {feature name:rgb values}
fill_colors (map, optional) – fill color map with {feature name:rgba values}
- Returns
annotation file path. None if error in writing the file.
- Return type
string
- luna.pathology.cli.dsa.dsa_viz.save_dsa_annotation(base_annotation, elements, annotation_name, output_folder, image_filename)[source]¶
Helper function to save annotation elements to a json file.
- Parameters
base_annotation (dict) – base annotation structure for DSA
elements (list) – list of annotation elements
annotation_name (string) – annotation name for HistomicsUI
output_folder (string) – path to a directory to save the annotation file
image_filename (string) – name of the image in DSA e.g. 123.svs
- Returns
annotation file path. None if error in writing the file.
- Return type
string
- luna.pathology.cli.dsa.dsa_viz.stardist_cell(data_config)[source]¶
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
data_config (string) – path to your data config file that includes input/output parameters.
input (string) – path to TSV classification data generated by stardist
output_folder (string) – directory where the DSA compatible annotation json file will be saved
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 (map, optional) – line color map with {feature name:rgb values}
fill_colors (map, optional) – fill color map with {feature name:rgba values}
- Returns
annotation file path. None if error in writing the file.
- Return type
string
- luna.pathology.cli.dsa.dsa_viz.stardist_polygon(data_config)[source]¶
Build DSA annotation json from stardist geojson classification results
- Parameters
data_config (string) – path to your data config file that includes input/output parameters.
input (string) – path to stardist geojson classification results
output_folder (string) – directory where the DSA compatible annotation json file will be saved
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 (map, optional) – user-provided line color map with {feature name:rgb values}
fill_colors (map, optional) – user-provided fill color map with {feature name:rgba values}
- Returns
annotation file path. None if error in writing the file.
- Return type
string
pyluna-pathology.luna.pathology.cli.dsa.utils module¶
- luna.pathology.cli.dsa.utils.get_color(name, line_colors={}, fill_colors={}, alpha=100)[source]¶
Get colors for cells/regions based on discrete categories.
- Parameters
name (string) – feature name e.g. Stroma, Tumor
line_colors (dict, optional) – line color map with {feature name:rgb values}
fill_colors (dict, optional) – fill color map with {feature name:rgba values}
alpha (int, optional) – alpha value for the fill color. 100 by default
- Returns
RGBA values for line and fill colors
- Return type
string
- luna.pathology.cli.dsa.utils.get_continuous_color(value, outline_color='same_as_fill', alpha=100)[source]¶
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
value (float) – continuous value in [0,1]
outline_color (string, optional) – manages the color used to outline the border of the annotation. by default, uses the same color as fill_color.
alpha (int, optional) – alpha value for the fill color. 100 by default
- Returns
RGBA line and fill colors
- Return type
string
- luna.pathology.cli.dsa.utils.vectorize_np_array_bitmask_by_pixel_value(bitmask_np, label_num=255, polygon_tolerance=1, contour_level=0.5)[source]¶
Get simplified contours from the bitmask
- Parameters
bitmask_np (np.array) – a numpy bitmask
label_num (int, optional) – numeric value to filter the numpy array
polygon_tolerance (float, optional) – Maximum distance from original points of polygon to approximated polygonal chain. If tolerance is 0, the original coordinate array is returned.
contour_level (float, optional) – Value along which to find contours in the array. 0.5 by default
- Returns
simplified approximated contours
- Return type
list