Hi Everyone!!
I am trying to pass the FASTP trimmed files to BWAMEM process in nextflow and for some reason after running the code mentioned below (dsl2
), I only get one bam file. The FASTP runs on all 24 files but BWAMEM process runs only on single file. I don't understand what's wrong. I am trying to imitate this pipeline
params.memory = "3g"
params.cpus = 1
params.output = "."
process FASTP{
cpus params.cpus
memory params.memory
publishDir "${params.output}/02_adapterTrimming", mode: 'copy'
input:
tuple val(sid), path(reads)
output:
tuple val(sid), file(fq_1_paired), file(fq_2_paired), emit: trimmed_reads
file("${sid}.fastp_stats.json")
file("${sid}.fastp_stats.html")
script:
fq_1_paired = sid + '_R1_P.fastq.gz'
fq_2_paired = sid + '_R2_P.fastq.gz'
"""
fastp \
--in1 ${reads[0]} \
--in2 ${reads[1]}\
--out1 $fq_1_paired \
--out2 $fq_2_paired \
--json ${sid}.fastp_stats.json \
--html ${sid}.fastp_stats.html
"""
}
process BWAMEM{
publishDir "${params.output}/03_alignment", mode: 'copy'
memory params.memory
cpus params.cpus
input:
tuple val(sid), file(reads1), file(reads2)
val(reference)
output:
path "*.sorted.bam", emit: alignments
path "*.bai"
shell:
'''
ref=$(echo !{reference} | sed -e 's/\\.[^.]*$//')
id=$(zcat !{reads1} | head -n 1 | cut -f 3-4 -d":" | sed 's/@//')
bwa mem -M -R "$(echo "@RG\\tID:${id}\\tSM:!{sid}\\tPL:ILLUMINA")" -t !{task.cpus} ${ref} !{reads1} !{reads2} | samtools sort -@ !{task.cpus} -o !{sid}.sorted.bam -
samtools index -@ !{task.cpus} !{sid}.sorted.bam
'''
}
and the workflow section is
if (params.input != false) {
Channel.fromFilePairs(params.input, checkIfExists: true )
.set { input_fastqs }
}
workflow{
reference_ch=BWAINDEX.out.bwa_idx.flatten().filter(~/.*fai/)
FASTP(input_fastqs)
BWAMEM(FASTP.out[0], reference_ch)
}
I tried BWAMEM(FASTP.out.trimmed_reads.groupTuple(), reference_ch)
as well but it's aligning a single sample
N E X T F L O W ~ version 21.10.6
Launching `main.nf` [pedantic_montalcini] - revision: aeba1fa55a
executor > local (26)
[11/767e8f] process > BWAINDEX [100%] 1 of 1 ✔
[96/644b6d] process > FASTP (24) [100%] 24 of 24 ✔
[97/2a2e3d] process > BWAMEM (1) [100%] 1 of 1 ✔
It works. However, now it gives me the following error. Is there a way to apply
toRealPath()
withbasename
?Thanks I resolved this issue with emitting
.fa
file directly and usingtoRealPath