This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Should I re-index a bam after editing the read groups in the bam header?

I have an indexed bam file. I wish to update the sample ID (SM) field in the read groups (RG) entries in the bam header, which I do using samtools reheader. I was wondering if it is recommended to re-generate the bam index (.bai) file after editing the header. The bam index specifications do not mention read groups so I do not know if read groups metadata is included in the index.

Any insights will be appreciated

bam

1 answer

yes, the bytes have changed, the size of the file has changed: the indexes for random-access have changed, you must re-index.

Thank you! Does this also apply to cram files? I reckon the answer is yes for the same reason but I note that unlike bams, with crams it is possible to change the header in-place, so I wanted to be sure.

Log in to answer this question.