How to filter out chromosome regions from a .bam file
2
0
Entering edit mode
21 months ago
bertb ▴ 10

Hello,

I know that I can create a subset of a bam file for a desired region using samtools view:

samtools view -b UWNsub100k_int.bam chrXII:450000-470000 >  UWNsub100k_ribos.bam

What I want to do, however, is create a .bam file that excludes these regions. Perhaps something similar to -v for grep. Is there a samtools command for this?

Thanks,

RNA-Seq alignment • 1.7k views
ADD COMMENT
1
Entering edit mode

use bedtools complement to generate the complement of chrXII:450000-470000

ADD REPLY
6
Entering edit mode
21 months ago

samtools view -U file will output reads not selected by filters to file. This does not apply to regions specified on the command line (after the input file name) or with -M, as using the index to jump to the specified regions is separate from “filtering the reads” — however it does apply to -L.

So construct unwanted.bed from your regions to be excluded and use

samtools view -L unwanted.bed -U remaining.bam -o /dev/null UWNsub100k_int.bam
ADD COMMENT
0
Entering edit mode

This worked well. Thank you!

ADD REPLY
1
Entering edit mode
21 months ago

Samtools view -L will let you give samtools a bed files of the regions you want. I don't think there is a -v equivalent.

ADD COMMENT

Login before adding your answer.

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