added calculation of gap-proportion
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Fri, 4 Mar 2011 22:51:37 +0000 (22:51 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Fri, 4 Mar 2011 22:51:37 +0000 (22:51 +0000)
forester/ruby/evoruby/lib/evo/apps/msa_processor.rb
forester/ruby/evoruby/lib/evo/msa/msa.rb

index 708a9b7..0745c21 100644 (file)
@@ -292,8 +292,11 @@ module Evoruby
       end
 
       if ( msa.is_aligned() )
-        Util.print_message( PRG_NAME, "Length of original alignment : " + msa.get_length.to_s )
-        log << "Length of original alignment : " + msa.get_length.to_s + ld
+        Util.print_message( PRG_NAME, "Length of original alignment         : " + msa.get_length.to_s )
+        log << "Length of original alignment         : " + msa.get_length.to_s + ld
+        gp = msa.calculate_gap_proportion
+        Util.print_message( PRG_NAME, "Gap-proportion of original alignment : " + gp.to_s )
+        log << "Gap-proportion of original alignment : " +  gp.to_s + ld
       else
         Util.print_message( PRG_NAME, "the input is not aligned" )
         log << "The input is not aligned" + ld
@@ -472,8 +475,11 @@ module Evoruby
 
         unless ( @rg )
           if ( msa.is_aligned() )
-            Util.print_message( PRG_NAME, "length of processed alignment: " + msa.get_length.to_s )
-            log <<  "length of processed alignment: " + msa.get_length.to_s + ld
+            Util.print_message( PRG_NAME, "Length of processed alignment        : " + msa.get_length.to_s )
+            log <<  "Length of processed alignment        : " + msa.get_length.to_s + ld
+            gp = msa.calculate_gap_proportion
+            Util.print_message( PRG_NAME, "Gap-proportion of processed alignment: " + gp.to_s )
+            log << "Gap-proportion of processed alignment: " +  gp.to_s + ld
           else
             Util.print_warning_message( PRG_NAME, "output is not aligned" )
             log << "output is not aligned" + ld
index 2924646..3912a77 100644 (file)
@@ -225,7 +225,7 @@ module Evoruby
             seq_1 = get_sequence( index_1 )
             seq_2 = get_sequence( index_2 )
             overlap_count = 0
-            for i in 0...seq_1.get_length()
+            for i in 0...seq_1.get_length
                 if !Util.is_aa_gap_character?( seq_1.get_character_code( i ) ) &&
                      !Util.is_aa_gap_character?( seq_2.get_character_code( i ) )
                     overlap_count += 1
@@ -238,7 +238,7 @@ module Evoruby
             seq_1 = get_sequence( index_1 )
             seq_2 = get_sequence( index_2 )
             identities_count = 0
-            for i in 0...seq_1.get_length()
+            for i in 0...seq_1.get_length
                 if !Util.is_aa_gap_character?( seq_1.get_character_code( i ) ) &&
                      !Util.is_aa_gap_character?( seq_2.get_character_code( i ) ) &&
                      seq_1.get_character_code( i ) != 63 &&
@@ -373,6 +373,25 @@ module Evoruby
             end
             return cols
         end
+        
+        def calculate_gap_proportion()
+            if ( !is_aligned() )
+                error_msg = "attempt to get gap only columns of unaligned msa"
+                raise StandardError, error_msg, caller
+            end
+            total_sum = 0.0
+            gap_sum = 0.0
+            for c in 0 ... get_length
+                for s in 0 ... get_number_of_seqs
+                    total_sum = total_sum + 1
+                    if Util.is_aa_gap_character?( get_sequence( s ).get_character_code( c ) )
+                        gap_sum = gap_sum  + 1
+                    end
+                end
+               
+            end
+            return gap_sum / total_sum
+        end
 
         def get_gap_columns()
             if ( !is_aligned() )