]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/lib/maasha/align/pair.rb
added math_aux.rb
[biopieces.git] / code_ruby / lib / maasha / align / pair.rb
index 307197ad1dc6df82d324d6d87e7c82af778a25fb..72a5eae798262c7e4c276dd243ff22c7a70fa8cf 100644 (file)
@@ -107,26 +107,34 @@ module PairAlign
 
     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.
@@ -158,7 +166,7 @@ module PairAlign
       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)