text: user174: 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++?
  
  user37: #include "htslib/vcf.h"
  
  int main(int argc, char *argv[])
  {
      htsFile *fp;
      bcf_hdr_t *hdr;
      bcf_idpair_t *ctg;
      int i;
      if (argc == 1) {
          fprintf(stderr, "Usage: print-ctg <in.vcf>\n");
          return 1;
      }
      fp = vcf_open(argv[1], "r");
      hdr = vcf_hdr_read(fp);
      ctg = hdr->id[BCF_DT_CTG];
      for (i = 0; i < hdr->n[BCF_DT_CTG]; ++i)
          printf("%s\t%d\n", ctg[i].key, ctg[i].val->info[0]);
      bcf_hdr_destroy(hdr);
      vcf_close(fp);
      return 0;
  }
  
  On stability: this use has been in htslib forever. In general, functions/structs/variables in the public headers are meant to be stable. However, there is no guarantee that future versions will always keep the same APIs.
  
original_text: 174: <p>A typical VCF file has:</p>
  
  <pre><code>##contig=&lt;ID=chr1,length=248956422&gt;
  ##contig=&lt;ID=chr2,length=242193529&gt;
  </code></pre>
  
  <p>I would like to use <code>htslib</code> in C++ to read it. My attempt:</p>
  
  <pre><code>htsFile *fp = bcf_open("my.vcf", "r");
  bcf_hdr_t *hdr = bcf_hdr_read(fp); 
  </code></pre>
  
  <p>In <a href="https://github.com/samtools/htslib/blob/develop/htslib/vcf.h" rel="nofollow noreferrer">https://github.com/samtools/htslib/blob/develop/htslib/vcf.h</a>, I'm not able to find a function that can do that for me.</p>
  
  <p>How to read <code>chr1</code> and <code>248956422</code> in C++?</p>
   37: <pre class="lang-c prettyprint-override"><code>#include "htslib/vcf.h"
  
  int main(int argc, char *argv[])
  {
      htsFile *fp;
      bcf_hdr_t *hdr;
      bcf_idpair_t *ctg;
      int i;
      if (argc == 1) {
          fprintf(stderr, "Usage: print-ctg &lt;in.vcf&gt;\n");
          return 1;
      }
      fp = vcf_open(argv[1], "r");
      hdr = vcf_hdr_read(fp);
      ctg = hdr-&gt;id[BCF_DT_CTG];
      for (i = 0; i &lt; hdr-&gt;n[BCF_DT_CTG]; ++i)
          printf("%s\t%d\n", ctg[i].key, ctg[i].val-&gt;info[0]);
      bcf_hdr_destroy(hdr);
      vcf_close(fp);
      return 0;
  }
  </code></pre>
  
  <p>On stability: this use has been in htslib forever. In general, functions/structs/variables in the public headers are meant to be stable. However, there is no guarantee that future versions will always keep the same APIs.</p>
  