A typical VCF file has:
##contig=<ID=chr1,length=248956422>
##contig=<ID=chr2,length=242193529>
I would like to use htslib in C++ to read it. My attempt:
htsFile *fp = bcf_open("my.vcf", "r");
bcf_hdr_t *hdr = bcf_hdr_read(fp);
In https://github.com/samtools/htslib/blob/develop/htslib/vcf.h, I'm not able to find a function that can do that for me.
How to read chr1 and 248956422 in C++?
bcf_hdr_parse_linedoes that. It returns an object x of typebcf_hrec_t*, for whichstrcmp(x->key, "contig") == 0)for your lines. You can then access thex->keysandx->vals. Untested. – Konrad Rudolph Feb 28 '18 at 10:49