# matches are returned in an Array of Match objects.
def patscan(pattern, offset = 0, max_mismatches = 0, max_insertions = 0, max_deletions = 0)
raise BackTrackError, "Bad pattern: #{pattern}" unless pattern.downcase =~ OK_PATTERN
- raise BackTrackError, "offset: #{offset} out of range (0 ... #{self.length - 1})" unless (0 ... self.length).include? offset
+ raise BackTrackError, "offset: #{offset} out of range (0 ... #{self.length - 1})" unless (0 ... self.length).include? offset
raise BackTrackError, "max_mismatches: #{max_mismatches} out of range (0 .. #{MAX_MIS})" unless (0 .. MAX_MIS).include? max_mismatches
raise BackTrackError, "max_insertions: #{max_insertions} out of range (0 .. #{MAX_INS})" unless (0 .. MAX_INS).include? max_insertions
raise BackTrackError, "max_deletions: #{max_deletions} out of range (0 .. #{MAX_DEL})" unless (0 .. MAX_DEL).include? max_deletions
inline do |builder|
builder.add_static "id_seq", 'rb_intern("@seq")', "ID"
+ # Macro for matching nucleotides including ambiguity codes.
builder.prefix %{
#define MATCH(A,B) ((bitmap[(unsigned short) A] & bitmap[(unsigned short) B]) != 0)
}
+ # Bitmap for matching nucleotides including ambiguity codes.
+ # For each value bits are set from the left: bit pos 1 for A,
+ # bit pos 2 for T, bit pos 3 for C, and bit pos 4 for G.
builder.prefix %{
unsigned short bitmap[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
}
- # ss is the start of the string, used only for reporting the match endpoints.
+ # Backtrack algorithm for matching a pattern (p) starting in a sequence (s) allowing for mm
+ # mismatches, ins insertions and del deletions. ss is the start of the sequence, used only for
+ # reporting the match endpoints.
builder.prefix %{
unsigned int backtrack(char* ss, char* s, char* p, int mm, int ins, int del)
{
}
}
- # Find all occurrences of p starting at pos in s, with at most
- # mm mismatches, ins insertions and del deletions.
+ # Find pattern (p) in a sequence (@seq) starting at pos, with at most mm mismatches, ins
+ # insertions and del deletions.
builder.c %{
static VALUE track(char* p, unsigned int pos, int mm, int ins, int del)
{
}
end
+ # Class containing match information.
class Match
attr_reader :pos, :length, :match