<p>Greetings all,</p>

<p>Let me start by saying I know how to add read groups to a <a href='http://samtools.sourceforge.net/SAM1.pdf'>BAM</a> file.  What I am looking for is the easiest way to do it.  This problem has been around for a while so I though I would see what neat tricks people are using. </p>

<p>Thanks  </p>

See [this](http://sourceforge.net/apps/mediawiki/samtools/index.php?title=SAM_protocol#Generate_merged_alignment).

The library information of each read group is kept in `rg.txt`

    perl -e 'print "@RG\tID:ga\tSM:hs\tLB:ga\tPL:Illumina\n@RG\tID:454\tSM:hs\tLB:454\tPL:454\n"' > rg.txt
    samtools merge -rh rg.txt - ga.bam 454.bam | samtools rmdup - - | samtools rmdup -s - aln.bam

Some discussion over [here](http://seqanswers.com/forums/showthread.php?t=4180).

<a href="http://www.ngcrawford.com/2012/04/17/python-adding-read-group-rg-tags-to-bam-or-sam-files/">Python: Adding Read Group (@RG) tags to BAM or SAM files:</a>

<a href="http://www.broadinstitute.org/gsa/wiki/index.php/Frequently_Asked_Questions#How_can_I_tell_if_my_BAM_file_has_read_group_and_sample_information.3F">How can I tell if my BAM file has read group and sample information</a>

Related post: https://www.biostars.org/p/43897/