diff --git a/utils/nextflow/meta.yaml b/utils/nextflow/meta.yaml index 914b3a353e3..65f34f91139 100644 --- a/utils/nextflow/meta.yaml +++ b/utils/nextflow/meta.yaml @@ -5,4 +5,8 @@ authors: notes: | This wrapper can e.g. be used to run `nf-core `_ pipelines. In each of the nf-core pipeline descriptions, you will find available parameters and the output file structure (under "aws results"). - The latter can be used to set the desired output files for this wrapper. \ No newline at end of file + The latter can be used to set the desired output files for this wrapper. +params: + launch_dir: | + Allows adjusting the directory from which nextflow is launched. + Nextflow itself does not allow doing so; it always sets launchDir (read-only) from where it was invoked. diff --git a/utils/nextflow/test/Snakefile b/utils/nextflow/test/Snakefile index 8b2562bb8d6..29d69866223 100644 --- a/utils/nextflow/test/Snakefile +++ b/utils/nextflow/test/Snakefile @@ -44,15 +44,18 @@ rule chipseq_pipeline: gtf="data/genome.gtf", # any -- pipeline file arguments can be given here as = output: - "results/multiqc/broadPeak/multiqc_report.html", + multiqc_report="results/multiqc/broadPeak/multiqc_report.html", + # directory from which nextflow is launched, will contain the `.nextflow` directory + launch_dir=directory("some_directory"), params: pipeline="nf-core/chipseq", revision="2.0.0", profile=["test", "docker"], + launch_dir=lambda wildcards, output: output.launch_dir, # The chosen pipeline expects an --outdir to be given. # We infer this from the output file path. Since that file path can be changed # e.g. in case of cloud storage, we use a lambda function to infer the outdir. - outdir=lambda wildcards, output: str(Path(output[0]).parents[-2]), + outdir=lambda wildcards, output: str(Path(output.multiqc_report).parents[-2]), # any -- pipeline arguments can be given here as = handover: True wrapper: diff --git a/utils/nextflow/wrapper.py b/utils/nextflow/wrapper.py index ea5c8cbde2b..23b49c74997 100644 --- a/utils/nextflow/wrapper.py +++ b/utils/nextflow/wrapper.py @@ -32,16 +32,18 @@ files = ",".join(files) add_parameter(name, files) for name, value in snakemake.params.items(): - if ( - name != "pipeline" - and name != "revision" - and name != "profile" - and name != "extra" - ): + if name not in {"pipeline", "revision", "profile", "extra", "launch_dir"}: add_parameter(name, value) log = snakemake.log_fmt_shell(stdout=False, stderr=True) args = " ".join(args) pipeline = snakemake.params.pipeline +launch_dir = snakemake.params.get("launch_dir") +if launch_dir: + if not os.path.isdir(launch_dir): + raise ValueError(f"launch_dir does not exist: {launch_dir}") + else: + os.chdir(launch_dir) + shell("nextflow run {pipeline} {args} {extra} {log}")