BWA mem bam output name sorted
1
1
Entering edit mode
4.2 years ago
User000 ▴ 690

Hello,

I have a sorted bam file (bwa mem alignment). Now I need to mark and remove duplicates using samtools. Before it asks me to do collate and fixmate then sort and then markdup. I was wondering if bam output (without sorting) is already name sorted (bwa version 0.7.17)? So I could skip unnecessary sorting, collating steps and after alignment pass directly to fixmate?

bam bwa samtools • 5.2k views
ADD COMMENT
0
Entering edit mode

BWA does not provide sorted bam file as output. If you want to check whether the aligned file is sorted or not use the following command.

samtools view -H <BAM file name> | grep SO
ADD REPLY
3
Entering edit mode
4.2 years ago
ATpoint 81k

The alignment output (if without further manipulation) is grouped by name since fastq is grouped by name. Therefore you can pipe this directly into fixmate, e.g.:

bwa mem (...options) | samtools fixmate -m - - | samtools sort -o sorted.bam

The -m option of fixmate adds the mate tags which are required for the markdup command. The file must also be coordinate-sorted whereas fixmate requires files to be grouped or sorted by name.

samtools markdup sorted.bam markdup.bam
ADD COMMENT

Login before adding your answer.

Traffic: 2026 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6