Merge branch 'bug/JAL-3099alignmentVisibleWidth' into merge/JAL-3099
[jalview.git] / src / jalview / analysis / Conservation.java
index 2b5a8f6..0af5d20 100755 (executable)
@@ -143,8 +143,8 @@ public class Conservation
    * @param end
    *          end column position
    */
-  public Conservation(String name, int threshold,
-          List<SequenceI> sequences, int start, int end)
+  public Conservation(String name, int threshold, List<SequenceI> sequences,
+          int start, int end)
   {
     this.name = name;
     this.threshold = threshold;
@@ -244,8 +244,8 @@ public class Conservation
     else
     {
       // JBPNote INFO level debug
-      System.err
-              .println("ERROR: calcSeqNum called with out of range sequence index for Alignment\n");
+      System.err.println(
+              "ERROR: calcSeqNum called with out of range sequence index for Alignment\n");
     }
   }
 
@@ -273,7 +273,7 @@ public class Conservation
        * or not conserved (-1)
        * Using TreeMap means properties are displayed in alphabetical order
        */
-      SortedMap<String, Integer> resultHash = new TreeMap<String, Integer>();
+      SortedMap<String, Integer> resultHash = new TreeMap<>();
       SymbolCounts symbolCounts = values.getSymbolCounts();
       char[] symbols = symbolCounts.symbols;
       int[] counts = symbolCounts.values;
@@ -414,7 +414,8 @@ public class Conservation
         continue;
       }
 
-      char c = sequences[i].getCharAt(column); // gaps do not have upper/lower case
+      char c = sequences[i].getCharAt(column); // gaps do not have upper/lower
+                                               // case
 
       if (Comparison.isGap((c)))
       {
@@ -566,7 +567,7 @@ public class Conservation
    */
   private void percentIdentity(ScoreMatrix sm)
   {
-    seqNums = new Vector<int[]>();
+    seqNums = new Vector<>();
     int i = 0, iSize = sequences.length;
     // Do we need to calculate this again?
     for (i = 0; i < iSize; i++)
@@ -618,9 +619,10 @@ public class Conservation
    * @param endCol
    * @param scoreMatrix
    */
-  protected void findQuality(int startCol, int endCol, ScoreMatrix scoreMatrix)
+  protected void findQuality(int startCol, int endCol,
+          ScoreMatrix scoreMatrix)
   {
-    quality = new Vector<Double>();
+    quality = new Vector<>();
 
     double max = -Double.MAX_VALUE;
     float[][] scores = scoreMatrix.getMatrix();
@@ -719,8 +721,8 @@ public class Conservation
 
   /**
    * Complete the given consensus and quuality annotation rows. Note: currently
-   * this method will enlarge the given annotation row if it is too small,
-   * otherwise will leave its length unchanged.
+   * this method will reallocate the given annotation row if it is different to
+   * the calculated width, otherwise will leave its length unchanged.
    * 
    * @param conservation
    *          conservation annotation row
@@ -734,30 +736,25 @@ public class Conservation
   public void completeAnnotations(AlignmentAnnotation conservation,
           AlignmentAnnotation quality2, int istart, int alWidth)
   {
-    char[] sequence = getConsSequence().getSequence();
-    float minR;
-    float minG;
-    float minB;
-    float maxR;
-    float maxG;
-    float maxB;
-    minR = 0.3f;
-    minG = 0.0f;
-    minB = 0f;
-    maxR = 1.0f - minR;
-    maxG = 0.9f - minG;
-    maxB = 0f - minB; // scalable range for colouring both Conservation and
-    // Quality
+    SequenceI cons = getConsSequence();
+
+    /*
+     * colour scale for Conservation and Quality;
+     */
+    float minR = 0.3f;
+    float minG = 0.0f;
+    float minB = 0f;
+    float maxR = 1.0f - minR;
+    float maxG = 0.9f - minG;
+    float maxB = 0f - minB;
 
     float min = 0f;
     float max = 11f;
     float qmin = 0f;
     float qmax = 0f;
 
-    char c;
-
     if (conservation != null && conservation.annotations != null
-            && conservation.annotations.length < alWidth)
+            && conservation.annotations.length != alWidth)
     {
       conservation.annotations = new Annotation[alWidth];
     }
@@ -766,7 +763,7 @@ public class Conservation
     {
       quality2.graphMax = (float) qualityMaximum;
       if (quality2.annotations != null
-              && quality2.annotations.length < alWidth)
+              && quality2.annotations.length != alWidth)
       {
         quality2.annotations = new Annotation[alWidth];
       }
@@ -778,7 +775,7 @@ public class Conservation
     {
       float value = 0;
 
-      c = sequence[i];
+      char c = cons.getCharAt(i);
 
       if (Character.isDigit(c))
       {
@@ -798,11 +795,11 @@ public class Conservation
         float vprop = value - min;
         vprop /= max;
         int consp = i - start;
-        String conssym = (value > 0 && consp > -1 && consp < consSymbs.length) ? consSymbs[consp]
-                : "";
+        String conssym = (value > 0 && consp > -1
+                && consp < consSymbs.length) ? consSymbs[consp] : "";
         conservation.annotations[i] = new Annotation(String.valueOf(c),
-                conssym, ' ', value, new Color(minR + (maxR * vprop), minG
-                        + (maxG * vprop), minB + (maxB * vprop)));
+                conssym, ' ', value, new Color(minR + (maxR * vprop),
+                        minG + (maxG * vprop), minB + (maxB * vprop)));
       }
 
       // Quality calc
@@ -811,10 +808,9 @@ public class Conservation
         value = quality.elementAt(i).floatValue();
         float vprop = value - qmin;
         vprop /= qmax;
-        quality2.annotations[i] = new Annotation(" ",
-                String.valueOf(value), ' ', value, new Color(minR
-                        + (maxR * vprop), minG + (maxG * vprop), minB
-                        + (maxB * vprop)));
+        quality2.annotations[i] = new Annotation(" ", String.valueOf(value),
+                ' ', value, new Color(minR + (maxR * vprop),
+                        minG + (maxG * vprop), minB + (maxB * vprop)));
       }
     }
   }
@@ -865,11 +861,12 @@ public class Conservation
    */
   String getTooltip(int column)
   {
-    char[] sequence = getConsSequence().getSequence();
-    char val = column < sequence.length ? sequence[column] : '-';
+    SequenceI cons = getConsSequence();
+    char val = column < cons.getLength() ? cons.getCharAt(column) : '-';
     boolean hasConservation = val != '-' && val != '0';
     int consp = column - start;
-    String tip = (hasConservation && consp > -1 && consp < consSymbs.length) ? consSymbs[consp]
+    String tip = (hasConservation && consp > -1 && consp < consSymbs.length)
+            ? consSymbs[consp]
             : "";
     return tip;
   }