循环两个变量在nextflow块?



我试图应用使用循环在nextflow块上快速使用函数,但我不确定如何设置两个变量的循环。我希望将——in1和——in2更改为正向和反向读对,以便为每个读取对获得输出文件。

#!/usr/bin/env nextflow
nextflow.enable.dsl=2
workflow {
FASTP()
}
process FASTP {
script:
"""
fastp
--in1 ${baseDir}/sequences/sequences_split/SRR19573234_R1.fastq 
--in2 ${baseDir}/sequences/sequences_split/SRR19573234_R2.fastq 
--out1 ${baseDir}/sequences/sequences_split/sequences_trimmed/trimmed_SRR19573234_R1.fastq 
--out2 ${baseDir}/sequences/sequences_split/sequences_trimmed/trimmed_SRR19573234_R2.fastq 
--html ${baseDir}/results/trimmed_SRR19573234.fastp.html

fastp 
--in1 ${baseDir}/sequences/sequences_split/SRR19573260_R1.fastq 
--in2 ${baseDir}/sequences/sequences_split/SRR19573260_R2.fastq 
--out1 ${baseDir}/sequences/sequences_split/sequences_trimmed/trimmed_SRR19573260_R1.fastq 
--out2 ${baseDir}/sequences/sequences_split/sequences_trimmed/trimmed_SRR19573260_R2.fastq 
--html ${baseDir}/results/trimmed_SRR19573260.fastp.html
"""
}

您可以使用fromFilePairs工厂方法创建一个通道,该通道发出与glob模式匹配的文件对。它们以元组的形式返回,其中第一个元素是组键,第二个元素是文件列表(按字典顺序排序)。例如:

params.reads = './sequences/sequences_split/*_R{1,2}.fastq'
process fastp {
input:
tuple val(sample), path(reads)
output:
tuple val(sample), path("trimmed_${sample}_R{1,2}.fastq"), emit: trimmed
path("trimmed_${sample}.fastp.html"), emit: html
script:
def (r1, r2) = reads
"""
fastp \
--in1 "${r1}" \
--in2 "${r2}" \
--out1 "trimmed_${sample}_R1.fastq" \
--out2 "trimmed_${sample}_R2.fastq" \
--html trimmed_${sample}.fastp.html
"""
}
workflow {
readgroups = Channel.fromFilePairs( params.reads )
fastp( readgroups )
// do something with the trimmed reads
fastp.out.trimmed.view()
}

结果:

$ nextflow run main.nf 
N E X T F L O W  ~  version 22.10.0
Launching `main.nf` [extravagant_mercator] DSL2 - revision: a2bffdf878
executor >  local (2)
[47/bc3a2e] process > fastp (1) [100%] 2 of 2 ✔
[SRR19573234, [/path/to/work/87/11dac1260431a174200e2d0df35754/trimmed_SRR19573234_R1.fastq, /path/to/work/87/11dac1260431a174200e2d0df35754/trimmed_SRR19573234_R2.fastq]]
[SRR19573260, [/path/to/work/47/bc3a2e4c149ba9d7dcb909ec668747/trimmed_SRR19573260_R1.fastq, /path/to/work/47/bc3a2e4c149ba9d7dcb909ec668747/trimmed_SRR19573260_R2.fastq]]

创建一个以3列分隔的文本文件选项卡:ID, R1, R2,读取文件,分割并使用此通道作为FASTP的输入

nextflow.enable.dsl=2
params.fastqs = "NO_FILE"

workflow {
fch = Channel.fromPath(params.fastqs).splitCsv(header:false,sep:'t')
FASTP(fch)
}
process FASTP {
input:
tuple val(id),val(R1),val(R2)
output:
tuple val(id),path("trimmed_${ID}_R1.fastq"),path("trimmed_${ID}_R2.fastq"),path("trimmed_${ID}.fastp.html")
script:
"""
fastp  
--in1 ${R1}  
--in2 ${R2}  
--out1 trimmed_${ID}_R1.fastq  
--out2 trimmed_${ID}_R2.fastq  
--html trimmed_${ID}.fastp.html
"""
}

相关内容

  • 没有找到相关文章

最新更新