Skip to content

Commit

Permalink
Fix BAM header cleaning (#78)
Browse files Browse the repository at this point in the history
* Fix samtools sort reversion

* Move BAM header cleaning to trimPrimerSequences process
  • Loading branch information
Matt Bull authored Sep 26, 2020
1 parent db1b21b commit d613e9d
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions modules/illumina.nf
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,10 @@ process readMapping {
tuple(sampleName, path("${sampleName}.sorted.bam"))

script:
if ( params.cleanBamHeader )
"""
ln -s ${forward} sample_1.fq.gz
ln -s ${reverse} sample_2.fq.gz
bwa mem -t ${task.cpus} ${ref} sample_1.fq.gz sample_2.fq.gz | samtools view -bS | \
samtools sort -o ${sampleName}.sorted.bam
"""

else
"""
bwa mem -t ${task.cpus} ${ref} ${forward} ${reverse} | samtools view -bS | \
samtools sort -o ${sampleName}.sorted.bam
"""
"""
bwa mem -t ${task.cpus} ${ref} ${forward} ${reverse} | \
samtools sort -o ${sampleName}.sorted.bam
"""
}

process trimPrimerSequences {
Expand All @@ -104,6 +94,25 @@ process trimPrimerSequences {
} else {
ivarCmd = "ivar trim"
}

if ( params.cleanBamHeader )
"""
samtools reheader --no-PG -c 'sed "s/${sampleName}/sample/g"' ${bam} | \
samtools view -F4 -o sample.mapped.bam
mv sample.mapped.bam ${sampleName}.mapped.bam
samtools index ${sampleName}.mapped.bam
${ivarCmd} -i ${sampleName}.mapped.bam -b ${bedfile} -m ${params.illuminaKeepLen} -q ${params.illuminaQualThreshold} -p ivar.out
samtools reheader --no-PG -c 'sed "s/${sampleName}/sample/g"' ivar.out.bam | \
samtools sort -o sample.mapped.primertrimmed.sorted.bam
mv sample.mapped.primertrimmed.sorted.bam ${sampleName}.mapped.primertrimmed.sorted.bam
"""

else
"""
samtools view -F4 -o ${sampleName}.mapped.bam ${bam}
samtools index ${sampleName}.mapped.bam
Expand Down

0 comments on commit d613e9d

Please sign in to comment.