Filter a bam file
3
3
Entering edit mode
10.0 years ago
slanciano ▴ 70

Hi,

I would like to know if is possible to filter a bam file with a bed file. I want to keep only all reads non-overlapped with my bed file. Do you know if there is a option or a way to do that with bedtools or samtools?

Thanks.

Sophie

bedtools sequence bed samtools bam • 7.7k views
ADD COMMENT
6
Entering edit mode
10.0 years ago

Although this has been already answered, just a quick note about bedtools vs samtools for reads filtering. I have always experienced slower times when using bedtools intersect compared to samtools view -L. I've sometimes even found samtools performing in half bedtools' time, so I try to favour the former as much as possible. if you would want the reads that overlap a bedfile I would definitely suggest using samtools instead of bedtools, but as the non-overlapping-reads are wanted it wouldn't work. in case the bedtools intersect filtering takes a long time or if you have to perform the same filter over and over again I would suggest to create a "negative" bedfile substracting your bedfile from a bedfile containing your genome's coordinates. this subtraction (which would be really fast and only performed once) would give you a bedfile with regions you'd like the reads to be at, therefore you could use it with samtools view -L as much as needed.

ADD COMMENT
0
Entering edit mode

Oh thank you very much for these useful advices

ADD REPLY
0
Entering edit mode

I like your idea of creating a negative bed file and then using bedtools subtract to remove those regions from bam.

ADD REPLY
3
Entering edit mode
10.0 years ago
komal.rathi ★ 4.1k

You will have to add -v to it.

bedtools intersect -abam reads.bam -b sample.bed -v > reads.nosample.bam
ADD COMMENT
0
Entering edit mode

Great !!! THANKS for your help !!

ADD REPLY
0
Entering edit mode
10.0 years ago
PoGibas 5.1k

Bedtools intersect works with both BED/GFF/VCF and BAM files as input.

ADD COMMENT
0
Entering edit mode

Yes but with bedtools intersect I don't find options to remove overlapped reads

ADD REPLY

Login before adding your answer.

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