In bsw2_stat(), fail to infer when no pairs are within boundaries

Just as we set r.failed and return early if there are no high-quality
read pairs at all, also do so if there are none within the calculated
boundaries.  This avoids returning avg=NAN std=NAN, which leads to
malloc(INFINITY) and a crash; fixes #108.
This commit is contained in:
John Marshall 2017-06-30 13:36:16 +01:00
parent 298284d754
commit bcb475cd03
1 changed files with 6 additions and 0 deletions

View File

@ -70,6 +70,12 @@ bsw2pestat_t bsw2_stat(int n, bwtsw2_t **buf, kstring_t *msg, int max_ins)
for (i = x = 0, r.avg = 0; i < k; ++i) for (i = x = 0, r.avg = 0; i < k; ++i)
if (isize[i] >= r.low && isize[i] <= r.high) if (isize[i] >= r.low && isize[i] <= r.high)
r.avg += isize[i], ++x; r.avg += isize[i], ++x;
if (x == 0) {
ksprintf(msg, "[%s] fail to infer the insert size distribution: no pairs within boundaries.\n", __func__);
free(isize);
r.failed = 1;
return r;
}
r.avg /= x; r.avg /= x;
for (i = 0, r.std = 0; i < k; ++i) for (i = 0, r.std = 0; i < k; ++i)
if (isize[i] >= r.low && isize[i] <= r.high) if (isize[i] >= r.low && isize[i] <= r.high)