Skip to content

Commit ae28a04

Browse files
committed
added force, delete_cache, and recover to baysor cli interface
1 parent 5d39d00 commit ae28a04

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

cholab-prep/example_xenium-multichannel-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ segmentation:
3939
min_area: 30 # [optional] minimum area (in microns^2) for a cell to not be filtered
4040
prior_shapes_key: cell_id # [optional] if prior segmentation has been performed, this is the column in the transcript dataframe that indicated the cell that contains the transcript. This doesn't need to be provided if you run cellpose with Sopa.
4141
unassigned_value: UNASSIGNED # [optional] if prior segmentation has been performed and if 'cell_key' above is provided, this is the value given to transcript that is not contained inside any cell
42+
force: true # [optional] if True, ignore failed patches and continue with the successful ones
43+
delete_cache: true # [optional] whether to delete the cache after segmentation
44+
recover: false # [optional] if True, recover the cache from a failed segmentation, and continue
4245
config: # [this is the baysor config, as in https://github.com/kharchenkolab/Baysor]
4346
data:
4447
exclude_genes: "NegControl*,BLANK_*,antisense_*,Blank*" # genes excluded from the Baysor segmentation

sopa/cli/segmentation.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ def _run_staining_segmentation(
157157
**method_kwargs: int,
158158
):
159159
from sopa.io.standardize import read_zarr_standardized
160-
from sopa.segmentation import StainingSegmentation, custom_staining_based, methods
160+
from sopa.segmentation import (
161+
StainingSegmentation,
162+
custom_staining_based,
163+
methods,
164+
)
161165

162166
from .utils import _default_boundary_dir
163167

@@ -242,6 +246,9 @@ def baysor(
242246
),
243247
min_area: float = typer.Option(default=0, help="Minimum area (in micron^2) for a cell to be considered as valid"),
244248
scale: float = typer.Option(default=None, help="Baysor scale parameter (for config inference)"),
249+
force: bool = typer.Option(default=False, help="If True, ignore failed patches and continue with the successful ones."),
250+
delete_cache: bool = typer.Option(default=True, help="Whether to delete the cache after segmentation."),
251+
recover: bool = typer.Option(default=False, help="If True, recover the cache from a failed segmentation, and continue."),
245252
):
246253
"""Perform Baysor segmentation. This can be done on all patches directly, or on one individual patch."""
247254
import sys
@@ -253,7 +260,8 @@ def baysor(
253260
sdata = read_zarr_standardized(sdata_path)
254261

255262
try:
256-
baysor(sdata, config=config, min_area=min_area, patch_index=patch_index, scale=scale)
263+
baysor(sdata, config=config, min_area=min_area, patch_index=patch_index, scale=scale,
264+
force=force, delete_cache=delete_cache, recover=recover)
257265
except CalledProcessError as e:
258266
sys.exit(e.returncode)
259267

workflow/Snakefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ rule patch_segmentation_baysor:
125125
threads: 8
126126
params:
127127
baysor_config = args["segmentation"]["baysor"].as_cli(keys=["config"]),
128+
baysor_params = args["segmentation"]["baysor"].as_cli(keys=["force", "delete_cache", "recover"]),
128129
sdata_path = paths.sdata_path,
129130
resources:
130131
cpus_per_task=8,
@@ -137,7 +138,7 @@ rule patch_segmentation_baysor:
137138
module purge
138139
fi
139140
140-
sopa segmentation baysor {params.sdata_path} --patch-index {wildcards.index} {params.baysor_config}
141+
sopa segmentation baysor {params.sdata_path} --patch-index {wildcards.index} {params.baysor_config} {params.baysor_params}
141142
"""
142143

143144
rule patch_segmentation_comseg:

0 commit comments

Comments
 (0)