Reduce Bam File With Specific Loci In Bedfile
2
0
Entering edit mode
11.5 years ago
marcodpc ▴ 60

I want to reduce my bam file, obtaining a new bam file that contain

only loci in the bed file in input like

chr1 30498890 34983248

chr2 30398890 31483248

chr3 10492890 14983248

chr4 30492890 34283248

I try with:

samtools view -L test.bed test.bam | awk '$2 != 4 {print}'

and

intersectBed -abam file.bam -b test.bed

but the source bam file isn't reduce dimension.

How can I do ?

bam • 2.4k views
ADD COMMENT
1
Entering edit mode
11.5 years ago
marcodpc ▴ 60

I easily solved with BEDtools intersectBed -abam file.bam -b test.bed > reduced.bam

ADD COMMENT
0
Entering edit mode
11.5 years ago

You can use the bedOps utiltiy's tool sam2bed and then modify the command as

sam2bed <(samtools view -L test.bed test.bam | awk '$2 != 4 {print}') output.bed

ADD COMMENT

Login before adding your answer.

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