text: user9222: 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
  
  user15489: Not sure about samtools, but picard AddOrReplaceReadGroups can clear existing read groups and write a new one.
  
original_text: 9222: <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>
   15489: <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>
  