]> git.donarmstrong.com Git - biopieces.git/commitdiff
moved inline C code to seperate file
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Sun, 23 Jun 2013 09:38:18 +0000 (09:38 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Sun, 23 Jun 2013 09:38:18 +0000 (09:38 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@2185 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/lib/maasha/seq/levenshtein.rb

index b9f824308751ce19af2806346d8a459ec5c1dec3..2e34de0712831f51e6b48fe91abcd07db5720a6d 100644 (file)
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 require 'inline'
+require 'maasha/seq/ambiguity'
 
 # Class to calculate the Levenshtein distance between two
 # given strings.
 # http://en.wikipedia.org/wiki/Levenshtein_distance
 class Levenshtein
+  extend Ambiguity
+
   BYTES_IN_INT = 4
 
   def self.distance(s, t)
@@ -45,34 +48,7 @@ class Levenshtein
   # >>>>>>>>>>>>>>> RubyInline C code <<<<<<<<<<<<<<<
 
   inline do |builder|
-    # Macro for matching nucleotides including ambiguity codes.
-    builder.prefix %{
-      #define MATCH(A,B) ((bitmap[A] & bitmap[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 %{
-      char bitmap[256] = {
-          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-          0, 1,14, 4,11, 0, 0, 8, 7, 0, 0,10, 0, 5,15, 0,
-          0, 0, 9,12, 2, 2,13, 3, 0, 6, 0, 0, 0, 0, 0, 0,
-          0, 1,14, 4,11, 0, 0, 8, 7, 0, 0,10, 0, 5,15, 0,
-          0, 0, 9,12, 2, 2,13, 3, 0, 6, 0, 0, 0, 0, 0, 0,
-          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-      };
-    }
+    add_ambiguity_macro(builder)
 
     builder.prefix %{
       unsigned int min(unsigned int a, unsigned int b, unsigned int c)