]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/lib/maasha/seq.rb
added test for length of seq/qual mismatch
[biopieces.git] / code_ruby / lib / maasha / seq.rb
index 2788e5dcc02d78cdb9e3fd38ef83749bad158b79..fd83ba3282d28c561358fb9383c18e324d9a7ed4 100644 (file)
@@ -27,9 +27,12 @@ require 'maasha/seq/digest'
 require 'maasha/seq/trim'
 require 'narray'
 
-autoload :BackTrack,   'maasha/seq/backtrack.rb'
-autoload :Dynamic,     'maasha/seq/dynamic.rb'
-autoload :Homopolymer, 'maasha/seq/homopolymer.rb'
+autoload :BackTrack,   'maasha/seq/backtrack'
+autoload :Dynamic,     'maasha/seq/dynamic'
+autoload :Homopolymer, 'maasha/seq/homopolymer'
+autoload :Hamming,     'maasha/seq/hamming'
+autoload :Levenshtein, 'maasha/seq/levenshtein'
+autoload :Ambiguity,   'maasha/seq/ambiguity'
 
 # Residue alphabets
 DNA     = %w[a t c g]
@@ -68,7 +71,6 @@ TRANS_TAB11 = {
   "GTG" => "V", "GCG" => "A", "GAG" => "E", "GGG" => "G"
 }
 
-
 # Error class for all exceptions to do with Seq.
 class SeqError < StandardError; end
 
@@ -133,6 +135,10 @@ class Seq
     @seq      = seq
     @type     = type
     @qual     = qual
+
+    if @qual
+      raise SeqError, "Sequence length and score length mismatch: #{@seq.length} != #{@qual.length}" if @seq.length != @qual.length
+    end
   end
 
   # Method that guesses and returns the sequence type
@@ -384,8 +390,18 @@ class Seq
 
   # Method to determine the Hamming Distance between
   # two Sequence objects (case insensitive).
-  def hamming_distance(seq)
-    self.seq.upcase.hamming_distance(seq.seq.upcase)
+  def hamming_distance(entry, options = nil)
+    if options and options[:ambiguity]
+      Hamming.distance(self.seq, entry.seq)
+    else
+      self.seq.upcase.hamming_distance(entry.seq.upcase)
+    end
+  end
+
+  # Method to determine the Edit Distance between
+  # two Sequence objects (case insensitive).
+  def edit_distance(entry)
+    Levenshtein.distance(self.seq, entry.seq)
   end
 
   # Method that generates a random sequence of a given length and type.