From 1f3187e535311e1ad25320de4a8d1a35fc9c80e8 Mon Sep 17 00:00:00 2001 From: dimalvovs Date: Mon, 28 Apr 2025 11:31:41 -0400 Subject: [PATCH] add example for running in nextflow, close #142 --- nextflow/main.nf | 22 +++++- nextflow/nextflow.config | 165 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 nextflow/nextflow.config diff --git a/nextflow/main.nf b/nextflow/main.nf index 5d83f9a7..a1dfc5a0 100644 --- a/nextflow/main.nf +++ b/nextflow/main.nf @@ -171,4 +171,24 @@ process COGAPS_ADATA2DGC { R: \$(Rscript -e 'print(packageVersion("base"))' | awk '{print \$2}') END_VERSIONS """ -} \ No newline at end of file +} + +//example channel with data folders, for example +ch_data = Channel.fromPath('./test/**gist.rds') + .map { tuple([id:it.getParent().getName()], it)} + +//example channel with cparams +ch_cparams = Channel.of([npatterns: 7, niterations: 100, sparse: 1, distributed: 'null', nsets:1, nthreads:1], + [npatterns: 7, niterations: 100, sparse: 0, distributed: 'null', nsets:1, nthreads:1]) + +// combine the two channels as input to CoGAPS +ch_input = ch_data.combine(ch_cparams) + +//run the workflow +workflow { + COGAPS(ch_input) +} + +//example: +//nextflow run main.nf -profile docker -resume +//nextflow run main.nf -profile slurm -resume \ No newline at end of file diff --git a/nextflow/nextflow.config b/nextflow/nextflow.config new file mode 100644 index 00000000..bc8a9b80 --- /dev/null +++ b/nextflow/nextflow.config @@ -0,0 +1,165 @@ +// default params +params { + outdir = 'out' + input = '' + + //cogaps params + npatterns = 7 + nsets = 1 + niterations = 100 + sparse = 1 + seed = 42 + distributed = 'null' + nthreads = 1 + + max_memory = '8.GB' + max_cpus = 4 + max_time = '48.h' +} + +//reporting +def trace_timestamp = new java.util.Date().format( 'yyyy-MM-dd_HH-mm-ss') +timeline { + enabled = true + file = "${params.outdir}/pipeline_info/execution_timeline_${trace_timestamp}.html" +} +report { + enabled = true + file = "${params.outdir}/pipeline_info/execution_report_${trace_timestamp}.html" +} +trace { + enabled = true + file = "${params.outdir}/pipeline_info/execution_trace_${trace_timestamp}.txt" +} +dag { + enabled = true + file = "${params.outdir}/pipeline_info/pipeline_dag_${trace_timestamp}.html" +} + +//output +process { + publishDir = { "${params.outdir}" } +} + +//resources +def check_max(obj, type) { + if (type == 'memory') { + try { + if (obj.compareTo(params.max_memory as nextflow.util.MemoryUnit) == 1) + return params.max_memory as nextflow.util.MemoryUnit + else + return obj + } catch (all) { + println " ### ERROR ### Max memory '${params.max_memory}' is not valid! Using default value: $obj" + return obj + } + } else if (type == 'time') { + try { + if (obj.compareTo(params.max_time as nextflow.util.Duration) == 1) + return params.max_time as nextflow.util.Duration + else + return obj + } catch (all) { + println " ### ERROR ### Max time '${params.max_time}' is not valid! Using default value: $obj" + return obj + } + } else if (type == 'cpus') { + try { + return Math.min( obj, params.max_cpus as int ) + } catch (all) { + println " ### ERROR ### Max cpus '${params.max_cpus}' is not valid! Using default value: $obj" + return obj + } + } +} + +process { + /* +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + btc/spatial Nextflow base config file +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + A 'blank slate' config file, appropriate for general use on most high performance + compute environments. Assumes that all software is installed and available on + the PATH. Runs in `local` mode - all jobs will be run on the logged in environment. +---------------------------------------------------------------------------------------- + */ + + // TODO nf-core: Check the defaults for all processes + cpus = { check_max( 1 * task.attempt, 'cpus' ) } + memory = { check_max( 6.GB * task.attempt, 'memory' ) } + time = { check_max( 4.h * task.attempt, 'time' ) } + + errorStrategy = { task.exitStatus in ((130..145) + 104) ? 'retry' : 'finish' } + maxRetries = 1 + maxErrors = '-1' + + // Process-specific resource requirements + // NOTE - Please try and re-use the labels below as much as possible. + // These labels are used and recognised by default in DSL2 files hosted on nf-core/modules. + // If possible, it would be nice to keep the same label naming convention when + // adding in your local modules too. + // TODO nf-core: Customise requirements for specific processes. + // See https://www.nextflow.io/docs/latest/config.html#config-process-selectors + withLabel:process_single { + cpus = { check_max( 1 , 'cpus' ) } + memory = { check_max( 6.GB * task.attempt, 'memory' ) } + time = { check_max( 4.h * task.attempt, 'time' ) } + } + withLabel:process_low { + cpus = { check_max( 2 * task.attempt, 'cpus' ) } + memory = { check_max( 12.GB * task.attempt, 'memory' ) } + time = { check_max( 4.h * task.attempt, 'time' ) } + } + withLabel:process_medium { + cpus = { check_max( 6 * task.attempt, 'cpus' ) } + memory = { check_max( 24.GB * task.attempt, 'memory' ) } + time = { check_max( 8.h * task.attempt, 'time' ) } + } + withLabel:process_high { + cpus = { check_max( 12 * task.attempt, 'cpus' ) } + memory = { check_max( 72.GB * task.attempt, 'memory' ) } + time = { check_max( 16.h * task.attempt, 'time' ) } + } + withLabel:process_long { + time = { check_max( 48.h * task.attempt, 'time' ) } + } + withLabel:process_high_memory { + memory = { check_max( 200.GB * task.attempt, 'memory' ) } + } + withLabel:error_ignore { + errorStrategy = 'ignore' + } + withLabel:error_retry { + errorStrategy = 'retry' + maxRetries = 2 + } +} + +// profiles to run the pipeline +profiles { + docker { + docker.enabled = true + } + + singularity { + singularity.enabled = true + singularity.autoMounts = true + } + + slurm { + singularity.enabled = true + singularity.autoMounts = true + process { + executor = 'slurm' + cpus = 10 + memory = '10 GB' + } + } + test { + process { + withName: COGAPS { + cpus = 1 + } + } + } +} \ No newline at end of file