X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FConservation.java;h=cbc4dcae3130c89b40ccf47d77dfd7e488cd2194;hb=57738a1f3c19b1c3a00bd3ac5108f8cd0af32f99;hp=f94a6583475a433f7aa2e5af9ed730d644da495d;hpb=ff450fad8709ae81919af7a15ea382af7292794c;p=jalview.git diff --git a/src/jalview/analysis/Conservation.java b/src/jalview/analysis/Conservation.java index f94a658..cbc4dca 100755 --- a/src/jalview/analysis/Conservation.java +++ b/src/jalview/analysis/Conservation.java @@ -20,6 +20,8 @@ */ package jalview.analysis; +import java.util.Locale; + import jalview.analysis.scoremodels.ScoreMatrix; import jalview.analysis.scoremodels.ScoreModels; import jalview.datamodel.AlignmentAnnotation; @@ -30,6 +32,7 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import jalview.schemes.ResidueProperties; import jalview.util.Comparison; +import jalview.util.Format; import java.awt.Color; import java.util.List; @@ -54,6 +57,8 @@ public class Conservation private static final int GAP_INDEX = -1; + private static final Format FORMAT_3DP = new Format("%2.5f"); + SequenceI[] sequences; int start; @@ -143,8 +148,8 @@ public class Conservation * @param end * end column position */ - public Conservation(String name, int threshold, - List sequences, int start, int end) + public Conservation(String name, int threshold, List sequences, + int start, int end) { this.name = name; this.threshold = threshold; @@ -244,8 +249,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 +278,7 @@ public class Conservation * or not conserved (-1) * Using TreeMap means properties are displayed in alphabetical order */ - SortedMap resultHash = new TreeMap(); + SortedMap resultHash = new TreeMap<>(); SymbolCounts symbolCounts = values.getSymbolCounts(); char[] symbols = symbolCounts.symbols; int[] counts = symbolCounts.values; @@ -309,7 +314,7 @@ public class Conservation protected static void recordConservation(Map resultMap, String res) { - res = res.toUpperCase(); + res = res.toUpperCase(Locale.ROOT); for (Entry> property : ResidueProperties.propHash .entrySet()) { @@ -414,7 +419,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 +572,7 @@ public class Conservation */ private void percentIdentity(ScoreMatrix sm) { - seqNums = new Vector(); + seqNums = new Vector<>(); int i = 0, iSize = sequences.length; // Do we need to calculate this again? for (i = 0; i < iSize; i++) @@ -618,9 +624,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(); + quality = new Vector<>(); double max = -Double.MAX_VALUE; float[][] scores = scoreMatrix.getMatrix(); @@ -693,7 +700,7 @@ public class Conservation max = Math.max(max, bigtot); - quality.addElement(new Double(bigtot)); + quality.addElement(Double.valueOf(bigtot)); } double newmax = -Double.MAX_VALUE; @@ -705,7 +712,7 @@ public class Conservation tmp = ((max - tmp) * (size - cons2GapCounts[j])) / size; // System.out.println(tmp+ " " + j); - quality.setElementAt(new Double(tmp), j); + quality.setElementAt(Double.valueOf(tmp), j); if (tmp > newmax) { @@ -719,8 +726,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 @@ -752,7 +759,7 @@ public class Conservation float qmax = 0f; if (conservation != null && conservation.annotations != null - && conservation.annotations.length < alWidth) + && conservation.annotations.length != alWidth) { conservation.annotations = new Annotation[alWidth]; } @@ -761,7 +768,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]; } @@ -793,11 +800,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 @@ -806,10 +813,10 @@ 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))); + String description = FORMAT_3DP.form(value); + quality2.annotations[i] = new Annotation(" ", description, ' ', + value, new Color(minR + (maxR * vprop), + minG + (maxG * vprop), minB + (maxB * vprop))); } } } @@ -864,7 +871,8 @@ public class Conservation 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; }