Question: Picard Addreplacereadgroup Error: Rg Id Not Found In Header
1
gravatar for William
7.2 years ago by
William4.5k
Europe
William4.5k wrote:

I have a bam file which is missing read groups in the header.

Picard ValidateSamFile.jar gives : ERROR: Record 1, Read name M0VN6:402:2486, RG ID on SAMRecord not found in header: M0VN6 ...

So I try to use Picard AddOrReplaceReadGroups:

AddOrReplaceReadGroups.jar I= myBam.bam O= myBam.readGroupReplaced.bam SORT_ORDER=coordinate RGID=myBam RGLB=myBam RGPL=IONTORRENT RGSM=myBam RGPU=myBam

This gives the error:

ERROR: Record 1, Read name M0VN6:402:2486, RG ID on SAMRecord not found in header: M0VN6 ...

Why does Picard AddOrReplaceReadGroups crash about this? This is what I am trying to fix by using that function. Or do I misunderstand what AddOrReplaceReadGroups does?

What I get from the AddOrReplaceReadGroups discription is that it replaces all read groups in the Bam file with the one specified and assigns all reads to this read group.

picard bam • 7.4k views
ADD COMMENTlink written 7.2 years ago by William4.5k

You might want to have a look at the SAM format specifications

ADD REPLYlink written 7.2 years ago by Matt Shirley9.1k
4
gravatar for Matt Shirley
7.2 years ago by
Matt Shirley9.1k
Cambridge, MA
Matt Shirley9.1k wrote:

You have read group tags in each individual read (RGID). What you are telling Picard to do is add a conflicting @RG line to the header of your SAM file. You should just add the RG header line in the format:

@RG ID:id   PL:iontorrent   LB:library  SM:sample

This is all you need, since your reads already have RG ids. You should be able to verify this by looking at a read and finding the RG:Z:id tag.

ADD COMMENTlink written 7.2 years ago by Matt Shirley9.1k

Ok how do I ad a read group to the bam header? Do I manually copy and edit the header to a file and then use picard ReplaceSamHeader?

ADD REPLYlink written 7.2 years ago by William4.5k
1

That would be fine. You can do the following to append the @RG line to your BAM header:

echo '@RG\tID:id\tPL:iontorrent\tLB:library\tSM:sample' > rg
samtools view -H my.bam | cat - rg | header
samtools reheader header my.bam
ADD REPLYlink modified 5.7 years ago • written 7.2 years ago by Matt Shirley9.1k

There's a typo here, right? You don't want 'echo' there twice, and the read group fields have to be separated by a tab.

ADD REPLYlink written 5.7 years ago by seidel6.8k

Yes, thanks. I am not sure what happened but it's fixed now.

ADD REPLYlink written 5.7 years ago by Matt Shirley9.1k

i guess you are missing the '-e' option for echo, otherwise the tab wont be interpreted correctly.

ADD REPLYlink written 5.1 years ago by eva10
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1987 users visited in the last hour