]> git.donarmstrong.com Git - biopieces.git/commitdiff
added identity method to align.rb
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Wed, 18 Apr 2012 17:02:20 +0000 (17:02 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Wed, 18 Apr 2012 17:02:20 +0000 (17:02 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1804 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/lib/maasha/align.rb

index 32532fe26be362277eb36670ffa400aea7df5066..737f2f8f978c4e28477677939f6961d14df344de 100755 (executable)
@@ -143,6 +143,22 @@ class Align
     @entries.size
   end
 
+  # Method that returns the identity of an alignment with two members.
+  def identity
+    if self.members != 2
+      raise AlignError "Bad number of members for similarity calculation: #{self.members}"
+    end
+      
+    na1 = NArray.to_na(@entries[0].seq.upcase, "byte")
+    na2 = NArray.to_na(@entries[1].seq.upcase, "byte")
+
+    shared   = (na1 - na2).count_false
+    total    = (@entries[0].length < @entries[1].length) ? @entries[0].length : @entries[1].length
+    identity = (shared.to_f / total).round(2)
+
+    identity
+  end
+
   # Method to create a consensus sequence from an Align object and
   # return a new Seq object with the consensus.
   def consensus