tool for bam soft clipping reads within bed file regions
3
0
Entering edit mode
8.7 years ago

What is a good tool that will take a bam file and a bed file describing regions where all aligned bases of aligned reads should be soft-clipped, but leave the aligned bases outside the regions intact and produce an output bam as a result?

bam clipping bed • 4.8k views
ADD COMMENT
5
Entering edit mode
8.7 years ago

I wrote PcrClipReads for a previous question on biostars

I'm not sure if it's really what you need...

ADD COMMENT
0
Entering edit mode

Brilliant! Bang on the money! Thanks Pierre!

ADD REPLY
1
Entering edit mode

I want to be the first author of whatever you'll write :-)

ADD REPLY
2
Entering edit mode
3.6 years ago

update 2021: there is now samtools ampliconclip samtools-ampliconclip http://www.htslib.org/doc/samtools-ampliconclip.html

Clip reads in a SAM compatible file based on data from a BED file.

ADD COMMENT
1
Entering edit mode
8.7 years ago

Home made solution, not tested:

## Clip reads overlapping target regions (note that -L option is slow as it doesn't use the index)
samtools view -F4 -L clippable.bed -h aln.bam | awk '{if($0 ~ "^@"){print $0} else {len=length($10); $6=len"S"; print $0}}' | samtools view -u - > clipped.tmp.bam

## Get reads *not* overlapping clippable regions (input should be sorted)
bedtools intersect -sorted -ubam -v -a aln.bam -b clippable.bed > unclipped.tmp.bam

## Put them back together
samtools merge aln2.bam clipped.tmp.bam unclipped.tmp.bam

You should decide how to handle reads partially overlapping the clippable regions and make sure these reads are not present in output twice.

ADD COMMENT

Login before adding your answer.

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