This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Convert a BAM from GRCh37 to hg19?

Hello!

I was about to re-run the mapping step to create BAM files with hg19 coordinates, but realised that perhaps it's easier to convert the existing GRCh37 BAM files to hg19 coordinates, without having to re-run the aligner completely.

I looked around for ways to do this but only find methods for creating chain files e.g. hg19-h38.

I would greatly appreciate some help with this. :-]

Joel

grch37 hg19 bam

I was under the impression that chrM was actually different between the two?

1 answer

I ended up using samtools reheader, as the chromosomes seemed similar enough. I ended up wasting some hours thinking reheader ONLY changed the header section. I wish the samtools documentation was better... turns out reheader changes the chromosome names everywhere in the file.

Thanks for your help though, I found salvation much faster thanks to you :-]

My command in case someone is curious:

samtools reheader -c "sed -e 's/SN:\([0-9XY]\+\)/SN:chr\1/' -e 's/SN:MT/SN:chrM/'" h37.bam > hg19.bam

Correction: I changed the * to \+, elsewise lots of things went wrong... sorry!

Log in to answer this question.