Skip to content

run_stardist_cell_detection

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
def stardist_simple(
    slide_manifest: DataFrame[SlideSchema],
    cell_expansion_size: float,
    image_type: str,
    output_urlpath: str,
    debug_opts: str,
    num_cores: int,
    image: str,
    use_singularity: bool,
    max_heap_size: str,
    storage_options: dict,
    output_storage_options: dict,
    annotation_column: str = "stardist_geojson_url",
) -> DataFrame[SlideSchema]:
    """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.

    Args:
        slide_manifest (DataFrame[SlideSchema]): slide manifest from slide_etl
        cell_expansion_size (float): size in pixels to expand cell cytoplasm
        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
        num_cores (int): Number of cores to use for CPU parallelization
        image (str): docker/singularity image
        use_singularity (bool): use singularity instead of docker
        max_heap_size (str): maximum heap size to pass to java options
        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

    Returns:
        DataFrame[SlideSchema]: slide manifest
    """

    client = get_or_create_dask_client()

    futures = []
    for row in slide_manifest.itertuples(name="Slide"):
        future = client.submit(
            __stardist_simple,
            row.url,
            cell_expansion_size,
            image_type,
            output_urlpath,
            debug_opts,
            num_cores,
            image,
            use_singularity,
            max_heap_size,
            storage_options,
            output_storage_options,
        )
        futures.append(future)
    results = client.gather(futures)
    return slide_manifest.assign(
        **{annotation_column: [x["geojson_url"] for x in results]}
    )

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
def stardist_cell_lymphocyte(
    slide_manifest: DataFrame[SlideSchema],
    output_urlpath: str,
    num_cores: int,
    use_gpu: bool = False,
    image: str = "mskmind/qupath-stardist:0.4.3",
    use_singularity: bool = False,
    max_heap_size: str = "64G",
    storage_options: dict = {},
    output_storage_options: dict = {},
    annotation_column: str = "lymphocyte_geojson_url",
) -> DataFrame[SlideSchema]:
    """Run stardist using qupath CLI

    Args:
        slide_manifest (DataFrame[SlideSchema]): slide manifest from slide_etl
        output_urlpath (str): output url/path
        num_cores (int): Number of cores to use for CPU parallelization
        use_gpu (bool): use GPU
        image (str): docker/singularity image
        use_singularity (bool): use singularity instead of docker
        max_heap_size (str): maximum heap size to pass to java options
        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

    Returns:
        DataFrame[SlideSchema]: slide manifest
    """
    client = get_or_create_dask_client()

    futures = []
    for row in slide_manifest.itertuples(name="Slide"):
        fs, output_path = fsspec.core.url_to_fs(
            output_urlpath, **output_storage_options
        )
        future = client.submit(
            __stardist_cell_lymphocyte,
            row.url,
            fs.unstrip_protocol(str(Path(output_path) / row.id)),
            row.id,
            num_cores,
            use_gpu,
            image,
            use_singularity,
            max_heap_size,
            storage_options,
            output_storage_options,
        )
        futures.append(future)
    results = client.gather(futures)
    return slide_manifest.assign(
        **{annotation_column: [x["geojson_url"] for x in results]}
    )