<p>Not sure about samtools, but <a href="http://broadinstitute.github.io/picard/command-line-overview.html#AddOrReplaceReadGroups" rel="nofollow noreferrer">picard AddOrReplaceReadGroups</a> can clear existing read groups and write a new one.</p>

CC BY-SA 4.0
2022-06-14T16:10:26.050Z
2022-06-14T16:10:26.050Z
Cloudberry
<p>I have a bam file that contains two @RG lines:</p>
<pre><code>@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
</code></pre>
<p>I wish to replace it with one @RG line:</p>
<pre><code>@RG     ID:Foo SM:Foo        PL:Illumina     LB:Library.fa
</code></pre>
<p>What is the best way to do this?</p>
<p>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</p>

<sam><samtools>
Can I use samtools addreplacerg to replace multiple RG entries at the same time?
# Can I use samtools addreplacerg to replace multiple RG entries at the same time?

(Asked by: username_0 on 2022-06-14)

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

**Tags:** sam, samtools

---

## 1 answers

### Answer by username_1 on 2022-06-14. Score: 2 | Accepted answer

Not sure about samtools, but [picard AddOrReplaceReadGroups](http://broadinstitute.github.io/picard/command-line-overview.html#AddOrReplaceReadGroups) can clear existing read groups and write a new one.


---

