Is there a way to remove reads whose mate does not map as expected in a Bam file directly? I know we can run command line "samtools view -h -f 2 in.bam out.sam" to exclude the reads in the output sam file.
However, I wonder if I could exclude those reads directly from the in.bam file.
Hi, Take some time to go through the samtools manual. It will definitely help you. Samtools works for both sam and bam format and can generate output files in both sam and bam format. Also, you can't just change the original file with samtools. You will have to create a new sam or bam file using the original sam/bam file. The command mentioned above can be used to generate a new "bam" output if
-b
parameter is used. Check http://samtools.sourceforge.net/samtools.shtml.Thanks. I'm not sure whether "-b" works but will definitely try that.
I tried to read samtools manual carefully but failed to understand all of the details. I would like to see more examples.
It will work. But there will be a new bam file instead of modifying your original bam file.