如何使用 Nextflow 输出具有路径的价值通道
How to output a value channel that has paths using Nextflow
假设一个人有一些输出文件的过程(例如,将 sam 文件转换为 bam 文件)并且一个人希望该过程的输出成为一个价值通道,以便它可以多次重复使用。可以在通道输出期间执行此操作吗?或者,是否必须在输出并完成该过程后在队列通道上调用操作员(第一个?)?
这是一个例子:
process sam2bam {
input:
path samfile from alignments
output:
path '*sorted.bam' into sam2bam //CAN THIS BE A VALUE CHANNEL
script:
"""
samtools view -b -o ${samfile}.bam ${samfile}
"""
}
到目前为止,我已经输出了队列通道,然后复制它或尝试通过 first 将其转换为值通道。这看起来很笨拙,我认为必须有某种方法可以直接输出具有路径的价值通道。我似乎无法在文档中找到简单的答案。
谢谢!
最终这取决于 'alignments' 频道是否已经是 value channel:
A value channel is implicitly created by a process when an input
specifies a simple value in the from
clause. Moreover, a value channel
is also implicitly created as output for a process whose inputs are
only value channels.
请注意,这将创建一个 queue channel:
alignments = Channel.fromPath( 'test.sorted.sam' )
这将创建一个 value channel:
alignments = file( 'test.sorted.sam' )
所以如果'alignments'渠道是价值渠道,那么下游'sam2bam'渠道也是价值渠道。如果 'alignments channel' 确实是一个队列通道,那么是的,您需要使用 returns 单个值的通道运算符之一,例如 first, last, collect, count, min, max, reduce, sum. The one you want is almost always collect.
请注意,您还可以使用 each
input repeater 为集合中的每个项目重复执行流程。不确定您的下游代码是什么样的,但这样的代码可能很方便:
alignments = Channel.fromPath( '*.sorted.sam' )
chromosomes = Channel.of(1..23, 'X', 'Y')
process sam2bam {
input:
path samfile from alignments
output:
path "${samfile.baseName}.bam" into sam2bam
"""
touch "${samfile.baseName}.bam"
"""
}
process do_something {
echo true
input:
path bam from sam2bam
each chrom from chromosomes
"""
echo "${chrom}: ${bam}"
"""
}
假设一个人有一些输出文件的过程(例如,将 sam 文件转换为 bam 文件)并且一个人希望该过程的输出成为一个价值通道,以便它可以多次重复使用。可以在通道输出期间执行此操作吗?或者,是否必须在输出并完成该过程后在队列通道上调用操作员(第一个?)?
这是一个例子:
process sam2bam {
input:
path samfile from alignments
output:
path '*sorted.bam' into sam2bam //CAN THIS BE A VALUE CHANNEL
script:
"""
samtools view -b -o ${samfile}.bam ${samfile}
"""
}
到目前为止,我已经输出了队列通道,然后复制它或尝试通过 first 将其转换为值通道。这看起来很笨拙,我认为必须有某种方法可以直接输出具有路径的价值通道。我似乎无法在文档中找到简单的答案。
谢谢!
最终这取决于 'alignments' 频道是否已经是 value channel:
A value channel is implicitly created by a process when an input specifies a simple value in the
from
clause. Moreover, a value channel is also implicitly created as output for a process whose inputs are only value channels.
请注意,这将创建一个 queue channel:
alignments = Channel.fromPath( 'test.sorted.sam' )
这将创建一个 value channel:
alignments = file( 'test.sorted.sam' )
所以如果'alignments'渠道是价值渠道,那么下游'sam2bam'渠道也是价值渠道。如果 'alignments channel' 确实是一个队列通道,那么是的,您需要使用 returns 单个值的通道运算符之一,例如 first, last, collect, count, min, max, reduce, sum. The one you want is almost always collect.
请注意,您还可以使用 each
input repeater 为集合中的每个项目重复执行流程。不确定您的下游代码是什么样的,但这样的代码可能很方便:
alignments = Channel.fromPath( '*.sorted.sam' )
chromosomes = Channel.of(1..23, 'X', 'Y')
process sam2bam {
input:
path samfile from alignments
output:
path "${samfile.baseName}.bam" into sam2bam
"""
touch "${samfile.baseName}.bam"
"""
}
process do_something {
echo true
input:
path bam from sam2bam
each chrom from chromosomes
"""
echo "${chrom}: ${bam}"
"""
}