def matches_score(matches, q_min, s_min, q_max, s_max)
matches.each do |match|
- score_length = match.length
+ score_length = match_score_length(match)
+ score_diag = match_score_diag(match, q_min, s_min, q_max, s_max)
+ score_corner = match_score_corner(match, q_min, s_min, q_max, s_max)
- min = (q_min - s_min).abs
- max = ((q_max - q_min) - (s_max - s_min)).abs
- beg = ((match.q_beg - q_min) - (match.s_beg - s_min)).abs
- if beg > (max - min) / 2
- score_diag = max - min
- else
- score_diag = beg
- end
-
-# puts "score_length: #{score_length} score_diag: #{score_diag} score: #{score_length - score_diag}"
-
- match.score = score_length - score_diag
+ match.score = score_length - score_diag - score_corner
+ puts match
+ puts "score_length: #{score_length} score_diag: #{score_diag} score_corner: #{score_corner} score: #{match.score}"
end
matches.sort_by! { |match| match.score }
end
+ def match_score_length(match)
+ 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.
matches
end
- # Method that indexes a seuquence within a given interval such that the
+ # 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)
--- /dev/null
+# Copyright (C) 2007-2012 Martin A. Hansen.
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# http://www.gnu.org/copyleft/gpl.html
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# This software is part of the Biopieces framework (www.biopieces.org).
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+module Math
+ # Class method to calculate the distance from at point to a line.
+ # The point and line are given as pairs of coordinates.
+ def self.dist_point2line(
+ px, # point x coordinate
+ py, # point y coordinate
+ x1, # line 1 x coordinate
+ y1, # line 1 y coordinate
+ x2, # line 2 x coordinate
+ y2 # line 2 y coordinate
+ )
+
+ a = (y2 - y1).to_f / (x2 - x1).to_f
+ b = y1 - a * x1
+
+ (a * px + b - py).abs / Math.sqrt(a ** 2 + 1)
+ end
+
+
+ # Class method to calculate the distance between two points given
+ # as pairs of coordinates.
+ def self.dist_point2point(x1, y1, x2, y2)
+ Math.sqrt((x2.to_f - x1.to_f) ** 2 + (y2.to_f - y1.to_f) ** 2)
+ end
+end