1
votes

I have the following (simplified) nextflow module. It has one process, which runs a multiple sequence alignment on a fasta file, and a workflow that runs this process (eventually it will run other processes too):

process clustal_omega_msa {
    input:
      path fastas
    output:
      path 'clustal.sto'
    script:
      """
      cat ${fastas} > merged.fa
      clustalo -infile merged.fa --outfmt=stockholm
      """
    container "https://depot.galaxyproject.org/singularity/clustalo:1.2.4--h1b792b2_4"
}

workflow msa {
  take:
    path fastas
  main:
    clustal_omega_msa(fastas)
}

I want this workflow to be both importable as a sub-workflow, and also executable directly. For this reason I have specified no parameters, and only used inputs (because I believe parameters can't be specified when calling a subworkflow).

However, I can see no way to run this subworkflow directly on the command line.

If I run nextflow run msa.nf -entry msa I get the following error:

No such variable: fastas

 -- Check script 'msa.nf' at line: 1 or see '.nextflow.log' file for more details

This makes sense - I haven't specified where these files come from. But how can I? If I follow the config part of the docs and create a nextflow.config with the following contents:

fastas = "/some/path/to/*.fasta"

I still get this error. I am also aware there is a -params-file option, but I believe that only works for parameters, not inputs.

1

1 Answers

1
votes

Implicit workflow definitions are ignored when a script is imported as module. This means that your workflow script that can be used either as a library module or as an application script:

nextflow.enable.dsl=2
params.input_fasta_files = './data/*.fasta'


process clustal_omega_msa {

    input:
    path fastas
    
    output:
    path 'clustal.sto'

    """
    cat ${fastas} > merged.fa
    clustalo -infile merged.fa --outfmt=stockholm
    """
}

workflow msa {
  
    take:
    fasta_files
  
    main:
    clustal_omega_msa(fasta_files)
}

workflow {

    input_fasta_files = Channel.fromPath( params.input_fasta_files ).collect()

    msa( input_fasta_files )
}

Note that if you were to move the 'msa' sub-workflow into a separate file, for example called 'msa.nf', you could then just import it and specify any required params to it using the addParams option. For example:

nextflow.enable.dsl=2

include { msa } from './path/to/msa.nf' addParams(foo: 'bar')

params.input_fasta_files = './data/*.fasta'


workflow {

    input_fasta_files = Channel.fromPath( params.input_fasta_files ).collect()

    msa(input_fasta_files)
}