# How to rename Read Groups

I periodically run into problems with Read Groups. I am in a desperate need for a tool that would allow me to fix them.

This time, when I was mapping reads, I formatted all the information in the Read Groups right, but the name of the read groups (which I, unfortunately, chose to be RUN_LANE, not realizing that some of the samples were on the same lane in the same run). And once I tried to do a joint genotyping, freebayes got mad at me.

So, is there an easy way to rename read groups?

Piccard tools' AddOrReplaceReadGroups won't do the job as some of the samples were multiplexed on different lanes/runs and this information should be preserved.

Basically, I need all bam files with read groups like this

@RG     ID:HJ5FNDSXY_L2 SM:WW5-6        PL:ILLUMINA     LB:WW5-6
@RG     ID:HJ5JVDSXY_L2 SM:WW5-6        PL:ILLUMINA     LB:WW5-6
@RG     ID:HJHGLDSXY_L4 SM:WW5-6        PL:ILLUMINA     LB:WW5-6


to change to something like (so the ID string will be unique for every combination of sample, run and library)

@RG     ID:WW5-6_HJ5FNDSXY_L2 SM:WW5-6        PL:ILLUMINA     LB:WW5-6
@RG     ID:WW5-6_HJ5JVDSXY_L2 SM:WW5-6        PL:ILLUMINA     LB:WW5-6
@RG     ID:WW5-6_HJHGLDSXY_L4 SM:WW5-6        PL:ILLUMINA     LB:WW5-6


There is a similar question asking about adjustments of read groups using pysam. That is actually quite close to what I need, but it's rather hacky solution I would rather avoid if I can.

I also vaguely remember seeing a tool for fixing read groups problems while ago on Twitter, but I can not find it now and I don't know if I just made it up or not.

• The most annoying part of this problem is that the lowest effort solution is to remap the reads with corrected RG IDs (but I always feel bad for burning computational hours in vein). Jan 15 at 14:37