Skip to content

Commit 87a467e

Browse files
committed
feat(workflow): ✨ wire dilate_labels into build_fn via cfg["dilate"]
Applies to every method (cellpose/threshold/custom) uniformly, since build_fn wraps its single return point rather than each branch. Adds a commented-out dilate: N example to both config.yaml and config_cilia.yaml.
1 parent 62b2cbb commit 87a467e

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

workflow/config/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ empty_threshold: null # null → Otsu; or a number
3030

3131
# ---- segmentation -----------------------------------------------------------
3232
method: "cellpose" # "cellpose" (GPU), "threshold" (no GPU; testing), "custom"
33+
# dilate: 2 # optional: pixels to grow labels by after segmentation, any method
3334
# Also namespaces this run's intermediate files under work_dir/<label_name>/,
3435
# so a second segmentation (different label_name, e.g. nuclei vs cytoplasm)
3536
# can safely target the same work_dir — see docs/guide/snakemake.md

workflow/config/config_cilia.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ skip_empty: true
2525
empty_threshold: null
2626

2727
method: "custom"
28+
# dilate: 2 # optional: pixels to grow labels by after segmentation
2829
label_name: "cilia_labels"
2930
custom:
3031
module: "patchworks.plugins.dog"

workflow/scripts/_pw.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,34 @@ def build_fn(cfg):
133133
cfg : dict
134134
Snakemake config. ``method`` selects ``"cellpose"`` (default), a simple
135135
``"threshold"`` (testing / no-GPU), or ``"custom"`` to import your own
136-
function (``cfg["custom"] = {module, function, kwargs}``).
136+
function (``cfg["custom"] = {module, function, kwargs}``). Optional
137+
``cfg["dilate"]``: int, pixels to grow labels by after segmentation
138+
(via ``patchworks.dilate_labels``), applied regardless of ``method``.
139+
Omitted/0 disables dilation.
140+
141+
Returns
142+
-------
143+
callable
144+
``(ndarray) -> ndarray`` returning integer labels.
145+
"""
146+
fn = _build_method_fn(cfg)
147+
148+
dilate = cfg.get("dilate")
149+
if dilate:
150+
from patchworks import dilate_labels
151+
152+
fn = dilate_labels(fn, iterations=dilate)
153+
154+
return fn
155+
156+
157+
def _build_method_fn(cfg):
158+
"""Build the per-tile segmentation function for ``cfg["method"]``.
159+
160+
Parameters
161+
----------
162+
cfg : dict
163+
Snakemake config, see :func:`build_fn`.
137164
138165
Returns
139166
-------

0 commit comments

Comments
 (0)