Created
August 20, 2015 15:00
-
-
Save andrewyatz/b6624c2fdb78ddfe792d to your computer and use it in GitHub Desktop.
Small bit of XS to retrieve the headers from a tabix indexed file such as a VCF file. Method returns an array reference.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SV* | |
tabix_headers(t) | |
tabix_t *t | |
PREINIT: | |
ti_iter_t iter; | |
const char *s; | |
int len; | |
CODE: | |
if (ti_lazy_index_load(t) < 0) { | |
fprintf(stderr,"[tabix] failed to load the index file.\n"); | |
return; | |
} | |
const ti_conf_t *idxconf = ti_get_conf(t->idx); | |
iter = ti_query(t, 0, 0, 0); | |
AV *av = newAV(); | |
while ((s = ti_read(t, iter, &len)) != 0) { | |
if ((int)(*s) != idxconf->meta_char) break; | |
av_push(av, newSVpv(s,0)); | |
} | |
ti_iter_destroy(iter); | |
RETVAL=newRV_noinc(av); | |
OUTPUT: | |
RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment