From 971df6ec5d54b1feea54dfb68e790bf3e31b9fe9 Mon Sep 17 00:00:00 2001 From: Heng Li Date: Fri, 2 Mar 2012 18:52:38 -0500 Subject: [PATCH] another bug in u8; allow **qry set to NULL --- ksw.c | 8 +++++--- ksw.h | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ksw.c b/ksw.c index 3f0fea8..15301c0 100644 --- a/ksw.c +++ b/ksw.c @@ -194,7 +194,7 @@ end_loop16: gmax = imax; te = i; // te is the end position on the target for (j = 0; LIKELY(j < slen); ++j) // keep the H1 vector _mm_store_si128(Hmax + j, _mm_load_si128(H1 + j)); - if (gmax + q->shift >= 255 || gmax + q->shift >= endsc) break; + if (gmax + q->shift >= 255 || gmax >= endsc) break; } S = H1; H1 = H0; H0 = S; // swap H0 and H1 } @@ -333,10 +333,12 @@ kswr_t ksw_align(int qlen, uint8_t *query, int tlen, uint8_t *target, int m, con kswr_t r, rr; kswr_t (*func)(kswq_t*, int, const uint8_t*, int, int, int); - if (*qry) q = *qry; - else *qry = q = ksw_qinit((xtra&KSW_XBYTE)? 1 : 2, qlen, query, m, mat); + if (qry == 0 || *qry == 0) + q = ksw_qinit((xtra&KSW_XBYTE)? 1 : 2, qlen, query, m, mat); + if (qry && *qry == 0) *qry = q; func = q->size == 2? ksw_i16 : ksw_u8; r = func(q, tlen, target, gapo, gape, xtra); + if (qry == 0) free(q); if ((xtra&KSW_XSTART) == 0 || ((xtra&KSW_XSUBO) && r.score < (xtra&0xffff))) return r; revseq(r.qe + 1, query); revseq(r.te + 1, target); // +1 because qe/te points to the exact end, not the position after the end q = ksw_qinit((*qry)->size, r.qe + 1, query, m, mat); diff --git a/ksw.h b/ksw.h index 66927b7..e1ecf8d 100644 --- a/ksw.h +++ b/ksw.h @@ -57,7 +57,8 @@ extern "C" { * and when the function returns, *qry will point to the profile, which can * be deallocated simply by free(). If one query is aligned against multiple * target sequences, *qry should be set to NULL during the first call and - * freed after the last call. + * freed after the last call. Note that qry can equal 0. In this case, the + * query profile will be deallocated in ksw_align(). */ kswr_t ksw_align(int qlen, uint8_t *query, int tlen, uint8_t *target, int m, const int8_t *mat, int gapo, int gape, int xtra, kswq_t **qry); -- 2.47.3