Question: Samtools: remove reads whose mate does not map as expected
0
gravatar for devinliao0918
5.9 years ago by
United States
devinliao091830 wrote:

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 • 1.5k views
ADD COMMENTlink modified 5.9 years ago by Devon Ryan95k • written 5.9 years ago by devinliao091830

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 REPLYlink modified 7 months ago by RamRS27k • written 5.9 years ago by Ashutosh Pandey12k

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 REPLYlink written 5.9 years ago by devinliao091830

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

ADD REPLYlink written 5.9 years ago by Ashutosh Pandey12k
1
gravatar for Devon Ryan
5.9 years ago by
Devon Ryan95k
Freiburg, Germany
Devon Ryan95k wrote:

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 COMMENTlink modified 5.9 years ago • written 5.9 years ago by Devon Ryan95k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 846 users visited in the last hour