This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Add Information To @Rg Using Picard, Without Replacing Read Groups

Hello!

I'm using GATK to process some BAM files using their Best Practices. However, I forgot to add platform information under the @RG tag in the BAM header when I did the alignment (using BWA).

So, I've done dedup marking, indel realignment and the next step is base score recalibration. GATK won't do this since the platform information is missing from the BAM file. My first thought was to just use AddOrReplaceReadGroups from Picard, but as I understand it, this removes all other read groups in the BAM file and replace them with the one specified when running the program.

My question is: Can I just add platform information to the existing BAM file without removing the read groups in it (and replacing them with a single one)?

To clarify further, my header now looks something like this:

...    
@RG     ID:ABC0021    SM:SAMPLE123
@RG     ID:ABC0026    SM:SAMPLE123
@RG     ID:ABC0013    SM:SAMPLE123
...

And I want it to look something like this:

...    
@RG     ID:ABC0021    SM:SAMPLE123    PL:illumina    PU:1    LB:Lib1
@RG     ID:ABC0026    SM:SAMPLE123    PL:illumina    PU:1    LB:Lib1
@RG     ID:ABC0013    SM:SAMPLE123    PL:illumina    PU:1    LB:Lib1
...

Also with the platform info added to the reads.

Is this possible to achieve using Picard?

picard

2 answers

Ignore me if you have already figured out the solution otherwise you can try something like this:

samtools view -H $BAM | sed "s/SM:SAMPLE123/SM:SAMPLE123\tPL:ILLUMINA/g" | samtools reheader - $BAM 

No temporary files will be created.

Duplicate of How Can I Edit Some Rows In .Bam Header File?

I don't believe I'm asking exactly the same question since my problem is not just the header. I want to modify the header and make the corresponding changes in the information for each read.

as far as I can see the RG-ID of the reads would not change isn't it ?

My mistake, I thought that I also had to change something in the read information. Sorry and thank you for pointing me to the answer :)

Log in to answer this question.