From: cmzmasek@gmail.com Date: Fri, 4 Mar 2011 22:51:37 +0000 (+0000) Subject: added calculation of gap-proportion X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=83aa317912858681f37a37f879c06af3292e9ae6;p=jalview.git added calculation of gap-proportion --- diff --git a/forester/ruby/evoruby/lib/evo/apps/msa_processor.rb b/forester/ruby/evoruby/lib/evo/apps/msa_processor.rb index 708a9b7..0745c21 100644 --- a/forester/ruby/evoruby/lib/evo/apps/msa_processor.rb +++ b/forester/ruby/evoruby/lib/evo/apps/msa_processor.rb @@ -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 diff --git a/forester/ruby/evoruby/lib/evo/msa/msa.rb b/forester/ruby/evoruby/lib/evo/msa/msa.rb index 2924646..3912a77 100644 --- a/forester/ruby/evoruby/lib/evo/msa/msa.rb +++ b/forester/ruby/evoruby/lib/evo/msa/msa.rb @@ -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() )