X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=kprobaln.c;h=04e526a1c3b639f29c8265f2c3f638c2c40abcb0;hb=0ccd9d36ebf35ce620a8248ecf4336c84065e6c0;hp=5201c1af75b9c24636ee67481b0461ab7713e7a1;hpb=fe9d679264cafa551db00fe309eea2858a536ee8;p=samtools.git diff --git a/kprobaln.c b/kprobaln.c index 5201c1a..04e526a 100644 --- a/kprobaln.c +++ b/kprobaln.c @@ -77,6 +77,8 @@ int kpa_glocal(const uint8_t *_ref, int l_ref, const uint8_t *_query, int l_quer const uint8_t *ref, *query; int bw, bw2, i, k, is_diff = 0, is_backward = 1, Pr; + if ( l_ref<=0 || l_query<=0 ) return 0; // FIXME: this may not be an ideal fix, just prevents sefgault + /*** initialization ***/ is_backward = state && q? 1 : 0; ref = _ref - 1; query = _query - 1; // change to 1-based coordinate @@ -87,7 +89,7 @@ int kpa_glocal(const uint8_t *_ref, int l_ref, const uint8_t *_query, int l_quer // allocate the forward and backward matrices f[][] and b[][] and the scaling array s[] f = calloc(l_query+1, sizeof(void*)); if (is_backward) b = calloc(l_query+1, sizeof(void*)); - for (i = 0; i <= l_query; ++i) { + for (i = 0; i <= l_query; ++i) { // FIXME: this will lead in segfault for l_query==0 f[i] = calloc(bw2 * 3 + 6, sizeof(double)); // FIXME: this is over-allocated for very short seqs if (is_backward) b[i] = calloc(bw2 * 3 + 6, sizeof(double)); } @@ -161,7 +163,7 @@ int kpa_glocal(const uint8_t *_ref, int l_ref, const uint8_t *_query, int l_quer double p = 1., Pr1 = 0.; for (i = 0; i <= l_query + 1; ++i) { p *= s[i]; - if (p < 1e-100) Pr += -4.343 * log(p), p = 1.; + if (p < 1e-100) Pr1 += -4.343 * log(p), p = 1.; } Pr1 += -4.343 * log(p * l_ref * l_query); Pr = (int)(Pr1 + .499);