Skip to content

Commit

Permalink
pre-commit test2
Browse files Browse the repository at this point in the history
  • Loading branch information
tdefa committed Jun 5, 2024
1 parent 553a740 commit 60d4da9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/tutorials/cli_other_segmentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
```
28 changes: 18 additions & 10 deletions sopa/cli/patchify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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)))

Expand Down
2 changes: 1 addition & 1 deletion sopa/cli/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,5 @@ def comseg(
gene_column,
patches_dirs,
min_area,
shapes_key=SopaKeys.COMSEG_BOUNDARIES
shapes_key=SopaKeys.COMSEG_BOUNDARIES,
)
9 changes: 6 additions & 3 deletions sopa/cli/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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

Expand Down

0 comments on commit 60d4da9

Please sign in to comment.