inprogress
[jalview.git] / forester / java / src / org / forester / msa / MsaMethods.java
index ff8342c..45c9697 100644 (file)
@@ -65,7 +65,7 @@ public final class MsaMethods {
     public static int calcGapSumPerColumn( final Msa msa, final int col ) {
         int gap_rows = 0;
         for( int j = 0; j < msa.getNumberOfSequences(); ++j ) {
-            if ( msa.getResidueAt( j, col ) == Sequence.GAP ) {
+            if ( msa.isGapAt( j, col ) ) {
                 gap_rows++;
             }
         }
@@ -159,6 +159,14 @@ public final class MsaMethods {
         return BasicMsa.createInstance( seqs );
     }
 
+    public static DescriptiveStatistics calculateIdentityRatio( final int from, final int to, final Msa msa ) {
+        final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
+        for( int c = from; c <= to; ++c ) {
+            stats.addValue( calculateIdentityRatio( msa, c ) );
+        }
+        return stats;
+    }
+
     public static double calculateIdentityRatio( final Msa msa, final int column ) {
         final SortedMap<Character, Integer> dist = calculateResidueDestributionPerColumn( msa, column );
         int majority_count = 0;
@@ -175,11 +183,13 @@ public final class MsaMethods {
     public static SortedMap<Character, Integer> calculateResidueDestributionPerColumn( final Msa msa, final int column ) {
         final SortedMap<Character, Integer> map = new TreeMap<Character, Integer>();
         for( final Character r : msa.getColumnAt( column ) ) {
-            if ( !map.containsKey( r ) ) {
-                map.put( r, 1 );
-            }
-            else {
-                map.put( r, map.get( r ) + 1 );
+            if ( r != Sequence.GAP ) {
+                if ( !map.containsKey( r ) ) {
+                    map.put( r, 1 );
+                }
+                else {
+                    map.put( r, map.get( r ) + 1 );
+                }
             }
         }
         return map;