This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to use Samtools to remove reads whose mate does not map as expected

Can anyone tell me how to remove reads whose mate does not map as expected? I know GATK is able to do this.

There is an option fixmate in samtools, but it could not be used to remove the reads I described above.

next-gen

2 answers

I might be wrong here, but looking at the sam flags;

2 - for read mapped in proper pair

So you can just keep the reads mapped in proper pair.

samtools view -f 2 foo.bam

Does this mean that I have to convert the Bam file into sam file first? I wonder whether there is a way to remove reads unmapped in proper pair.

You can input a BAM or SAM file:

samtools view -f 2 -o foo_proper-pairs.bam foo.bam
samtools view -f 2 -bS -o foo_proper-pairs.bam foo.sam

[this was meant to be a comment on the previous reply]

Log in to answer this question.