This is a test version of Biostars. For the public version, visit https://www.biostars.org.
samtools addreplacerg gives error

I have bam files, created by bowtie2, to which I need to add read group information. The obvious tool is samtools addreplacerg from samtools v1.3.1 , but I always get an error. Below is the simplest command I tried, with the error. I have tried single quotes, double quotes, adding "@RG\t" to the text, and too many other variants to mention. All give the same message. Can anyone tell me what I am doing wrong?

samtools addreplacerg -r ID:S1 -o 3D7-D3-B3_S1_RGID.bam 3D7-D3-B3_S1_s.bam

[parse_args] The supplied RG line lacks an ID tag.

alignment bam samtools

In the meantime I created a header file for each bam file and used samtools merge -rh tempheader_S1 ... which worked fine. So the task is done, but I would still like to know why I couldn't use the more obvious command, which gives me other options for the ID flag than the input bam filename

Try this command it will surely work

samtools addreplacerg -r "@RG\tID:S1" -o 3D7-D3-B3_S1_RGID.bam 3D7-D3-B3_S1_s.bam 
  1. At the time this did not work, as I said in the list of things I tried.
  2. Since samtools 1.4 release this will work, as stated in the comment by John Marshall
  3. My actual mistake was failing to repeat '-r' before each element I was adding to the information, but thinking that a single '-r' was needed for the entire key:tag set. This is stated in my comment on John Marshall's answer

1 answer

This is a samtools bug that has since been fixed, though the fix has not yet appeared in a release.

This "lacks an ID tag" message was incorrectly triggered if -r ID:foo is the last -r option given. Normally the reason for adding an RG header is that you want to add lots of interesting information about the read group:

samtools addreplacerg -r ID:S1 -r LB:L1 -r SM:SAMPLE1 -o output foo.bam

and naturally you would put the most important bit (the primary key!) ID first :-), and so addreplacerg would complete successfully and not erroneously give this error.

Amusingly enough, this was fixed for ideological reasons not because this minor bug was noticed.

Thanks! I originally had:

samtools addreplacerg -r ID:S1 SM:S1 PL:ILLUMINA -o out.bam in.bam

without the repeated "-r", which gives the same "The supplied RG line lacks an ID tag", and that error message had me trying all sorts of incorrect fixes, including stripping down to just the ID tag

This fix subsequently appeared in the samtools 1.4 release, in 2017.

Log in to answer this question.