This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Soft-clipping read ends based on read group

Is it possible to clip (soft-clip preferably) n (for example, 3) nucleotides from both ends of reads in a bam file, but only for the reads with a certain defined read group?

I have merged bams for ancient DNA samples and the bams used for merging come from both UDG-treated and non-UDG-treated libraries. I would like to clip 3 nts from the ends of only the reads coming from non-UDG-treated libraries. These are marked by a label in Read Group: @RG LB:**dmg

So as a result I would like to have the same bam output but with the "dmg" labelled reads clipped

I hoped for gatk ClipReads or perhaps trimBam function of bamUtil to allow this but I haven't really found any clue as to whether and how that could be done.

Any tips appreciated.

Cheers, Martyna

ancient molecule at bam dna rg ends clipping damage

Hi,

Can you please share how did you clip both ends of the reads with ClipReads? Clipping form the start with -CT "1-3" for instance works just fine, but I can't figure out how to clip the opposite end as well (with reads having different lengths).

Thanks!

2 answers

split the bam per read group (samtools view --read-group xxx) , clip the read with your solution above, merge the groups (samtools merge).

I think you could use a multistep approach where you split your SAM file by readgroups with

samtools split

trim the relevant sample with either of the tools ClipRead or bamUtil trim (softclip is supported):

then merge the BAM files back together with

samtools merge 

@Pierre Lindenbaum, @Istvan Albert, thanks a lot! My brain has somehow fixed on trying to do this in a single step.

Log in to answer this question.