JAL-1841 JAL-2215 add the ‘ignore gaps’ structure consensus fraction
[jalview.git] / src / jalview / analysis / StructureFrequency.java
index 29d02fe..29bdb7a 100644 (file)
@@ -24,6 +24,7 @@ import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
+import jalview.util.Comparison;
 import jalview.util.Format;
 
 import java.util.ArrayList;
@@ -113,6 +114,7 @@ public class StructureFrequency
     {
       int canonicalOrWobblePairCount = 0;
       int otherPairCount = 0;
+      int nongap = 0;
       maxResidue = "-";
       values = new int[255];
       pairs = new int[255][255];
@@ -151,21 +153,16 @@ public class StructureFrequency
                       .println("WARNING: Consensus skipping null sequence - possible race condition.");
               continue;
             }
-            c = sequences[j].getCharAt(i);
 
-            // standard representation for gaps in sequence and structure
-            if (c == '.' || c == ' ')
-            {
-              c = '-';
-            }
+            c = sequences[j].getCharAt(i);
+            cEnd = sequences[j].getCharAt(bpEnd);
 
-            if (c == '-')
+            if (Comparison.isGap(c) || Comparison.isGap(cEnd))
             {
               values['-']++;
               continue;
             }
-            cEnd = sequences[j].getCharAt(bpEnd);
-
+            nongap++;
             /*
              * ensure upper-case for counting purposes
              */
@@ -192,7 +189,6 @@ public class StructureFrequency
             pairs[c][cEnd]++;
           }
         }
-        // nonGap++;
       }
 
       residueHash = new Hashtable();
@@ -204,7 +200,17 @@ public class StructureFrequency
 
         residueHash.put(PAIRPROFILE, pairs);
       }
-      int count = Math.max(canonicalOrWobblePairCount, otherPairCount);
+
+      /*
+       * the count is the number of valid pairs (as a percentage, determines
+       * the relative size of the profile logo)
+       */
+      int count = canonicalOrWobblePairCount;
+
+      /*
+       * currently displaying as '(' if most pairs are valid, or as
+       * '[' if there are more invalid than valid pairs 
+       */
       if (!maxResidue.equals("-"))
       {
         maxResidue = canonicalOrWobblePairCount >= otherPairCount ? "("
@@ -216,8 +222,9 @@ public class StructureFrequency
       percentage = ((float) count * 100) / jSize;
       residueHash.put(PID_GAPS, new Float(percentage));
 
-      // percentage = ((float) count * 100) / (float) nongap;
-      // residueHash.put(PID_NOGAPS, new Float(percentage));
+      percentage = ((float) count * 100) / nongap;
+      residueHash.put(PID_NOGAPS, new Float(percentage));
+
       if (result[i] == null)
       {
         result[i] = residueHash;
@@ -245,6 +252,9 @@ public class StructureFrequency
         percentage = ((float) count * 100) / jSize;
         residueHash.put(PID_GAPS, new Float(percentage));
 
+        percentage = ((float) count * 100) / nongap;
+        residueHash.put(PID_NOGAPS, new Float(percentage));
+
         result[bpEnd] = residueHash;
       }
     }