From dd70ea115f61049f5dcddc2a5ea42e6151c89413 Mon Sep 17 00:00:00 2001 From: bednarsky <72978444+bednarsky@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:03:50 +0100 Subject: [PATCH 1/4] Adapt to my resource settings --- workflow/Snakefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/workflow/Snakefile b/workflow/Snakefile index 74e2a5d..af50e97 100644 --- a/workflow/Snakefile +++ b/workflow/Snakefile @@ -240,8 +240,12 @@ rule annotate: conda: "sopa" resources: - partition="gpgpuq" if args['annotation']['method'] == "tangram" else "shortq", - gpu="a100:1" if args['annotation']['method'] == "tangram" else 0, +resources: + # adapted by RB, recommended by sopa author + slurm_partition = "gpu" if args['annotation']['method'] == "tangram" else "shortq", + slurm_extra = "--qos=gpu --gres=gpu:h100pcie" if args['annotation']['method'] == "tangram" else "--qos=shortq", + mem_mb = 128000, + runtime = "12h", params: method_name = args['annotation']['method'], args_annotation = str(args['annotation']['args']), From a4b3b502fb027951d1ff36d0184fefc8cb25845d Mon Sep 17 00:00:00 2001 From: bednarsky <72978444+bednarsky@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:14:21 +0100 Subject: [PATCH 2/4] Bug fix: indentation error --- workflow/Snakefile | 1 - 1 file changed, 1 deletion(-) diff --git a/workflow/Snakefile b/workflow/Snakefile index af50e97..1fa992e 100644 --- a/workflow/Snakefile +++ b/workflow/Snakefile @@ -240,7 +240,6 @@ rule annotate: conda: "sopa" resources: -resources: # adapted by RB, recommended by sopa author slurm_partition = "gpu" if args['annotation']['method'] == "tangram" else "shortq", slurm_extra = "--qos=gpu --gres=gpu:h100pcie" if args['annotation']['method'] == "tangram" else "--qos=shortq", From 39308b588601ccdf07f0bc6821cdf41ab03a4b6c Mon Sep 17 00:00:00 2001 From: bednarsky <72978444+bednarsky@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:43:50 +0100 Subject: [PATCH 3/4] Move variable access into params to avoid name error path is unknown in this context #166 --- workflow/Snakefile | 75 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/workflow/Snakefile b/workflow/Snakefile index 1fa992e..a316c8e 100644 --- a/workflow/Snakefile +++ b/workflow/Snakefile @@ -11,12 +11,15 @@ rule all: paths.explorer_experiment, paths.explorer_image, paths.report, + params: + explorer_directory = paths.explorer_directory, + explorer_experiment = paths.explorer_experiment, shell: """ echo 🎉 Successfully run sopa - echo → SpatialData output directory: {paths.sdata_path} - echo → Explorer output directory: {paths.explorer_directory} - echo → Open the result in the explorer: 'open {paths.explorer_experiment}' + echo → SpatialData output directory: {params.sdata_path} + echo → Explorer output directory: {params.explorer_directory} + echo → Open the result in the explorer: 'open {params.explorer_experiment}' """ rule to_spatialdata: @@ -29,10 +32,12 @@ rule to_spatialdata: resources: mem_mb=128_000, params: - args_reader = str(args['read']) + args_reader = str(args['read']), + data_path = paths.data_path, + sdata_path = paths.sdata_path, shell: """ - sopa read {paths.data_path} --sdata-path {paths.sdata_path} {params.args_reader} + sopa read {params.data_path} --sdata-path {params.sdata_path} {params.args_reader} """ checkpoint patchify_cellpose: @@ -43,11 +48,12 @@ checkpoint patchify_cellpose: patches = touch(paths.smk_patches), params: args_patchify = str(args["patchify"].where(contains="pixel")), + sdata_path = paths.sdata_path, conda: "sopa" shell: """ - sopa patchify image {paths.sdata_path} {params.args_patchify} + sopa patchify image {params.sdata_path} {params.args_patchify} """ checkpoint patchify_baysor: @@ -61,11 +67,12 @@ checkpoint patchify_baysor: args_patchify = str(args["patchify"].where(contains="micron")), args_baysor = args.dump_baysor_patchify() if args.baysor else "", arg_prior = "--use-prior" if args.cellpose else "", + sdata_path = paths.sdata_path, conda: "sopa" shell: """ - sopa patchify baysor {paths.sdata_path} {params.args_patchify} {params.args_baysor} {params.arg_prior} + sopa patchify baysor {params.sdata_path} {params.args_patchify} {params.args_baysor} {params.arg_prior} """ checkpoint patchify_comseg: @@ -86,11 +93,12 @@ checkpoint patchify_comseg: )), args_comseg = args.dump_comseg_patchify() if args.comseg else "", arg_prior = "--use-prior" if args.cellpose else "", + sdata_path = paths.sdata_path, conda: "sopa" shell: """ - sopa patchify comseg {paths.sdata_path} {params.args_patchify} {params.args_comseg} {params.arg_prior} + sopa patchify comseg {params.sdata_path} {params.args_patchify} {params.args_comseg} {params.arg_prior} """ rule patch_segmentation_cellpose: @@ -103,9 +111,11 @@ rule patch_segmentation_cellpose: "sopa" params: args_cellpose = str(args["segmentation"]["cellpose"]), + sdata_path = paths.sdata_path, + smk_cellpose_temp_dir = paths.smk_cellpose_temp_dir, shell: """ - sopa segmentation cellpose {paths.sdata_path} --patch-dir {paths.smk_cellpose_temp_dir} --patch-index {wildcards.index} {params.args_cellpose} + sopa segmentation cellpose {params.sdata_path} --patch-dir {params.smk_cellpose_temp_dir} --patch-index {wildcards.index} {params.args_cellpose} """ rule patch_segmentation_baysor: @@ -141,13 +151,16 @@ rule patch_segmentation_comseg: output: paths.smk_comseg_temp_dir / "{index}" / "segmentation_polygons.json", paths.smk_comseg_temp_dir / "{index}" / "segmentation_counts.h5ad", + params: + sdata_path = paths.sdata_path, + smk_comseg_temp_dir = paths.smk_comseg_temp_dir, conda: "sopa" resources: mem_mb=128_000, shell: """ - sopa segmentation comseg {paths.sdata_path} --patch-dir {paths.smk_comseg_temp_dir} --patch-index {wildcards.index} + sopa segmentation comseg {params.sdata_path} --patch-dir {params.smk_comseg_temp_dir} --patch-index {wildcards.index} """ def get_input_resolve(name, dirs=False): @@ -161,11 +174,14 @@ rule resolve_cellpose: get_input_resolve("cellpose"), output: touch(paths.smk_cellpose_boundaries), + params: + sdata_path = paths.sdata_path, + smk_cellpose_temp_dir = paths.smk_cellpose_temp_dir, conda: "sopa" shell: """ - sopa resolve cellpose {paths.sdata_path} --patch-dir {paths.smk_cellpose_temp_dir} + sopa resolve cellpose {params.sdata_path} --patch-dir {params.smk_cellpose_temp_dir} """ rule resolve_baysor: @@ -180,11 +196,14 @@ rule resolve_baysor: params: args_patches_dirs = lambda _, input: " ".join(f"--patches-dirs {directory}" for directory in input.dirs), args_min_area = args.min_area("baysor"), + sdata_path = paths.sdata_path, + smk_baysor_temp_dir = paths.smk_baysor_temp_dir, + gene_column = args.gene_column, shell: """ - sopa resolve baysor {paths.sdata_path} --gene-column {args.gene_column} {params.args_min_area} {params.args_patches_dirs} + sopa resolve baysor {params.sdata_path} --gene-column {params.gene_column} {params.args_min_area} {params.args_patches_dirs} - rm -r {paths.smk_baysor_temp_dir} # cleanup large baysor files + rm -r {params.smk_baysor_temp_dir} # cleanup large baysor files """ rule resolve_comseg: @@ -199,11 +218,14 @@ rule resolve_comseg: params: args_patches_dirs=lambda _, input: " ".join(f"--patches-dirs {directory}" for directory in input.dirs), args_min_area=args.min_area("comseg"), + sdata_path = paths.sdata_path, + smk_comseg_temp_dir = paths.smk_comseg_temp_dir, + gene_column = args.gene_column, shell: """ - sopa resolve comseg {paths.sdata_path} --gene-column {args.gene_column} {params.args_min_area} {params.args_patches_dirs} + sopa resolve comseg {params.sdata_path} --gene-column {params.gene_column} {params.args_min_area} {params.args_patches_dirs} - rm -r {paths.smk_comseg_temp_dir} # cleanup large comseg files + rm -r {params.smk_comseg_temp_dir} # cleanup large comseg files """ def get_smk_boundaries(args): @@ -225,11 +247,12 @@ rule aggregate: "sopa" params: args_aggregate = str(args["aggregate"] or ""), + sdata_path = paths.sdata_path, resources: mem_mb=64_000, shell: """ - sopa aggregate {paths.sdata_path} {params.args_aggregate} + sopa aggregate {params.sdata_path} {params.args_aggregate} """ rule annotate: @@ -248,9 +271,10 @@ rule annotate: params: method_name = args['annotation']['method'], args_annotation = str(args['annotation']['args']), + sdata_path = paths.sdata_path, shell: """ - sopa annotate {params.method_name} {paths.sdata_path} {params.args_annotation} + sopa annotate {params.method_name} {params.sdata_path} {params.args_annotation} """ rule image_write: @@ -258,16 +282,18 @@ rule image_write: paths.sdata_zgroup, output: paths.explorer_image, + params: + sdata_path = paths.sdata_path, + args_explorer = str(args["explorer"].where(keys=['lazy', 'ram_threshold_gb', 'pixel_size', 'pixelsize'])), + explorer_directory = paths.explorer_directory, conda: "sopa" resources: mem_mb=64_000, partition="longq" - params: - args_explorer = str(args["explorer"].where(keys=['lazy', 'ram_threshold_gb', 'pixel_size', 'pixelsize'])), shell: """ - sopa explorer write {paths.sdata_path} --output-path {paths.explorer_directory} {params.args_explorer} --mode "+i" --no-save-h5ad + sopa explorer write {params.sdata_path} --output-path {params.explorer_directory} {params.args_explorer} --mode "+i" --no-save-h5ad """ rule report: @@ -277,11 +303,14 @@ rule report: paths.annotations if args.annotate else [], output: paths.report, + params: + sdata_path = paths.sdata_path, + report = paths.report, conda: "sopa" shell: """ - sopa report {paths.sdata_path} {paths.report} + sopa report {params.sdata_path} {params.report} """ rule explorer: @@ -297,7 +326,9 @@ rule explorer: mem_mb=256_000, params: args_explorer = str(args["explorer"]), + sdata_path = paths.sdata_path, + explorer_directory = paths.explorer_directory, shell: """ - sopa explorer write {paths.sdata_path} --output-path {paths.explorer_directory} {params.args_explorer} --mode "-i" + sopa explorer write {params.sdata_path} --output-path {params.explorer_directory} {params.args_explorer} --mode "-i" """ From 2c247af14b9b702666cae033418699f6aa68b915 Mon Sep 17 00:00:00 2001 From: Quentin Blampey Date: Wed, 8 Jan 2025 09:56:58 +0100 Subject: [PATCH 4/4] minor fixes --- workflow/Snakefile | 1 + workflow/utils.py | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/workflow/Snakefile b/workflow/Snakefile index a316c8e..eec6297 100644 --- a/workflow/Snakefile +++ b/workflow/Snakefile @@ -14,6 +14,7 @@ rule all: params: explorer_directory = paths.explorer_directory, explorer_experiment = paths.explorer_experiment, + sdata_path = paths.sdata_path, shell: """ echo 🎉 Successfully run sopa diff --git a/workflow/utils.py b/workflow/utils.py index 0d81eea..9df8b97 100644 --- a/workflow/utils.py +++ b/workflow/utils.py @@ -204,8 +204,7 @@ def gene_column(self): return self.config["segmentation"]["baysor"]["config"]["data"]["gene"] elif "comseg" in self.config["segmentation"]: return self.config["segmentation"]["comseg"]["config"]["gene_column"] - else: - raise ValueError("No gene column found in the config") + return "" # gene column not needed ### ComSeg related methods