Hello,

I merged bam files using `samtools merge -r out.bam in1.bam in2.bam ...`

With `-r` option I got the RG tag for each read, as expected, good. However, the header of the merged bam does not have the @RG lines. So my question: Is there any off-the-shelf tools to add the @RG header lines once the reads have been tagged?

If not, the pipeline I have in mind goes along these lines:

 - Scan the bam file and collect all the different RG tags
 - Output the header of the bam file.
 - Append the RG tags to the header the
 - Reheader the original bam file.

Does it make sense?

Thanks

Dario
I ended up writing a little script for this, if anyone is interested it is here:

 - https://code.google.com/p/bioinformatics-misc/source/browse/trunk/addRGtoSAMHeader.py
 - https://github.com/dariober/bioinformatics-cafe/blob/master/addRGtoSAMHeader.py