Well, 0x8 is incorrect, which is the source of the problem here.
Hi,
I'm kind of newbie about BWA and I have a trivial question.
I performed an alignment with paired reads and now I'm trying to extract some of them with samtools.
- mapped reads whose mate is unmapped (
samtools view -f4 -F8 in.bam) - unmapped reads whose mate is mapped (
samtools view -f8 -F4 in.bam)
The problem is that I did expect that the same number of reads in both files (they are complementary, aren't they?). But I obtained more reads among the unmapped.
I can't find any explanation. thanks in advance
1 answer
The flags are weird but may not be incorrect. There is a big "hole" in the spec there that says:
Bit 0x4 is the only reliable place to tell whether the read is unmapped. If 0x4 is set, no
assumptions can be made about RNAME, POS, CIGAR, MAPQ, bits 0x2, 0x10, 0x100 and
0x800, and the bit 0x20 of the previous read in the template.
So what that says is that if the read is unmapped the rest of the fields may still be set but we need to ignore that since the information may be incorrect. Now if one were to match the flags directly they would get a different result. I often seen tools completely ignore the above and assume that if the read is unmapped the rest of the fields will be changed accordingly. That is not the case.
To the OP: I think the correct course of action is to first remove all reads where both the read and the mate are unmapped. Then on the remaining reads the flags will work correctly. We have every right to complain we shouldn't need to do that - I mean c'mon having an unmapped read that is listed as mapping to say position xyz with a certain mapping quality - yes that actually can happen.
that could be - I have some duties right now so I can't look into it more deeply - from experience I found that when counts don't match up it is almost always because the filtering ignores the 0x4 state and matches the flags exactly as we tell it to. But those flags can actually be set 'incorrectly'.
Log in to answer this question.
FYI,
-f 4 -F 8will give unmapped reads with mapped mates and-f 8 -F 4will give mapped reads with unmapped mates.What's the output of
samtools view -c -f 0x800 in.bamOh sorry..in the post I inverted the code for mapped/unmapped!!
However ..with
-f 0x800I obtain 0.. but I don't know the meaningBWA can produce chimeric/non-linear alignments, which will have the 0x800 bit in the flag set. I had hoped that that was the cause of the mismatch, but I guess not.
BTW, what sort of difference in number of reads are we talking about here. Just 1 or two or a significant number?
the unmapped mates are 1453574; the mapped mates 1418724. so I have a difference of 34850..quite significant, I think.
did you filter the BAM after aligning with bwa ?
I don't think. I did the alignment and then I converted sam in bam
That's it.
So.. looking at the unmapped file I found (for example) this couple of reads:
I completely miss the point..why are they among the unmapped mates?
I will try to edit this, because I can't submit new post (I'm a new user)
that's the version
and that's the code
thanks a lot
Those flags make absolutely no sense. What's the exact command you gave to bwa? Also, what version did you use.
You'd probably be better off using a more recent version and seeing if the incorrectly unset 0x8 bit in the flag is set properly there.
Does anybody know how I can get unmapped reads with unmapped mates?
Will
samtools view -f8 -F8 in.bamwork?You should ask a new question to get input from more people. Your comment will only reach the people in this thread.
That being said, the answer is ;-) :
You need to select for both
UNMAPandMUNMAPso-f 4 -f 8ought to do it.