I have problem with one my BAMs---it appears to have invalid read groups.

Normally when I have such a problem, I remove all the read groups from the BAM header as follows:

samtools view -H your.bam | grep -v "^@RG" | samtools reheader - original.bam > new.bam

and then I would execute AddOrReplaceReadGroups from Picard:


I have tried this, and there must still be reads with a read group in the optional tags RG:Z:.

How to do I definitively remove all read groups from a BAM, including all of the reads?


1 Answer 1


You might have to manually strip those auxiliary tags off:

samtools view -h your.bam | grep -v "^@RG" | sed "s/\tRG:Z:[^\t]*//" | samtools view -bo your_fixed.bam -

The sed bit is searching for the aux tag and removing everything up to the next tab.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.