Skip to content

Commit 7d2cbad

Browse files
fix smk pipeline after cli update
1 parent c8cc7c1 commit 7d2cbad

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

sopa/cli/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ def aggregate(
175175
help="Optional image key of the SpatialData object. By default, considers the only one image. It can be useful if another image is added later on",
176176
),
177177
method_name: str = typer.Option(
178-
help="If segmentation was performed with a generic method, this is the name of the method used."
178+
None,
179+
help="If segmentation was performed with a generic method, this is the name of the method used.",
179180
),
180181
):
181182
"""Create an `anndata` table containing the transcript count and/or the channel intensities per cell"""

workflow/Snakefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ checkpoint patchify_baysor:
5656
paths.smk_cellpose_boundaries if args.cellpose else [],
5757
output:
5858
patches_file = paths.smk_patches_file_baysor,
59-
baysor_temp_dir = directory(paths.baysor_temp_dir),
59+
smk_baysor_temp_dir = directory(paths.smk_baysor_temp_dir),
6060
params:
6161
args_patchify = str(args["patchify"].where(contains="micron")),
6262
args_baysor = args.dump_baysor_patchify() if args.baysor else "",
@@ -73,23 +73,23 @@ rule patch_segmentation_cellpose:
7373
paths.smk_patches_file_image,
7474
paths.smk_patches,
7575
output:
76-
f"{paths.cellpose_temp_dir}/{{index}}.parquet",
76+
f"{paths.smk_cellpose_temp_dir}/{{index}}.parquet",
7777
conda:
7878
"sopa"
7979
params:
8080
args_cellpose = str(args["segmentation"]["cellpose"]),
8181
shell:
8282
"""
83-
sopa segmentation cellpose {paths.sdata_path} --patch-dir {paths.cellpose_temp_dir} --patch-index {wildcards.index} {params.args_cellpose}
83+
sopa segmentation cellpose {paths.sdata_path} --patch-dir {paths.smk_cellpose_temp_dir} --patch-index {wildcards.index} {params.args_cellpose}
8484
"""
8585

8686
rule patch_segmentation_baysor:
8787
input:
8888
patches_file = paths.smk_patches_file_baysor,
89-
baysor_patch = f"{paths.baysor_temp_dir}/{{index}}",
89+
baysor_patch = f"{paths.smk_baysor_temp_dir}/{{index}}",
9090
output:
91-
f"{paths.baysor_temp_dir}/{{index}}/segmentation_polygons.json",
92-
f"{paths.baysor_temp_dir}/{{index}}/segmentation_counts.loom",
91+
f"{paths.smk_baysor_temp_dir}/{{index}}/segmentation_polygons.json",
92+
f"{paths.smk_baysor_temp_dir}/{{index}}/segmentation_counts.loom",
9393
params:
9494
args_baysor_prior_seg = args.baysor_prior_seg,
9595
resources:
@@ -119,7 +119,7 @@ rule resolve_cellpose:
119119
"sopa"
120120
shell:
121121
"""
122-
sopa resolve cellpose {paths.sdata_path} --patch-dir {paths.cellpose_temp_dir}
122+
sopa resolve cellpose {paths.sdata_path} --patch-dir {paths.smk_cellpose_temp_dir}
123123
"""
124124

125125
rule resolve_baysor:
@@ -138,7 +138,7 @@ rule resolve_baysor:
138138
"""
139139
sopa resolve baysor {paths.sdata_path} --gene-column {args.gene_column} {params.args_patches_dirs} {params.args_shapes}
140140
141-
rm -r {paths.baysor_temp_dir} # cleanup large baysor files
141+
rm -r {paths.smk_baysor_temp_dir} # cleanup large baysor files
142142
"""
143143

144144
rule aggregate:

workflow/utils.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,55 +26,62 @@ class WorkflowPaths:
2626
def __init__(self, config: dict) -> None:
2727
self.config = _sanity_check_config(config)
2828

29+
# spatialdata object files
2930
self.sdata_path = Path(self.config["sdata_path"])
3031
self.data_path = self.config["data_path"]
3132
self.sdata_zgroup = self.sdata_path / ".zgroup" # trick to fix snakemake ChildIOException
3233

