This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to extract and save the header of .bam,vcf and idat files in a text file

Can someone help with how to extract the header data (metainfo) from these three files: .bam, vcf and idat files.

I want to be able to extract these medatadata info and save each in a text file. I hope someone can help me with the how to.

Thanks!

bam ida vcf extract header

2 answers

## BAM:
samtools view -H file.bam > header_BAM.txt

## VCF:
awk '{if(/^#/)print;else exit}' file.vcf > header_VCF.txt

For idat I don't know.

You can use my bcftools plugin gtc2vcf as follows:

bcftools +gtc2vcf --idat file.idat

There is header information both at the beginning and the end of an IDAT file though

Log in to answer this question.