Skip to content

addreplacerg overwrite_all doesn't overwrite the old RG tags #856

Closed

Description

@silvewheat

I wanted to use samtools(v1.8) addreplacerg to replace the RG tags in a cram file.
My old RG tag is

@RG     ID:NG01Ga       LB:NG01Ga       PL:ILLUMINA     SM:NG01Ga
@RG     ID:NG01Gb       LB:NG01Gb       PL:ILLUMINA     SM:NG01Gb

So, I run this command in RedHat system.

samtools addreplacerg -m overwrite_all -r '@RG\tID:NG01G\tLB:NG01G\tPL:ILLUMINA\tSM:NG01G' --reference ASM.fa -O CRAM -o NG01G_reheader.cram -@ 5 NG01G.cram

Then, in the new cram file, there're three RG tags, the new one is appended, not replace the old.

@RG     ID:NG01Ga       LB:NG01Ga       PL:ILLUMINA     SM:NG01Ga
@RG     ID:NG01Gb       LB:NG01Gb       PL:ILLUMINA     SM:NG01Gb
@RG     ID:NG01G        LB:NG01G        PL:ILLUMINA     SM:NG01G

But, I have used the overwrite mode.
Is this normal?

Activity

  1. jkbonfield commented on May 30, 2018

    @jkbonfield
    Contributor

    Initially I was thinking this would be CRAM specific, given the description and because cram stores RG tags in a different way (they're an index into the Nth header record instead of an auxiliary tag string).

    However I get the same effect with BAM files. I think it's just a documentation thing. It is adding or replacing RG lines in records, but it cannot replace an RG line in the header. Indeed in the simplest example with a single RG line with ID:1#49 I tried replacing it via -r ID:1#49 -r SM:z and it tells me:

    [init] ID of new RG line specified conflicts with that of an existing header RG line. Overwrite not yet implemented.
    

    So yes, sadly it is normal! I'll leave this open though as it's a useful feature request to actually replace RG tags in the header too as the name of the command hints at.

    Until then, you can try outputting to stdout and feed that to a samtools reheader command with a corrected header.

  2. huizhen2014 commented on Nov 8, 2018

    @huizhen2014

    I was also confused addreplacerg did not work for replacing, but just appending a new RG with r parameter. I also tried the -R, which always outputed a message "RG ID supplied does not exist in header. Supply full @rg line with -r instead?", thought I had the same RG ID in bam file. So, I am afraid I gonna try the pircard to replace RG info.

  3. huizhen2014 commented on Nov 8, 2018

    @huizhen2014

    Just now, I have tried with picard AddOrReplaceReadGroups, it worked and directly replaced the old RG info

  4. jmarshall commented on Jul 17, 2019

    @jmarshall
    Member

    We recently ran afoul of this with BAM files in our pipeline. Here is an example with a SAM file replacerg.sam:

    $ cat replacerg.sam 
    @HD	VN:1.6
    @SQ	SN:ref	LN:45
    @RG	ID:foo	SM:fred
    r001	0	ref	29	17	5M	*	0	0	TAGGC	qqqqq	RG:Z:foo
    r002	0	ref	37	30	9M	*	0	0	CAGCGGCAT	qqqqqqqqq	RG:Z:foo
    $ samtools addreplacerg -r ID:bar -r SM:barney replacerg.sam
    @HD	VN:1.6
    @SQ	SN:ref	LN:45
    @RG	ID:foo	SM:fred
    @RG	ID:bar	SM:barney
    r001	0	ref	29	17	5M	*	0	0	TAGGC	qqqqq	RG:Z:bar
    r002	0	ref	37	30	9M	*	0	0	CAGCGGCAT	qqqqqqqqq	RG:Z:bar
    

    As addreplacerg otherwise removes any trace of foo, it seems sensible to completely replace the @RG ID:foo line too. Hopefully this will be easier with the new header API…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions