X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FConservation.java;h=bd87ee87df1b8c446401f322f058064ef5b584d0;hb=fab0afc9e1e7a5ca460f0cbd48545536f989a435;hp=ba4f705bf99aeab47ca5474d10b2e2317125a120;hpb=3d0101179759ef157b088ea135423cd909512d9f;p=jalview.git diff --git a/src/jalview/analysis/Conservation.java b/src/jalview/analysis/Conservation.java index ba4f705..bd87ee8 100755 --- a/src/jalview/analysis/Conservation.java +++ b/src/jalview/analysis/Conservation.java @@ -30,6 +30,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 +55,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; @@ -273,7 +276,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; @@ -567,7 +570,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++) @@ -622,7 +625,7 @@ public class Conservation protected void findQuality(int startCol, int endCol, ScoreMatrix scoreMatrix) { - quality = new Vector(); + quality = new Vector<>(); double max = -Double.MAX_VALUE; float[][] scores = scoreMatrix.getMatrix(); @@ -721,8 +724,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 @@ -736,30 +739,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]; } @@ -768,7 +766,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]; } @@ -780,7 +778,7 @@ public class Conservation { float value = 0; - c = sequence[i]; + char c = cons.getCharAt(i); if (Character.isDigit(c)) { @@ -813,7 +811,8 @@ public class Conservation value = quality.elementAt(i).floatValue(); float vprop = value - qmin; vprop /= qmax; - quality2.annotations[i] = new Annotation(" ", String.valueOf(value), + String description = FORMAT_3DP.form(value); + quality2.annotations[i] = new Annotation(" ", description, ' ', value, new Color(minR + (maxR * vprop), minG + (maxG * vprop), minB + (maxB * vprop))); } @@ -866,8 +865,8 @@ 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)