# How to pass multimap variable in workflow? redundant code

**URL:** <https://community.seqera.io/t/how-to-pass-multimap-variable-in-workflow-redundant-code/374>\
**Category:** Ask for help\
**Tags:** nextflow\
**Created:** [January 10, 2024, 7:39pm UTC](https://community.seqera.io/t/how-to-pass-multimap-variable-in-workflow-redundant-code/374 "2024-01-10T19:39:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![complexgenome](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/complexgenome/32/392_2.png) [@complexgenome](https://community.seqera.io/u/complexgenome)\
**Post date:** [January 10, 2024, 7:39pm UTC](https://community.seqera.io/t/how-to-pass-multimap-variable-in-workflow-redundant-code/374/1 "2024-01-10T19:39:56Z")

</div>

Hi there,

I’ve file structure as:

`tree workflows/`

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

`$tree modules/`

```auto
modules/
└── fastp_wes.nf

```

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

I’ve a **main.nf** as:

```auto
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**

```auto
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

```auto
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.

---

<div class="post-metadata">

**Author:** ![mribeirodantas](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mribeirodantas/32/235_2.png) [@mribeirodantas](https://community.seqera.io/u/mribeirodantas)\
**Post date:** [January 12, 2024, 5:37pm UTC](https://community.seqera.io/t/how-to-pass-multimap-variable-in-workflow-redundant-code/374/2 "2024-01-12T17:37:34Z")

</div>

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:

```Groovy
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)
}

```
