How to pass multimap variable in workflow? redundant code

Hi there,

I’ve file structure as:

tree workflows/

workflows/
├── rna.nf
└── wes.nf

$tree modules/

modules/
└── fastp_wes.nf

I set which analysis to run WES or RNA using user input.

I’ve a main.nf as:

include { rna  } from './workflows/rna'
include { wes } from './workflows/wes'

workflow {
    if (params.analysis=="both"){
        wes()
        rna() 
    }
    if (params.analysis=="wes"){
        wes()        
    }
    
    if (params.analysis=="rna"){
        rna()
 
    }
}

Inside wes and RNA I’m repeating split csv file code:
wes.nf

workflow wes {

def csvFile = params.input_csvFile

Channel.fromPath( csvFile )
        .splitCsv( )
                .multiMap { row ->
                def rna_reads=tuple(file(row[5]), file(row[6]))
            def tumor_reads = tuple( file( row[3]) ,file(row[4]))
            def normal_reads = tuple(file(row[1]),file(row[2]) )
            
            tumor:
                 tuple( row[0], tumor_reads )
            normal:
                 tuple( row[0], normal_reads )
                rna:
                tuple(row[0],rna_reads)
        }.set{samples}

samples.tumor.view { "tumor $it" }
samples.normal.view { "normal $it" }
samples.rna.view { "rna $it" }

  println "we are in wes"
    fastp().view()

}

I’ve rna.nf as

workflow rna {

def csvFile = params.input_csvFile
Channel.fromPath( csvFile )
        .splitCsv( )
                .multiMap { row ->
                def rna_reads=tuple(file(row[5]), file(row[6]))
            def tumor_reads = tuple( file( row[3]) ,file(row[4]))
            def normal_reads = tuple(file(row[1]),file(row[2]) )
            
            tumor:
                 tuple( row[0], tumor_reads )
            normal:
                 tuple( row[0], normal_reads )
                rna:
                tuple(row[0],rna_reads)
        }.set{samples}

samples.tumor.view { "tumor $it" }
samples.normal.view { "normal $it" }
samples.rna.view { "rna $it" }

    println "we are good in rna"

}

At the moment I have redundant code in WES and RNA workflow to read a CSV file and store.
How can I pass samples multi map to any workflow?

I tried to pass multi map variable but don’t know, it didn’t work; I accepted in input code block.

Any help would be appreciated.

For that, you need the take keyword and specify a name for each of the input channels provided to this workflow. See the example below:

process FOO {
  debug true

  input:
  val x
  
  output:
  stdout
  
  script:
  """
  echo ${x}
  """
}

workflow my_pipeline {
    take:
    foo
    bar

    main:
    FOO(foo)
}

workflow {
  Channel
    .of(1..10)
    .multiMap { it ->
      foo: it + 1
      bar: it * it
    }
    .set { result}
  my_pipeline(result)
}