34+
# spatial elements directories
3335
self.shapes_dir = self.sdata_path / "shapes"
3436
self.points_dir = self.sdata_path / "points"
3537
self.images_dir = self.sdata_path / "images"
3638
self.table_dir = self.sdata_path / "table"
3739

40+
# sdata.shapes
3841
self.baysor_boundaries = self.shapes_dir / "baysor_boundaries"
3942
self.cellpose_boundaries = self.shapes_dir / "cellpose_boundaries"
4043
self.patches = self.shapes_dir / "sopa_patches"
4144

45+
# snakemake cache / intermediate files
4246
self.sopa_cache = self.sdata_path / ".sopa_cache"
4347
self.smk_table = self.sopa_cache / "table"
4448
self.smk_patches = self.sopa_cache / "patches"
4549
self.smk_patches_file_image = self.sopa_cache / "patches_file_image"
4650
self.smk_patches_file_baysor = self.sopa_cache / "patches_file_baysor"
47-
self.smk_cellpose_boundaries = self.sopa_cache / "cellpose_boundaries"
48-
self.smk_baysor_boundaries = self.sopa_cache / "baysor_boundaries"
51+
self.smk_cellpose_temp_dir = self.sopa_cache / "cellpose_boundaries"
52+
self.smk_baysor_temp_dir = self.sopa_cache / "baysor_boundaries"
53+
self.smk_cellpose_boundaries = self.sopa_cache / "cellpose_boundaries_done"
54+
self.smk_baysor_boundaries = self.sopa_cache / "baysor_boundaries_done"
4955
self.smk_aggregation = self.sopa_cache / "aggregation"
5056

57+
# annotation files
5158
self.annotations = []
5259
if "annotation" in self.config:
5360
key = self.config["annotation"].get("args", {}).get("cell_type_key", "cell_type")
5461
self.annotations = self.table_dir / "table" / "obs" / key
5562

56-
self.cellpose_temp_dir = self.sopa_cache / "cellpose_boundaries"
57-
self.baysor_temp_dir = self.sopa_cache / "baysor_boundaries"
58-
63+
# user-friendly output files
5964
self.explorer_directory = self.sdata_path.with_suffix(".explorer")
6065
self.explorer_directory.mkdir(parents=True, exist_ok=True)
61-
6266
self.explorer_experiment = self.explorer_directory / "experiment.xenium"
6367
self.explorer_image = self.explorer_directory / "morphology.ome.tif"
64-
6568
self.report = self.explorer_directory / "analysis_summary.html"
6669

6770
def cells_paths(self, file_content: str, name, dirs: bool = False):
6871
if name == "cellpose":
69-
return [str(self.cellpose_temp_dir / f"{i}.parquet") for i in range(int(file_content))]
72+
return [
73+
str(self.smk_cellpose_temp_dir / f"{i}.parquet") for i in range(int(file_content))
74+
]
7075
if name == "baysor":
7176
indices = map(int, file_content.split())
7277
BAYSOR_FILES = ["segmentation_polygons.json", "segmentation_counts.loom"]
7378

7479
if dirs:
75-
return [str(self.baysor_temp_dir / str(i)) for i in indices]
80+
return [str(self.smk_baysor_temp_dir / str(i)) for i in indices]
7681
return [
77-
str(self.baysor_temp_dir / str(i) / file) for i in indices for file in BAYSOR_FILES
82+
str(self.smk_baysor_temp_dir / str(i) / file)
83+
for i in indices
84+
for file in BAYSOR_FILES
7885
]
7986

8087

@@ -114,7 +121,8 @@ def where(self, keys: Optional[list[str]] = None, contains: Optional[str] = None
114121

115122
def dump_baysor_patchify(self):
116123
return (
117-
str(self["segmentation"]["baysor"]) + f" --baysor-temp-dir {self.paths.baysor_temp_dir}"
124+
str(self["segmentation"]["baysor"])
125+
+ f" --baysor-temp-dir {self.paths.smk_baysor_temp_dir}"
118126
)
119127

120128
@classmethod

0 commit comments

Comments
 (0)