pyluna-pathology.luna.pathology.cli.dsa package
Contents
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_metadata(collection_name: str, gc) Optional[Tuple[str, Dict[str, any]]][source]¶
A function used to get the stylehseet associated with a DSA collection. The stylesheet can store the labels used in the annotation process
- Parameters
collection_name (str) – name of DSA collection used to store the slides
gc – girder client
- Returns
- a tuple consisting of the collection uuid
and thei stylesheet in JSON format or None if no stylesheet is associated with the provided collection
- Return type
Optional[Tuple[str, Dict[str, any]]]
- luna.pathology.cli.dsa.dsa_api_handler.get_collection_uuid(gc, collection_name: str) Optional[str][source]¶
Returns the DSA collection uuid from the provided collection_name
- Parameters
gc – girder client
collection_name (string) – name of the collection in DSA
- Returns
- DSA collection uuid. None if nothing matches the collection name or an
error in the get request
- Return type
string
- luna.pathology.cli.dsa.dsa_api_handler.get_item_uuid(image_name: str, collection_name: str, gc) Optional[str][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
collection_name (str) – name of DSA collection
gc – girder client
- Returns
DSA item uuid. None if nothing matches the collection/image name.
- Return type
string
- luna.pathology.cli.dsa.dsa_api_handler.get_slide_annotation(slide_id: str, annotation_name: str, collection_name: str, gc) Optional[Tuple[str, Dict[str, any], Dict[str, any]]][source]¶
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
slide_id (str) – id of WSI on DSA (filename without extension).
annotation_name (str) – name of annotation, or label, created on DSA
collection_name (str) – name of DSA collection the WSI belongs to
gc – girder client
- Returns
- 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)
- luna.pathology.cli.dsa.dsa_api_handler.get_slides_from_collection(collection_uuid: str, gc) Optional[List[str]][source]¶
A helper function that retrieves all slide names from a provided collection via accessing DSA resource tree
- Parameters
collection_uuid (str) – DSA collection uuid
gc – girder client
- Returns
a list of all slide file names belonging to the collection
- Return type
List[str]
- luna.pathology.cli.dsa.dsa_api_handler.push_annotation_to_dsa_image(item_uuid: str, dsa_annotation_json: Dict[str, any], uri: str, gc)[source]¶
Pushes annotation to DSA, adding given item_uuid (slide-specific id)
- Parameters
item_uuid (str) – DSA item uuid to be tied to the annotation
dsa_annotation_json (Dict[str, any]) – annotation JSON in DSA compatable format
uri (str) – DSA host:port e.g. localhost:8080
gc – girder client
- Returns
0 for successful upload, 1 otherwise
- Return type
int
pyluna-pathology.luna.pathology.cli.dsa.dsa_upload module¶
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