From: martinahansen Date: Wed, 18 Apr 2012 17:02:20 +0000 (+0000) Subject: added identity method to align.rb X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=6444547752232a922a0ad17de4b36d685965c41a;p=biopieces.git added identity method to align.rb git-svn-id: http://biopieces.googlecode.com/svn/trunk@1804 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_ruby/lib/maasha/align.rb b/code_ruby/lib/maasha/align.rb index 32532fe..737f2f8 100755 --- a/code_ruby/lib/maasha/align.rb +++ b/code_ruby/lib/maasha/align.rb @@ -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