X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sam.c;fp=sam.c;h=b8e7350f3bebd70cd043bf54de02c77315092ee9;hb=9bd8cd7dd42efa091a9361bb06a29d1bead405ce;hp=e8e742c80649f583b16de8fb7b1519eca9a5af10;hpb=d89ec29105e36257fe27067d350ebbe879378c8d;p=samtools.git diff --git a/sam.c b/sam.c index e8e742c..b8e7350 100644 --- a/sam.c +++ b/sam.c @@ -1,4 +1,6 @@ #include +#include +#include "faidx.h" #include "sam.h" #define TYPE_BAM 1 @@ -152,3 +154,22 @@ int sampileup(samfile_t *fp, int mask, bam_pileup_f func, void *func_data) bam_destroy1(b); return 0; } + +char *samfaipath(const char *fn_ref) +{ + char *fn_list = 0; + fn_list = calloc(strlen(fn_ref) + 5, 1); + strcat(strcpy(fn_list, fn_ref), ".fai"); + if (access(fn_list, R_OK) == -1) { // fn_list is unreadable + if (access(fn_ref, R_OK) == -1) { + fprintf(stderr, "[samfaipath] fail to read file %s.\n", fn_ref); + } else { + fprintf(stderr, "[samfaipath] build FASTA index...\n"); + if (fai_build(fn_ref) == -1) { + fprintf(stderr, "[samfaipath] fail to build FASTA index.\n"); + free(fn_list); fn_list = 0; + } + } + } + return fn_list; +}