diff --git a/.gitignore b/.gitignore index 0c0dca6..a7761c5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /build /dist .dep.inc +.Rproj.user diff --git a/src/BAMstructs.c b/src/BAMstructs.c index da28cbd..3ab164b 100644 --- a/src/BAMstructs.c +++ b/src/BAMstructs.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -28,12 +29,20 @@ int CheckIndexFile(char *fname) { if(fname == NULL) return 0; - char *idx = (char *)calloc(strlen(fname) + 5, sizeof(char)); - strcpy(idx, fname); - strcat(idx, ".bai"); + // Try to open the alignment file + htsFile *fp = hts_open(fname, "r"); + if (fp == NULL) { + return 0; + } - if(access( idx, F_OK ) == -1) + // Try to open the index + hts_idx_t *index = sam_index_load(fp, fname); + hts_close(fp); + + if (index == NULL) { return 0; + } + hts_idx_destroy(index); return 1; }