I have sam and bam files for the chimeric reads, which come from two different parts of the genome (For example, the first half of the read from part of Chromosome 1 and the second half of the read from part of Chromosome 3). I have removed the low mapping quality reads (MAPQ <= 30) and reads with high mismatches. This might result in some unpaired reads which need to be removed before further analysis. May I ask whether there is any way to remove the unpaired reads in sam/bam files? Thanks!
Asked
Active
Viewed 465 times
1 Answers
1
The -f option of samtools view is for flags and can be used to filter reads in bam/sam file matching certain criteria such as properly paired reads (0x2) :
samtools view -f 0x2 -b in.bam > out.bam
Paul Endymion
- 352
- 1
- 14
-
1Thanks. If I remove the low mapping quality reads and reads with high mismatches after the alignment, will the flags be updated? If they are not updated, there will possibly be unpaired reads even if I use flags for filtering in my point of view. – Wang Ming Jun 22 '22 at 06:06
-
That is a good question and there is a good change those flags won't be updated, it would need some testing. Here is a post on [seqanswers](https://www.seqanswers.com/forum/bioinformatics/bioinformatics-aa/20631-remove-reads-from-bam-whose-mate-has-already-been-filtered?t=24472) that might help you. – Paul Endymion Jun 22 '22 at 10:06