From c3d45308e1e6439d92b656d5da812600313bc65d Mon Sep 17 00:00:00 2001 From: Heng Li Date: Tue, 1 Oct 2024 23:05:14 -0400 Subject: [PATCH] r259: change an assertion failure to warning When bonus score is too high, the assert doesn't work. --- align.c | 15 +++++++-------- main.c | 2 +- miniprot.h | 4 ++-- ntseq.c | 6 ++---- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/align.c b/align.c index a8da82f..1a7c508 100644 --- a/align.c +++ b/align.c @@ -78,7 +78,7 @@ static int32_t mp_align_seq(void *km, const mp_mapopt_t *opt, const ns_opt_t *ns } } -static void mp_extra_cal(mp_reg1_t *r, const mp_mapopt_t *opt, const uint8_t *nt, int32_t l_nt, const char *aa, int32_t qlen) +static void mp_extra_cal(mp_reg1_t *r, const mp_mapopt_t *opt, const uint8_t *nt, int32_t l_nt, const char *aa, int32_t qlen, int32_t has_spsc) { int32_t k, i, j, l, nl = 0, al = 0, ft, n_intron, has_stop; int32_t blen0, n_iden0, phase0, qs0, n_fs0, n_stop0, score0; @@ -186,13 +186,12 @@ static void mp_extra_cal(mp_reg1_t *r, const mp_mapopt_t *opt, const uint8_t *nt } // check errors if (nl != r->ve - r->vs || al != r->qe - r->qs) { - fprintf(stderr, "BUG! %d == %d? %d == %d? ", nl, (int)(r->ve - r->vs), al, r->qe - r->qs); - for (k = 0; k < e->n_cigar; ++k) - fprintf(stderr, "%d%c", e->cigar[k]>>4, NS_CIGAR_STR[e->cigar[k]&0xf]); - fputc('\n', stderr); + if (mp_verbose >= 2) + fprintf(stderr, "Warning: unknown issue with --spsc (%d!=%d or %d!=%d)\n", nl, (int)(r->ve - r->vs), al, r->qe - r->qs); + free(r->p); free(r->feat); + r->p = 0, r->feat = 0; } - assert(nl == r->ve - r->vs); - assert(al == r->qe - r->qs); + assert(has_spsc == 1 || (nl == r->ve - r->vs && al == r->qe - r->qs)); } static void mp_extra_gen(void *km, mp_reg1_t *r, mp_cigar_t *cigar, int32_t score) @@ -329,7 +328,7 @@ void mp_align(void *km, const mp_mapopt_t *opt, const mp_idx_t *mi, int32_t len, mp_extra_gen(km, r, &cigar, score); r->p->dist_stop = mp_extra_stop(r, nt, as, ae); r->p->dist_start = mp_extra_start(r, nt, as, ae); - mp_extra_cal(r, opt, &nt[r->vs - as], l_nt - (r->vs - as), &aa[r->qs], len); + mp_extra_cal(r, opt, &nt[r->vs - as], l_nt - (r->vs - as), &aa[r->qs], len, mi->nt->spsc != 0); if (ss) kfree(km, ss); kfree(km, nt); } diff --git a/main.c b/main.c index 402757f..176221c 100644 --- a/main.c +++ b/main.c @@ -190,7 +190,7 @@ int main(int argc, char *argv[]) if (set_I && !set_G) mp_mapopt_set_max_intron(&mo, mi->nt->l_seq); if (mp_verbose >= 3) mp_idx_print_stat(mi, mo.max_occ); if (fn_idx != 0) mp_idx_dump(fn_idx, mi); - if (fn_spsc != 0) mp_ntseq_read_spsc(mi->nt, fn_spsc); + if (fn_spsc != 0) mp_ntseq_read_spsc(mi->nt, fn_spsc, mo.io - mo.go); for (i = o.ind + 1; i < argc; ++i) { int32_t res = mp_map_file(mi, argv[i], &mo, n_threads); if (res != 0) { diff --git a/miniprot.h b/miniprot.h index f7f5909..d7e131e 100644 --- a/miniprot.h +++ b/miniprot.h @@ -3,7 +3,7 @@ #include -#define MP_VERSION "0.13-r258-dirty" +#define MP_VERSION "0.13-r259-dirty" #define MP_F_NO_SPLICE 0x1 #define MP_F_NO_ALIGN 0x2 @@ -162,7 +162,7 @@ void mp_idx_destroy(mp_idx_t *mi); int mp_idx_dump(const char *fn, const mp_idx_t *mi); mp_idx_t *mp_idx_restore(const char *fn); void mp_idx_print_stat(const mp_idx_t *mi, int32_t max_occ); -int32_t mp_ntseq_read_spsc(mp_ntdb_t *nt, const char *fn); +int32_t mp_ntseq_read_spsc(mp_ntdb_t *nt, const char *fn, int32_t max_sc); int32_t mp_map_file(const mp_idx_t *idx, const char *fn, const mp_mapopt_t *opt, int n_threads); diff --git a/ntseq.c b/ntseq.c index b2905ee..a7a9f59 100644 --- a/ntseq.c +++ b/ntseq.c @@ -232,9 +232,7 @@ int32_t mp_ntseq_name2id(const mp_ntdb_t *nt, const char *name) return k == kh_end(h)? -1 : kh_val(h, k); } -#define MP_MAX_SPSC 30 - -int32_t mp_ntseq_read_spsc(mp_ntdb_t *nt, const char *fn) +int32_t mp_ntseq_read_spsc(mp_ntdb_t *nt, const char *fn, int32_t max_sc) { gzFile fp; kstring_t str = {0,0,0}; @@ -274,7 +272,7 @@ int32_t mp_ntseq_read_spsc(mp_ntdb_t *nt, const char *fn) } if (i < 4) continue; // not enough fields if (score <= 0) continue; - if (score > MP_MAX_SPSC) score = MP_MAX_SPSC; + if (score > max_sc) score = max_sc; cid = mp_ntseq_name2id(nt, name); if (cid < 0 || type < 0 || strand == 0 || pos < 0) continue; // FIXME: give a warning! s = &nt->spsc[cid << 1 | (strand > 0? 0 : 1)];