Question: tool for bam soft clipping reads within bed file regions
0
gravatar for 14134125465346445
2.8 years ago by
United Kingdom
141341254653464453.4k wrote:

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 bed clipping • 1.3k views
ADD COMMENTlink modified 2.8 years ago by dariober9.7k • written 2.8 years ago by 141341254653464453.4k
5
gravatar for Pierre Lindenbaum
2.8 years ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum115k wrote:

I wrote PcrClipReads for a previous question on biostars

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

ADD COMMENTlink modified 12 weeks ago by RamRS19k • written 2.8 years ago by Pierre Lindenbaum115k

Brilliant! Bang on the money! Thanks Pierre!

ADD REPLYlink modified 12 weeks ago by RamRS19k • written 2.8 years ago by 141341254653464453.4k
1

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

ADD REPLYlink modified 12 weeks ago by RamRS19k • written 2.8 years ago by Pierre Lindenbaum115k
0
gravatar for dariober
2.8 years ago by
dariober9.7k
Glasgow - UK
dariober9.7k wrote:

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 COMMENTlink modified 12 weeks ago by RamRS19k • written 2.8 years ago by dariober9.7k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1608 users visited in the last hour