This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to change a BAM file so the chromosome identifier is "chr 1" not just "1"

Hi

I'm trying to set up some files to call Super Enhancers using ROSE. I think I have everything I need, however my BAM files may not be formatted properly. using samtools idxstats I realized that the BAM file I'm using lists chromosomes with their numbers (IE: "1") rather than a "chr 1" format which is needed for ROSE. Any idea how I can convert this BAM file to change the chr identifiers? Thanks for any help you can provide!

chip-seq

1 answer

Use samtools reheader:

reheader

    samtools reheader <in.header.sam> <in.bam>

    Replace the header in in.bam with the header in in.header.sam. This command is much faster than replacing the header with a BAM→SAM→BAM conversion.

For those reading this and wondering, "but what about the chromosome names for each read?!?", the answer is that those names aren't actually stored in a BAM file. Rather, alignments have chromosome index number associated with them and the name you see when you use samtools view is taken from the header.

This worked great, thanks!!

Log in to answer this question.