Link Search Menu Expand Document

Step 8 - Use a Map with a process-key

Step 7 provides a way to use a consistent API for a process. Ideally, however, we would like different process invocation to be chained rather than to explicitly add the correct configuration all the time. Let us add an additional key to the map, so that a process knows it’s scope.

// Step - 8
process addTupleWithProcessHash {
  input:
    tuple val(id), val(input), val(config)
  output:
    tuple val("${id}"), val(output)
  exec:
    def thisConf = config.addTupleWithProcessHash
    output = (thisConf.operator == "+")
                ? input + thisConf.term
                : input - thisConf.term
}
workflow step8 {
  Channel.from( [ 1, 2, 3 ] ) \
    | map{ el ->
      [
        el.toString(),
        el,
        [ "addTupleWithProcessHash" :
          [
            "operator" : "-",
            "term" : 10
          ]
        ]
      ] } \
    | addTupleWithProcessHash \
    | view{ it }
}

Which yields:

> nextflow -q run . -entry step8
WARN: DSL 2 IS AN EXPERIMENTAL FEATURE UNDER DEVELOPMENT -- SYNTAX MAY CHANGE IN FUTURE RELEASE
[3, -7]
[2, -8]
[1, -9]

Please note that we used the process name as a key in the map, so that each process can tell what configuration parameter are relevant for its own scope. We call this Map a ConfigMap.