Samtools: remove reads whose mate does not map as expected
1
0
Entering edit mode
10.3 years ago

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.

next-gen • 2.3k views
ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

It will work. But there will be a new bam file instead of modifying your original bam file.

ADD REPLY
1
Entering edit mode
10.3 years ago

In other words, you want to know if it's possible to edit a BAM file in-place with samtools. The answer is no (well, samtools will let you by just specifying the same file for input and output). While it's theoretically possible, it'd be a good way to shoot yourself in the foot if not done correctly (such as if the writer file pointer caught up to and overwrote where the reader file pointer was pointed) so it's not something anyone will recommend you frequently do.

ADD COMMENT

Login before adding your answer.

Traffic: 2147 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6