I have read many posts regarding this question. The XT, XA tag doesn't seem to be used anymore by BWA mem, so I can't use them to identify uniquely mapped reads.
Some posts said that multiple hits are to be assigned a quality score of 0. However, I don't have any links to confirm if this is still true. Does anyone know where I can confirm this?
Does anyone know how to tell if a read is uniquely map from the result of BWA-mem alignment? Thank you.
If you want to ask for reads that have no secondary alignments, then you might need a script that runs through a read-name sorted file and looks for singleton read names.
Thank you, I'll try that.
I'm just wondering why hasn't there been a tool to perform such a task. This seems to be a common task when handling bam/sam files.
N.B., this isn't a common task. You'd be well advised to drop the concept of a "unique alignment" and just filter by MAPQ (and the flags that Matt Shirley indicated).
I am with the OP though that one should be able to select uniquely mapping reads. Even considering that I also agree that most people that want to make use of these "uniquely mapping reads" may not fully understand all the implications of it.
After all the concept of secondary alignment is not any better defined than that of a unique read. What exactly is a secondary alignment? At what point does an alignment become secondary and under what conditions won't get showns at all? FWIW I only have a superficial understanding of how it all works.
As for the original question I believe that bwa mem will produce a mapping quality of 0 if a read aligns in multiple locations. It used to work that way for a long time, even though technically there is no requirement or standard that would require that, it is a bwa specific convention. To filter for uniquely mapped reads pass the
-q 1
filtering flag to samtools view.It boils down to which definition of "uniquely mapping" you want to go by. I saw one on the samtools-help email list in the last week that would have meant filtering with
samtools view -q 40
.This won't work with output from bwa because it (always?) sticks secondary alignments into the XA tag of the primary alignment instead of recording them as secondary alignments in the samfile.