diff --git a/docs/tutorials/cli_other_segmentation.md b/docs/tutorials/cli_other_segmentation.md index 0d37a25f..3cb62624 100644 --- a/docs/tutorials/cli_other_segmentation.md +++ b/docs/tutorials/cli_other_segmentation.md @@ -73,4 +73,4 @@ sopa patchify comseg tuto.zarr --config-path config.json --patch-width-microns 2 3) Merge the results ```sh sopa resolve comseg tuto.zarr --gene-column genes -``` \ No newline at end of file +``` diff --git a/sopa/cli/patchify.py b/sopa/cli/patchify.py index e550adba..11ca3aed 100644 --- a/sopa/cli/patchify.py +++ b/sopa/cli/patchify.py @@ -70,7 +70,7 @@ def baysor( False, help="Whether to use cellpose segmentation as a prior for baysor (if True, make sure to first run Cellpose)", ), - ): +): """Prepare patches for transcript-based segmentation with baysor""" return transcript_segmentation( sdata_path=sdata_path, @@ -85,10 +85,17 @@ def baysor( use_prior = use_prior, ) - return transcript_segmentation(sdata_path = sdata_path, method = 'baysor', patch_width_microns = patch_width_microns, - patch_overlap_microns = patch_overlap_microns, temp_dir = baysor_temp_dir, - config_path = config_path, config = config, cell_key = cell_key, - unassigned_value = unassigned_value, use_prior = use_prior) + return transcript_segmentation( + sdata_path = sdata_path, + method = 'baysor', + patch_width_microns = patch_width_microns, + patch_overlap_microns = patch_overlap_microns, + temp_dir = baysor_temp_dir, + config_path = config_path, + config = config, + cell_key = cell_key, + unassigned_value = unassigned_value, + use_prior = use_prior) @app_patchify.command() def comseg( @@ -131,14 +138,15 @@ def comseg( config_path = config_path, config = config, cell_key = cell_key, unassigned_value = unassigned_value, - use_prior = True) + use_prior = True + ) @app_patchify.command() def transcript_segmentation( sdata_path: str = typer.Argument(help=SDATA_HELPER), method: str = typer.Option( "baysor", help="Name of the method to use, choose in ['baysor', 'comseg']. for ComSeg, make sure to first run Cellpose or " - f"manually add the segmentation boundaries to the sdata.shapes as {SopaKeys.CELLPOSE_BOUNDARIES} key" + f"manually add the segmentation boundaries to the sdata.shapes as {SopaKeys.CELLPOSE_BOUNDARIES} key", ), patch_width_microns: float = typer.Option(help="Width (and height) of each patch in microns"), patch_overlap_microns: float = typer.Option( @@ -187,14 +195,14 @@ def transcript_segmentation( assert ( config or config_path is not None ), "Provide '--config-path', the path to a Baysor config file (toml) or comseg file (jsons)" - assert method in ['baysor', 'comseg'], "method must be either 'baysor' or 'comseg'" + assert method in ["baysor", "comseg"], "method must be either 'baysor' or 'comseg'" if temp_dir is None: if method == "baysor": temp_dir = _default_boundary_dir(sdata_path, SopaKeys.BAYSOR_BOUNDARIES) filename = SopaFiles.PATCHES_DIRS_BAYSOR config_name = SopaFiles.TOML_CONFIG_FILE - elif method == 'comseg': + elif method == "comseg": temp_dir = _default_boundary_dir(sdata_path, SopaKeys.COMSEG_BOUNDARIES) filename = SopaFiles.PATCHES_DIRS_COMSEG config_name = SopaFiles.JSON_CONFIG_FILE @@ -215,7 +223,7 @@ def transcript_segmentation( use_prior, config, config_path, - config_name=config_name + config_name=config_name, ) _save_cache(sdata_path, filename, "\n".join(map(str, valid_indices))) diff --git a/sopa/cli/resolve.py b/sopa/cli/resolve.py index be6a43e8..e3fbedf9 100644 --- a/sopa/cli/resolve.py +++ b/sopa/cli/resolve.py @@ -133,5 +133,5 @@ def comseg( gene_column, patches_dirs, min_area, - shapes_key=SopaKeys.COMSEG_BOUNDARIES + shapes_key=SopaKeys.COMSEG_BOUNDARIES, ) diff --git a/sopa/cli/segmentation.py b/sopa/cli/segmentation.py index a781974f..08c2e524 100644 --- a/sopa/cli/segmentation.py +++ b/sopa/cli/segmentation.py @@ -4,15 +4,16 @@ import logging from pathlib import Path - import typer from tqdm import tqdm from .utils import SDATA_HELPER + app_segmentation = typer.Typer() log = logging.getLogger(__name__) + @app_segmentation.command() def cellpose( sdata_path: str = typer.Argument(help=SDATA_HELPER), @@ -181,6 +182,7 @@ def _run_staining_segmentation( else: segmentation.write_patch_cells(patch_dir, patch_index) + @app_segmentation.command() def comseg( sdata_path: str = typer.Argument(help=SDATA_HELPER), @@ -194,10 +196,11 @@ def comseg( ), ): """Perform ComSeg segmentation. This can be done on all patches directly, or on one individual patch.""" - from .utils import _default_boundary_dir + import json from sopa._constants import SopaFiles, SopaKeys from sopa.segmentation.methods import comseg_patch - import json + from .utils import _default_boundary_dir + config_name = SopaFiles.JSON_CONFIG_FILE