I have a bam file that contains two @RG lines:

@RG     ID:Foo.Bar_L1.Foo   PU:Bar_L1.Foo SM:Foo        PL:Illumina     LB:Library.fa
@RG     ID:Foo.Bar_L2.Foo   PU:Bar_L2.Foo SM:Foo        PL:Illumina     LB:Library.fa

I wish to replace it with one @RG line:

@RG     ID:Foo SM:Foo        PL:Illumina     LB:Library.fa

What is the best way to do this?

samtools addreplacerg looks useful, but it looks like I can only affect one @RG per call, and I have no desire to write out the whole bam file twice


1 Answer 1


Not sure about samtools, but picard AddOrReplaceReadGroups can clear existing read groups and write a new one.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.