- match.length
- end
-
- def match_score_diag(match, q_min, s_min, q_max, s_max)
- dist1 = (match.q_beg - match.s_beg).abs
- dist2 = ((match.q_end - match.q_end).abs - dist1).abs
-
- dist1 < dist2 ? dist1 : dist2
- end
-
- def match_score_corner(match, q_min, s_min, q_max, s_max)
- 1
- end
-
-
- # Method that finds all maximally expanded non-redundant matches shared
- # between two sequences inside a given search space.
- def matches_find(q_seq, s_seq, q_min, s_min, q_max, s_max, kmer)
- matches = []
- redundant = Hash.new { |h, k| h[k] = [] }
-
- s_index = index_seq(s_seq, s_min, s_max, kmer)
-
- q_pos = q_min
-
- while q_pos <= q_max - kmer + 1
- q_oligo = q_seq[q_pos ... q_pos + kmer]
-
- s_index[q_oligo].each do |s_pos|
- match = Match.new(q_pos, s_pos, kmer)
-
- unless match_redundant?(redundant, match)
- match_expand(match, q_seq, s_seq, q_min, s_min, q_max, s_max)
- matches << match
-
- match_redundant_add(redundant, match)
- end
- end
-
- q_pos += 1
- end
-
- matches
- end
-
- # Method that indexes a sequence within a given interval such that the
- # index contains all oligos of a given kmer size and the positions where
- # this oligo was located.
- def index_seq(seq, min, max, kmer)
- index_hash = Hash.new { |h, k| h[k] = [] }
-
- pos = min
-
- while pos <= max - kmer + 1
- oligo = seq[pos ... pos + kmer]
- index_hash[oligo] << pos
-
- pos += 1
- end
-
- index_hash
- end
-
- # Method to check if a match is redundant.
- def match_redundant?(redundant, match)
- redundant[match.q_beg].each do |s_interval|
- if s_interval.include? match.s_beg and s_interval.include? match.s_end
- return true
- end
- end
-
- false
- end
-
- # Method that adds a match to the redundancy index.
- def match_redundant_add(redundant, match)
- (match.q_beg .. match.q_end).each do |q|
- redundant[q] << (match.s_beg .. match.s_end)
- end
- end
-
- # Method that expands a match as far as possible to the left and right.
- def match_expand(match, q_seq, s_seq, q_min, s_min, q_max, s_max)
- match_expand_left(match, q_seq, s_seq, q_min, s_min)
- match_expand_right(match, q_seq, s_seq, q_max, s_max)
-
- match
- end
-
- # Method that expands a match as far as possible to the left.
- def match_expand_left(match, q_seq, s_seq, q_min, s_min)
- while match.q_beg > q_min and
- match.s_beg > s_min and
- q_seq[match.q_beg - 1] == s_seq[match.s_beg - 1]
- match.q_beg -= 1
- match.s_beg -= 1
- match.length += 1
+ match.length * FACTOR_SCORE_LENGTH
+ end
+
+ def match_score_diag(match, space)
+ if space.q_dim > space.s_dim # s_dim is the narrow end
+ dist_beg = Math.dist_point2line(match.q_beg,
+ match.s_beg,
+ space.q_min,
+ space.s_min,
+ space.q_min + space.s_dim,
+ space.s_min + space.s_dim)
+
+ dist_end = Math.dist_point2line( match.q_beg,
+ match.s_beg,
+ space.q_max - space.s_dim,
+ space.s_max - space.s_dim,
+ space.q_max,
+ space.s_max)
+ else
+ dist_beg = Math.dist_point2line( match.q_beg,
+ match.s_beg,
+ space.q_min,
+ space.s_min,
+ space.q_min + space.q_dim,
+ space.s_min + space.q_dim)
+
+ dist_end = Math.dist_point2line( match.q_beg,
+ match.s_beg,
+ space.q_max - space.q_dim,
+ space.s_max - space.q_dim,
+ space.q_max,
+ space.s_max)