MAX_INS = 5 # Maximum number of insertions allowed
MAX_DEL = 5 # Maximum number of deletions allowed
+ def patmatch(pattern, offset = 0, max_mismatches = 0, max_insertions = 0, max_deletions = 0)
+ self.patscan(pattern, offset, max_mismatches, max_insertions, max_deletions) do |m|
+ if block_given?
+ yield m
+ else
+ return m
+ end
+
+ break
+ end
+
+ if block_given?
+ yield nil
+ else
+ return nil
+ end
+ end
+
# ------------------------------------------------------------------------------
# str.scan(pattern[, max_mismatches[, max_insertions[, max_deletions]]])
# -> Array
matches = []
if block_given?
- while result = track_C(self.seq, self.length, pattern, offset, max_mismatches, max_insertions, max_deletions)
+ while result = scan_C(self.seq, self.length, pattern, offset, max_mismatches, max_insertions, max_deletions)
yield Match.new(result.first, result.last, self.seq[result.first ... result.first + result.last])
offset = result.first + 1
end
else
- while result = track_C(self.seq, self.length, pattern, offset, max_mismatches, max_insertions, max_deletions)
+ while result = scan_C(self.seq, self.length, pattern, offset, max_mismatches, max_insertions, max_deletions)
matches << Match.new(result.first, result.last, self.seq[result.first ... result.first + result.last])
offset = result.first + 1
end
# Backtrack algorithm for matching a pattern (p) starting in a sequence (s) allowing for mis
# mismatches, ins insertions and del deletions. ss is the start of the sequence, used only for
- # reporting the match endpoints.
+ # reporting the match endpoints. State is used to avoid ins followed by del and visa versa which
+ # are nonsense.
builder.prefix %{
unsigned int backtrack(
char *ss, // Sequence start
# Find pattern (p) in a sequence (s) starting at pos, with at most mis mismatches, ins
# insertions and del deletions.
builder.c %{
- VALUE track_C(
+ VALUE scan_C(
VALUE _s, // Sequence
VALUE _len, // Sequence length
VALUE _p, // Pattern