This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Genome Information From Bam

Hi!

Is their a way to know the genome build(ie., hg18 or hg19) to which the BAM file is aligned, other than manual inspection.

Thank you

genomics chip-seq bam

1 answer

get the dictionary in the sam header and test one chromosome

$ samtools view -H file.bam |\
 grep -E 'SN\:(chr)?22' |\
 awk '{if(index($0,"LN:51304566")!=0) printf("hg19\n"); else if(index($0,"LN:49691432")!=0) printf("hg18\n"); else printf("??\n");}'
hg19

Log in to answer this question.