diff --git a/bntseq.c b/bntseq.c index 6589434..465e383 100644 --- a/bntseq.c +++ b/bntseq.c @@ -179,17 +179,25 @@ bntseq_t *bns_restore(const char *prefix) if ((fp = fopen(strcat(strcpy(alt_filename, prefix), ".alt"), "r")) != 0) { // read .alt file if present char str[1024]; khash_t(str) *h; - int i, absent; + int c, i, absent; khint_t k; h = kh_init(str); for (i = 0; i < bns->n_seqs; ++i) { k = kh_put(str, h, bns->anns[i].name, &absent); kh_val(h, k) = i; } - while (fscanf(fp, "%s", str) == 1) { - k = kh_get(str, h, str); - if (k != kh_end(h)) - bns->anns[kh_val(h, k)].is_alt = 1; + i = 0; + while ((c = fgetc(fp)) != EOF) { + if (c == '\t' || c == '\n' || c == '\r') { + str[i] = 0; + if (str[0] != '@') { + k = kh_get(str, h, str); + if (k != kh_end(h)) + bns->anns[kh_val(h, k)].is_alt = 1; + } + while (c != '\n' && c != EOF) c = fgetc(fp); + i = 0; + } else str[i++] = c; // FIXME: potential segfault here } kh_destroy(str, h); fclose(fp); diff --git a/bwa.c b/bwa.c index 43d8a58..495b197 100644 --- a/bwa.c +++ b/bwa.c @@ -239,7 +239,12 @@ bwaidx_t *bwa_idx_load(const char *hint, int which) idx = calloc(1, sizeof(bwaidx_t)); if (which & BWA_IDX_BWT) idx->bwt = bwa_idx_load_bwt(hint); if (which & BWA_IDX_BNS) { + int i, c; idx->bns = bns_restore(prefix); + for (i = c = 0; i < idx->bns->n_seqs; ++i) + if (idx->bns->anns[i].is_alt) ++c; + if (bwa_verbose >= 3) + fprintf(stderr, "[M::%s] read %d ALT contigs\n", __func__, c); if (which & BWA_IDX_PAC) { idx->pac = calloc(idx->bns->l_pac/4+1, 1); err_fread_noeof(idx->pac, 1, idx->bns->l_pac/4+1, idx->bns->fp_pac); // concatenated 2-bit encoded sequence diff --git a/main.c b/main.c index db3c34f..77cace1 100644 --- a/main.c +++ b/main.c @@ -4,7 +4,7 @@ #include "utils.h" #ifndef PACKAGE_VERSION -#define PACKAGE_VERSION "0.7.10-r895-dirty" +#define PACKAGE_VERSION "0.7.10-r896-dirty" #endif int bwa_fa2pac(int argc, char *argv[]);