static inline GtContfind find_exact_overlaps(struct Data *d, bool use_kmp, GtUword min_length, bool find_nonmaximal) { GtContfind retval; if (d->u->seqnum == d->v->seqnum && d->v->direct) { if (!(d->mode == GT_OVLFIND_SPM || d->mode == GT_OVLFIND_ALL)) return GT_CONTFIND_EQ; if (use_kmp) retval = gt_ovlfind_kmp(d->u->seq, d->u->len, d->u->pi, NULL, 0, NULL, d->mode, min_length, find_nonmaximal, call_spmproc, d); else retval = gt_ovlfind_bf(d->u->seq, d->u->len, NULL, 0, d->mode, min_length, find_nonmaximal, call_spmproc, d); } else { if (use_kmp) retval = gt_ovlfind_kmp(d->u->seq, d->u->len, d->u->pi, d->v->seq, d->v->len, d->v->pi, d->mode, min_length, find_nonmaximal, call_spmproc, d); else retval = gt_ovlfind_bf(d->u->seq, d->u->len, d->v->seq, d->v->len, d->mode, min_length, find_nonmaximal, call_spmproc, d); } return retval; }
int gt_ovlfind_kmp_unit_test(GtError *err) { int had_err = 0; GtArray *a; struct GtOvlfindKmpResult *r; GtContfind retval; gt_kmp_t *u_pi, *v_pi; /*@i1@*/ gt_error_check(err); had_err = gt_kmp_preproc_unit_test(err); if (had_err != 0) return had_err; a = gt_array_new(sizeof (struct GtOvlfindKmpResult)); /* u suffix == v prefix */ if (!had_err) { gt_array_reset(a); u_pi = gt_kmp_preproc("aacgcacctg", 10UL); v_pi = gt_kmp_preproc("acctgatttc", 10UL); retval = gt_ovlfind_kmp("aacgcacctg", 10UL, u_pi, "acctgatttc", 10UL, v_pi, GT_OVLFIND_PROPER_SPM, 1UL, false, ovlfind_kmp_test_save, a); gt_ensure(had_err, retval == GT_CONTFIND_NO); gt_ensure(had_err, gt_array_size(a) == 1UL); GT_OVLFIND_KMP_EXPECT_RESULT(0UL, true, 5UL); gt_free(u_pi); gt_free(v_pi); } /* v suffix == u prefix */ if (!had_err) { gt_array_reset(a); u_pi = gt_kmp_preproc("atccgtgacgtg", 12UL); v_pi = gt_kmp_preproc("aagaagaatccg", 12UL); retval = gt_ovlfind_kmp("atccgtgacgtg", 12UL, u_pi, "aagaagaatccg", 12UL, v_pi, GT_OVLFIND_ALL, 1UL, false, ovlfind_kmp_test_save, a); gt_ensure(had_err, retval == GT_CONTFIND_NO); gt_ensure(had_err, gt_array_size(a) == 1UL); GT_OVLFIND_KMP_EXPECT_RESULT(0UL, false, 5UL); gt_free(u_pi); gt_free(v_pi); } /* no overlap */ if (!had_err) { gt_array_reset(a); u_pi = gt_kmp_preproc("aac", 3UL); v_pi = gt_kmp_preproc("tgc", 3UL); retval = gt_ovlfind_kmp("aac", 3UL, u_pi, "tgc", 3UL, v_pi, GT_OVLFIND_PROPER_SPM, 1UL, false, ovlfind_kmp_test_save, a); gt_ensure(had_err, retval == GT_CONTFIND_NO); gt_ensure(had_err, gt_array_size(a) == 0UL); gt_free(u_pi); gt_free(v_pi); } /* u suffix of v */ if (!had_err) { gt_array_reset(a); u_pi = gt_kmp_preproc("acagc", 5UL); v_pi = gt_kmp_preproc("gtacagc", 7UL); retval = gt_ovlfind_kmp("acagc", 5UL, u_pi, "gtacagc", 7UL, v_pi, GT_OVLFIND_SPM, 1UL, false, ovlfind_kmp_test_save, a); gt_ensure(had_err, gt_array_size(a) == 1UL); gt_ensure(had_err, retval == GT_CONTFIND_OFF); GT_OVLFIND_KMP_EXPECT_RESULT(0UL, false, 5UL); gt_array_reset(a); retval = gt_ovlfind_kmp("acagc", 5UL, u_pi, "gtacagc", 7UL, v_pi, GT_OVLFIND_PROPER_SPM, 1UL, false, ovlfind_kmp_test_save, a); gt_ensure(had_err, retval == GT_CONTFIND_U); gt_ensure(had_err, gt_array_size(a) == 0UL); gt_array_reset(a); retval = gt_ovlfind_kmp("acagc", 5UL, u_pi, "gtacagc", 7UL, v_pi, GT_OVLFIND_CNT, 1UL, false, ovlfind_kmp_test_save, a); gt_ensure(had_err, gt_array_size(a) == 0UL); gt_ensure(had_err, retval == GT_CONTFIND_U); gt_array_reset(a); retval = gt_ovlfind_kmp("acagc", 5UL, u_pi, "gtacagc", 7UL, v_pi, GT_OVLFIND_ALL, 1UL, false, ovlfind_kmp_test_save, a); gt_ensure(had_err, gt_array_size(a) == 1UL); gt_ensure(had_err, retval == GT_CONTFIND_U); GT_OVLFIND_KMP_EXPECT_RESULT(0UL, false, 5UL); gt_free(u_pi); gt_free(v_pi); } /* v suffix of u */ if (!had_err) { gt_array_reset(a); u_pi = gt_kmp_preproc("gtacagc", 7UL); v_pi = gt_kmp_preproc("acagc", 5UL); retval = gt_ovlfind_kmp("gtacagc", 7UL, u_pi, "acagc", 5UL, v_pi, GT_OVLFIND_SPM, 1UL, false, ovlfind_kmp_test_save, a); gt_ensure(had_err, retval == GT_CONTFIND_OFF); gt_ensure(had_err, gt_array_size(a) == 1UL); GT_OVLFIND_KMP_EXPECT_RESULT(0UL, true, 5UL); gt_array_reset(a); retval = gt_ovlfind_kmp("gtacagc", 7UL, u_pi, "acagc", 5UL, v_pi, GT_OVLFIND_PROPER_SPM, 1UL, false, ovlfind_kmp_test_save, a); gt_ensure(had_err, retval == GT_CONTFIND_V); gt_ensure(had_err, gt_array_size(a) == 0UL); gt_free(u_pi); gt_free(v_pi); } /* u prefix of v */ if (!had_err) { gt_array_reset(a); u_pi = gt_kmp_preproc("ctat", 4UL); v_pi = gt_kmp_preproc("ctatacagg", 9UL); retval = gt_ovlfind_kmp("ctat", 4UL, u_pi, "ctatacagg", 9UL, v_pi, GT_OVLFIND_SPM, 1UL, false, ovlfind_kmp_test_save, a); gt_ensure(had_err, retval == GT_CONTFIND_OFF); gt_ensure(had_err, gt_array_size(a) == 1UL); GT_OVLFIND_KMP_EXPECT_RESULT(0UL, true, 4UL); gt_array_reset(a); retval = gt_ovlfind_kmp("ctat", 4UL, u_pi, "ctatacagg", 9UL, v_pi, GT_OVLFIND_PROPER_SPM, 1UL, false, ovlfind_kmp_test_save, a); gt_ensure(had_err, retval == GT_CONTFIND_U); gt_ensure(had_err, gt_array_size(a) == 0UL); gt_free(u_pi); gt_free(v_pi); } /* v prefix of u */ if (!had_err) { gt_array_reset(a); u_pi = gt_kmp_preproc("ctatacagg", 9UL); v_pi = gt_kmp_preproc("ctat", 4UL); retval = gt_ovlfind_kmp("ctatacagg", 9UL, u_pi, "ctat", 4UL, v_pi, GT_OVLFIND_SPM, 1UL, false, ovlfind_kmp_test_save, a); gt_ensure(had_err, retval == GT_CONTFIND_OFF); gt_ensure(had_err, gt_array_size(a) == 1UL); GT_OVLFIND_KMP_EXPECT_RESULT(0UL, false, 4UL); gt_array_reset(a); retval = gt_ovlfind_kmp("ctatacagg", 9UL, u_pi, "ctat", 4UL, v_pi, GT_OVLFIND_PROPER_SPM, 1UL, false, ovlfind_kmp_test_save, a); gt_ensure(had_err, retval == GT_CONTFIND_V); gt_ensure(had_err, gt_array_size(a) == 0UL); gt_free(u_pi); gt_free(v_pi); } /* identical sequences */ if (!had_err) { gt_array_reset(a); u_pi = gt_kmp_preproc("acagc", 5UL); retval = gt_ovlfind_kmp("acagc", 5UL, u_pi, "acagc", 5UL, u_pi, GT_OVLFIND_SPM, 1UL, false, ovlfind_kmp_test_save, a); gt_ensure(had_err, retval == GT_CONTFIND_OFF); gt_ensure(had_err, gt_array_size(a) == 2UL); GT_OVLFIND_KMP_EXPECT_RESULT(0UL, true, 5UL); GT_OVLFIND_KMP_EXPECT_RESULT(1UL, false, 5UL); gt_array_reset(a); retval = gt_ovlfind_kmp("acagc", 5UL, u_pi, "acagc", 5UL, u_pi, GT_OVLFIND_PROPER_SPM, 1UL, false, ovlfind_kmp_test_save, a); gt_ensure(had_err, retval == GT_CONTFIND_EQ); gt_ensure(had_err, gt_array_size(a) == 0UL); gt_free(u_pi); } /* find_nonmaximal */ if (!had_err) { gt_array_reset(a); u_pi = gt_kmp_preproc("aacagtagtagt", 12UL); v_pi = gt_kmp_preproc("agtagtagttaa", 12UL); retval = gt_ovlfind_kmp("aacagtagtagt", 12UL, u_pi, "agtagtagttaa", 12UL, v_pi, GT_OVLFIND_SPM, 1UL, false, ovlfind_kmp_test_save, a); gt_ensure(had_err, retval == GT_CONTFIND_OFF); gt_ensure(had_err, gt_array_size(a) == 2UL); GT_OVLFIND_KMP_EXPECT_RESULT(0UL, true, 9UL); GT_OVLFIND_KMP_EXPECT_RESULT(1UL, false, 2UL); gt_array_reset(a); retval = gt_ovlfind_kmp("aacagtagtagt", 12UL, u_pi, "agtagtagttaa", 12UL, v_pi, GT_OVLFIND_SPM, 1UL, true, ovlfind_kmp_test_save, a); gt_ensure(had_err, gt_array_size(a) == 5UL); gt_ensure(had_err, retval == GT_CONTFIND_OFF); gt_free(u_pi); gt_free(v_pi); } /* min_length */ if (!had_err) { gt_array_reset(a); u_pi = gt_kmp_preproc("aggaccagtagt", 12UL); v_pi = gt_kmp_preproc("agtagttactac", 12UL); retval = gt_ovlfind_kmp("aggaccagtagt", 12UL, u_pi, "agtagttactac", 12UL, v_pi, GT_OVLFIND_SPM, 1UL, true, ovlfind_kmp_test_save, a); gt_ensure(had_err, retval == GT_CONTFIND_OFF); gt_ensure(had_err, gt_array_size(a) == 2UL); gt_array_reset(a); retval = gt_ovlfind_kmp("aggaccagtagt", 12UL, u_pi, "agtagttactac", 12UL, v_pi, GT_OVLFIND_SPM, 4UL, true, ovlfind_kmp_test_save, a); gt_ensure(had_err, gt_array_size(a) == 1UL); gt_ensure(had_err, retval == GT_CONTFIND_OFF); gt_free(u_pi); gt_free(v_pi); } gt_array_delete(a); return had_err; }