1 module test.sam_iter;
2 
3 import std.stdio;
4 import std..string;
5 
6 import dhtslib.htslib.hts;
7 import dhtslib.htslib.hts_log;
8 import dhtslib.htslib.sam;
9 
10 int main()
11 {
12     writeln("Query c raw htslib");
13     int j = 0;
14     auto fn = toStringz("/Users/james/Documents/Development/blachlylab/funmap/ENCFF399AWI.bam");
15 
16     htsFile* fp = hts_open(fn, cast(immutable(char)*)"r".ptr);
17     writefln("fp    : %x", fp);
18     writefln("fp->fn: %s", fromStringz(fp.fn));
19     writefln("fp->fp: %x", fp.fp.bgzf);
20     writefln("fp->fmt %s", fp.format);
21 
22     auto idx= sam_index_load(fp, fn);
23     bam1_t *b = bam_init1();
24     hts_itr_t *iter;
25     int r;
26     if ((iter = sam_itr_queryi(idx, 0, 1_000_000, 2_000_000)) == null) {
27         hts_log_error(__FUNCTION__, "Failed to parse region");
28         return 1;
29     }
30     writefln("iter == %x", iter);
31     writefln("fp->fp: %x", fp.fp.bgzf);
32     while ((r = sam_itr_next(fp, iter, b)) >= 0) {
33         j++;
34     }
35 
36     writefln("Processed %d records with raw iter", j);
37 
38     hts_itr_destroy(iter);
39     bam_destroy1(b);
40     hts_close(fp);
41 
42     return 0;
43 }