Question: Samtools: remove reads whose mate does not map as expected
0
gravatar for devinliao0918
4.8 years ago by
United States
devinliao091820 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.3k views
ADD COMMENTlink modified 4.8 years ago by Devon Ryan90k • written 4.8 years ago by devinliao091820

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 written 4.8 years ago by Ashutosh Pandey11k

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 4.8 years ago by devinliao091820

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

ADD REPLYlink written 4.8 years ago by Ashutosh Pandey11k
1
gravatar for Devon Ryan
4.8 years ago by
Devon Ryan90k
Freiburg, Germany
Devon Ryan90k 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 4.8 years ago • written 4.8 years ago by Devon Ryan90k
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: 2010 users visited in the last hour