Reputation: 311
I defined four boolean variables (bwa_flg, lariat_flg, gatk_flg, and deepvariant_flg) in nextflow.config. Depending on the setting, I may have two bams (bam from bwa or/and lariat), two vcfs (vcf from gatk or/and deepvariant) I need the bam-vcf pair to do the following analysis like phasing etc. (So I might have four pairs at most) I tried these:
if (params.lariat_flg) {
lariat(ch_reads).set{ch_lariatbam}
if (params.gatk_flg) {
gatk(ch_lariatbam)
phase etc...
}
if (params.deepvariant_flg) {
deepvariant(ch_lariatbam)
phase etc...
}
}
if (params.bwa_flg) { // also have to include gatk and deepvariant again from here because already used previously...
bwa(ch_reads).set{ch_bwabam}
if (params.gatk_flg) {
gatk(ch_bwabam)
phase etc...
}
if (params.deepvariant_flg) {
deepvariant(ch_bwabam)
phase etc...
}
}
I have to write the following phase etc. four times, plus include these processes from modules four times. how to do it smartly...
Upvotes: 1
Views: 326
Reputation: 1077
If the bams are coming from the same output channel you could use the buffer
operator in the workflow declaration.
workflow example {
main:
bwa(input)
if ( params.bwa_flg ){
bwa
.out
.bwa_out
.buffer( size: 2 )
.set { bam_ch }
} else {
bwa
.out
.bam_ch1
.flatten()
.set { bam_ch }
}
deepvariant( bam_ch )
...
And if you need a flexible input for the process you can define a function.
process deepvariant {
input:
path(bams)
script:
def process_bams = bams{ "deepvariant --input $it" }.join('\n')
"""
${process_bams}
"""
}
But if they are coming from different processes, but they are from the same sample id, then you can merge samples based on the same if statement principles in the workflow declaration so long as you output tuples with sample id.
workflow example {
main:
bwa(input)
lariat(input)
if ( params.bwa_flg && params.lariat_flg ){
bwa
.out.baw_out
.combine( lariat.out.lariat_out, by: 0 )
.set { bam_ch }
} else if ( params.bwa_flg ){
bwa
.out
.bam_out
.set { bam_ch }
} else if ( params.lariat_flg ){
lariat
.out
.lariat_out
.set { bam_ch }
}
deepvariant( bam_ch )
...
combine
will only work in this example if the outputs of bwa
and lariat
are something like tuple val(sample_id), path(bam), emit: lariat_out
Edit:
Here is the flexible deepvariant input, assuming multiple inputs are denoted each by -i
:
process deepvariant {
input:
tuple val(sample_id), path(bams)
script:
def flexi_bams = bams{ "-i $it" }.join{' '}
"""
deepvariant ${flexi_bams} -o ${sample_id}.output
"""
Upvotes: 0