This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Get all unmapped read and mate in bam

Hello,

I have a .bam file and i am trying to extract all combinations of unmapped read and its mate from it.

One type is unmapped read and its unmapped mate which i extract using,

samtools view -bh -f 12

where, read is unmapped and mate is unmapped

samtools view -bh -f 8 -F 4

where, read is mapped and mate is unmapped

samtools view -bh -f 4 -F 8

I would like to know if i'm doing it right? or am i missing something.

Thank you.

aligner genomics dna

1 answer

All looks good, and you can check that with samtools flags:

samtools flags 12
0xc     12      UNMAP,MUNMAP

samtools flags 8
0x8     8       MUNMAP

samtools flags 4
0x4     4       UNMAP

then as you show for flags:

  -f INT   only include reads with all  of the FLAGs in INT present [0]
  -F INT   only include reads with none of the FLAGS in INT present [0]

the only comment I have is that when you produce BAM files the -h flag is not needed.

Log in to answer this question.