Пример #1
0
static void match_naive_inexact(const Chars_holder *P, const Chars_holder *S,
		int max_nmis, int min_nmis, int fixedP, int fixedS)
{
	int Pshift, // position of pattern left-most char relative to the subject
	    n2, // 1 + position of pattern right-most char relative to the subject
	    min_Pshift, max_n2, nmis;
	const BytewiseOpTable *bytewise_match_table;

	if (P->length <= 0)
		error("empty pattern");
	bytewise_match_table = _select_bytewise_match_table(fixedP, fixedS);
	min_Pshift = P->length <= max_nmis ? 1 - P->length : -max_nmis;
	max_n2 = S->length - min_Pshift;
	for (Pshift = min_Pshift, n2 = min_Pshift + P->length;
	     n2 <= max_n2;
	     Pshift++, n2++)
	{
		nmis = _nmismatch_at_Pshift(P, S, Pshift, max_nmis,
					    bytewise_match_table);
		if (nmis <= max_nmis && nmis >= min_nmis)
			_report_match(Pshift + 1, P->length);
	}
	return;
}
Пример #2
0
void _match_pattern_indels(const Chars_holder *P, const Chars_holder *S,
		int max_nmis, int fixedP, int fixedS)
{
	int i0, j0, max_nmis1, nedit1, width1;
	char c0;
	const BytewiseOpTable *bytewise_match_table;
	Chars_holder P1;

	if (P->length <= 0)
		error("empty pattern");
	bytewise_match_table = _select_bytewise_match_table(fixedP, fixedS);
	_init_byte2offset_with_Chars_holder(&byte2offset, P,
					     bytewise_match_table);
	provisory_match_nedit = -1; // means no provisory match yet
	j0 = 0;
	while (j0 < S->length) {
		while (1) {
			c0 = S->ptr[j0];
			i0 = byte2offset.byte2code[(unsigned char) c0];
			if (i0 != NA_INTEGER) break;
			j0++;
			if (j0 >= S->length) goto done;
		}
		P1.ptr = P->ptr + i0 + 1;
		P1.length = P->length - i0 - 1;
		max_nmis1 = max_nmis - i0;
/*
#ifdef DEBUG_BIOSTRINGS
		if (debug) {
			Rprintf("[DEBUG] _match_pattern_indels(): "
				"j0=%d c0=%c i0=%d max_nmis1=%d\n", j0, c0, i0, max_nmis1);
		}
#endif
*/
		if (max_nmis1 >= 0) {
			if (max_nmis1 == 0) {
				nedit1 = _nmismatch_at_Pshift(&P1, S, j0 + 1,
							max_nmis1,
							bytewise_match_table);
				width1 = P1.length;
			} else {
				nedit1 = _nedit_for_Ploffset(&P1, S, j0 + 1,
							max_nmis1, 1, &width1,
							bytewise_match_table);
			}
			if (nedit1 <= max_nmis1) {
#ifdef DEBUG_BIOSTRINGS
				if (debug) {
					Rprintf("[DEBUG] _match_pattern_indels(): "
						"provisory match found at ");
					print_match(j0 + 1, width1 + 1, P, S,
						    bytewise_match_table);
				}
#endif
				report_provisory_match(j0 + 1, width1 + 1, nedit1 + i0);
			}
		}
		j0++;
	}
	done:
	if (provisory_match_nedit != -1)
		_report_match(provisory_match_start, provisory_match_width);
	return;
}