Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
htslib access (un)compressed offsets
#include <stdio.h>
#include <stdlib.h>
#include <htslib/hts.h>
#include <htslib/bgzf.h>
#include <hts_internal.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv)
{
// Code borrowed from htslib's function:
// *hts_idx_load_local(const char *fn)
//
// That is unfortunately not a public symbol for devs to use?:
//
// $ nm ../htslib/hts.o | grep load
// 000000000000aae0 T _hts_idx_load
// 000000000000ab60 T _hts_idx_load2
// 000000000000b550 t _hts_idx_load_core
uint8_t magic[4];
hts_idx_t *baifile = NULL;
hts_idx_t *idx = NULL;
BGZF *fp = bgzf_open("../htsget-aws/tests/data/test.bam", "r");
/*
The (simple) code below leads to:
hts_idx_t struct is: "pointer to incomplete class is not allowed"
*/
baifile = hts_idx_load("../htslib_bairead/tests/data/test.bai", HTS_FMT_BAI);
//printf("%zu\n", baifile->n);
// hts_idx_load_core is not exported:
//
// tinycount.c:42:13: warning: implicit declaration of function 'hts_idx_load_core' is invalid in C99
// [-Wimplicit-function-declaration]
// if (hts_idx_load_core(idx, fp, HTS_FMT_BAI) < 0)
//
// if (memcmp(magic, "BAI\1", 4) == 0)
// {
// uint32_t n;
// if (bgzf_read(fp, &n, 4) != 4)
// goto fail;
// if ((idx = hts_idx_init(n, HTS_FMT_BAI, 0, 14, 5)) == NULL)
// goto fail;
// if (hts_idx_load_core(idx, fp, HTS_FMT_BAI) < 0)
// goto fail;
// }
// return EXIT_SUCCESS;
// fail:
// bgzf_close(fp);
// hts_idx_destroy(idx);
// // free(meta);
// //return NULL;
// return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.