How to subtract a portion of a bam file from the large bam file of the same sample?
1
0
Entering edit mode
8.3 years ago
kirannbishwa01 ★ 1.6k

The question might seem confusing, but I really have this problem.

I have an aligned.bam file for a sample. I want to separate the bam file: 1) above a certain coverage 2) and bam file not in that coverage range.

I have selected the aligned reads above a certain coverage using: samtools coverage > creation bed file > reads in this bed region i.e selected.bam. Now, I want to get the portion of the bam file that is not in the selected.bam. So, basically its a complement of the selected.bam

Step01: Aligned.bam > calculate coverage (bed file) > select region above certain coverage (selected.bed) Step 02: Aligned.bam selected.bed (filter) > selected.bam

Step 03: How to get unselected.bam?

Note: I cannot use complement of the bed file because an aligned read may span the bed boundary. Using the complement of the bed file will cause some of the reads to be selected in both the categories.

bam alignment samtools merge bedtools • 2.7k views
ADD COMMENT
3
Entering edit mode
8.3 years ago

use -U in the samtools view command. That way you generate both files at the same time. :

-U FILE
  

Write alignments that are not selected by the various filter options to FILE. When this option is used, all alignments (or all alignments intersecting the regions specified) are written to either the output file or this file, but never both.

ADD COMMENT

Login before adding your answer.

Traffic: 1982 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