【问题标题】:Converting Channels into strings in Nextflow DSL2在 Nextflow DSL2 中将通道转换为字符串
【发布时间】:2022-11-11 01:08:32
【问题描述】:

我想知道如何在工作流块中提取 Nextflow Channel 的内容并使其成为字符串。

我需要这个例如:

  • 使用 Groovy 映射定义切换系统,其中映射键是根据进程的输出选择的
  • 使用 watchPath 方法观察作为前一个进程输出的路径
  • 任何其他需要字符串但字符串的值是动态且不固定的情况

我已经尝试过 .toString()、.map{}、.view() 以及我在文档中可以找到的所有内容

【问题讨论】:

    标签: groovy bioinformatics nextflow


    【解决方案1】:

    我想知道如何提取 Nextflow 频道的内容和 把它变成一个字符串

    最好避免尝试这样做。如果您只想根据流程的输出选择映射键,您只需在工作流块中声明您的映射并根据需要使用它。例如:

    process test {
    
        input:
        val myval
    
        output:
        path "${myval}.txt"
    
        """
        touch "${myval}.txt"
        """
    }
    
    workflow {
    
        def foobarbaz = ['foo': 1, 'bar': 2, 'baz': 3]
    
        Channel.of('foo', 'bar', 'baz')
            | test
            | map { tuple( foobarbaz[ it.baseName ], it ) }
            | view()
    }
    

    结果:

    $ nextflow run main.nf 
    N E X T F L O W  ~  version 22.10.0
    Launching `main.nf` [high_faggin] DSL2 - revision: 43aaa56eee
    executor >  local (3)
    [0e/0fd6dc] process > test (3) [100%] 3 of 3 ✔
    [1, /path/to/work/a7/d501cb2a8426c5639117d14e8fb7fe/foo.txt]
    [2, /path/to/work/22/df9cc4f1d34b9cca0d0331fac5c150/bar.txt]
    [3, /path/to/work/0e/0fd6dc0519a34c52903b990755f450/baz.txt]
    

    请注意,您不需要 watchPath 工厂方法来查看前一个进程的输出路径。只需在output 块中定义前一个进程的输出,并在下游进程的input 块中将它们声明为inputs。例如:

    process foo {
    
        input:
        val myval
    
        output:
        path "${myval}.txt"
    
        """
        echo "value: ${myval}" > "${myval}.txt"
        """
    }
    
    process bar {
    
        input:
        path myfile
    
        output:
        stdout
    
        """
        echo "Contents of ${myfile}:" 
        cat "${myfile}"
        """
    }
    
    workflow {
    
        Channel.of('foo', 'bar', 'baz')
            | foo 
            | bar
            | view()
    }
    

    结果:

    $ nextflow run main.nf 
    N E X T F L O W  ~  version 22.10.0
    Launching `main.nf` [clever_lovelace] DSL2 - revision: c388bd26af
    executor >  local (6)
    [ac/1be228] process > foo (2) [100%] 3 of 3 ✔
    [11/7b3c6e] process > bar (1) [100%] 3 of 3 ✔
    Contents of foo.txt:
    value: foo
    
    Contents of bar.txt:
    value: bar
    
    Contents of baz.txt:
    value: baz
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-10
      • 2015-10-24
      • 1970-01-01
      相关资源
      最近更新 更多