]> git.donarmstrong.com Git - biopieces.git/commitdiff
added hamming_distance method to seq.rb
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 5 Sep 2011 13:47:15 +0000 (13:47 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 5 Sep 2011 13:47:15 +0000 (13:47 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1516 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/lib/maasha/seq.rb
code_ruby/test/maasha/test_seq.rb

index 3b950aef6c3ae6326b65d4a2217f0eef4d672976..260a2b7038402a4fb13ef914f6e7acd6cb7e8a5c 100644 (file)
@@ -24,6 +24,7 @@
 
 require 'maasha/digest'
 require 'maasha/patternmatcher'
+require 'maasha/bits'
 #require 'maasha/patscan'
 
 # Residue alphabets
@@ -227,6 +228,12 @@ class Seq
     end
   end
 
+  # Method to determine the Hamming Distance between
+  # two Sequence objects (case insensitive).
+  def hamming_distance(seq)
+    self.seq.upcase.hamming_distance(seq.seq.upcase)
+  end
+
   # Method that generates a random sequence of a given length and type.
   def generate(length, type)
     raise SeqError, "Cannot generate sequence length < 1: #{length}" if length <= 0
index 93737d44280dbf02d8c029048ada0d2a51816998..7859fbef86a08b5f8802727e37f4243ba960102f 100755 (executable)
@@ -218,6 +218,12 @@ class TestSeq < Test::Unit::TestCase
     assert_equal("cgauCGAU", @entry.reverse_complement)
   end
 
+  def test_Seq_hamming_distance_returns_correctly
+    seq1 = Seq.new("test1", "ATCG")
+    seq2 = Seq.new("test2", "atgg")
+    assert_equal(1, seq1.hamming_distance(seq2))
+  end
+
   def test_Seq_generate_with_length_lt_1_raises
     assert_raise(SeqError) { @entry.generate(-10, "dna") }
     assert_raise(SeqError) { @entry.generate(0, "dna") }