X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fschemes%2FFeatureColour.java;h=e5bda58f853bb16173a6a21765b69e8fec7760e1;hb=f62dc5899b5bbcb87cc3f6b06fb1420f7768df82;hp=55fdf243c9984a963d7ca4bc347a5a8185579dec;hpb=e42eed3a0089a8a064560df4cf17a5021fd1e16a;p=jalview.git diff --git a/src/jalview/schemes/FeatureColour.java b/src/jalview/schemes/FeatureColour.java index 55fdf24..e5bda58 100644 --- a/src/jalview/schemes/FeatureColour.java +++ b/src/jalview/schemes/FeatureColour.java @@ -20,11 +20,14 @@ */ package jalview.schemes; +import java.util.Locale; + import jalview.api.FeatureColourI; import jalview.datamodel.SequenceFeature; import jalview.datamodel.features.FeatureMatcher; import jalview.util.ColorUtils; import jalview.util.Format; +import jalview.util.MessageManager; import java.awt.Color; import java.util.StringTokenizer; @@ -50,6 +53,12 @@ import java.util.StringTokenizer; */ public class FeatureColour implements FeatureColourI { + private static final String I18N_LABEL = MessageManager + .getString("label.label"); + + private static final String I18N_SCORE = MessageManager + .getString("label.score"); + private static final String ABSOLUTE = "abso"; private static final String ABOVE = "above"; @@ -187,19 +196,19 @@ public class FeatureColour implements FeatureColourI "Expected either 'label' or a colour specification in the line: " + descriptor); } - if (nextToken.toLowerCase().startsWith(LABEL)) + if (nextToken.toLowerCase(Locale.ROOT).startsWith(LABEL)) { byLabel = true; // get the token after the next delimiter: mincol = (gcol.hasMoreTokens() ? gcol.nextToken() : null); mincol = (gcol.hasMoreTokens() ? gcol.nextToken() : null); } - else if (nextToken.toLowerCase().startsWith(SCORE)) + else if (nextToken.toLowerCase(Locale.ROOT).startsWith(SCORE)) { mincol = (gcol.hasMoreTokens() ? gcol.nextToken() : null); mincol = (gcol.hasMoreTokens() ? gcol.nextToken() : null); } - else if (nextToken.toLowerCase().startsWith(ATTRIBUTE)) + else if (nextToken.toLowerCase(Locale.ROOT).startsWith(ATTRIBUTE)) { byAttribute = true; attName = (gcol.hasMoreTokens() ? gcol.nextToken() : null); @@ -297,7 +306,7 @@ public class FeatureColour implements FeatureColourI } gcol.nextToken(); // skip next '|' - if (tok.toLowerCase().startsWith(ABSOLUTE)) + if (tok.toLowerCase(Locale.ROOT).startsWith(ABSOLUTE)) { minval = gcol.nextToken(); gcol.nextToken(); // skip next '|' @@ -316,19 +325,19 @@ public class FeatureColour implements FeatureColourI { if (minval.length() > 0) { - min = new Float(minval).floatValue(); + min = Float.valueOf(minval).floatValue(); } } catch (Exception e) { throw new IllegalArgumentException( - "Couldn't parse the minimum value for graduated colour (" - + descriptor + ")"); + "Couldn't parse the minimum value for graduated colour ('" + + minval + "')"); } try { if (maxval.length() > 0) { - max = new Float(maxval).floatValue(); + max = Float.valueOf(maxval).floatValue(); } } catch (Exception e) { @@ -373,17 +382,17 @@ public class FeatureColour implements FeatureColourI { // threshold type and possibly a threshold value ttype = gcol.nextToken(); - if (ttype.toLowerCase().startsWith(BELOW)) + if (ttype.toLowerCase(Locale.ROOT).startsWith(BELOW)) { featureColour.setBelowThreshold(true); } - else if (ttype.toLowerCase().startsWith(ABOVE)) + else if (ttype.toLowerCase(Locale.ROOT).startsWith(ABOVE)) { featureColour.setAboveThreshold(true); } else { - if (!ttype.toLowerCase().startsWith("no")) + if (!ttype.toLowerCase(Locale.ROOT).startsWith("no")) { System.err.println( "Ignoring unrecognised threshold type : " + ttype); @@ -396,7 +405,7 @@ public class FeatureColour implements FeatureColourI { gcol.nextToken(); tval = gcol.nextToken(); - featureColour.setThreshold(new Float(tval).floatValue()); + featureColour.setThreshold(Float.valueOf(tval).floatValue()); } catch (Exception e) { System.err.println("Couldn't parse threshold value as a float: (" @@ -672,9 +681,12 @@ public class FeatureColour implements FeatureColourI /** * Returns the colour for the given instance of the feature. This may be a - * simple colour, a colour generated from the feature description (if - * isColourByLabel()), or a colour derived from the feature score (if - * isGraduatedColour()). + * simple colour, a colour generated from the feature description or other + * attribute (if isColourByLabel()), or a colour derived from the feature + * score or other attribute (if isGraduatedColour()). + *

+ * Answers null if feature score (or attribute) value lies outside a + * configured threshold. * * @param feature * @return @@ -884,4 +896,78 @@ public class FeatureColour implements FeatureColourI attributeName = name; } + @Override + public boolean isOutwithThreshold(SequenceFeature feature) + { + if (!isGraduatedColour()) + { + return false; + } + float scr = feature.getScore(); + if (attributeName != null) + { + try + { + String attVal = feature.getValueAsString(attributeName); + scr = Float.valueOf(attVal); + } catch (Throwable e) + { + scr = Float.NaN; + } + } + if (Float.isNaN(scr)) + { + return false; + } + + return ((isAboveThreshold() && scr <= threshold) + || (isBelowThreshold() && scr >= threshold)); + } + + @Override + public String getDescription() + { + if (isSimpleColour()) + { + return "r=" + colour.getRed() + ",g=" + colour.getGreen() + ",b=" + + colour.getBlue(); + } + StringBuilder tt = new StringBuilder(); + String by = null; + + if (getAttributeName() != null) + { + by = FeatureMatcher.toAttributeDisplayName(getAttributeName()); + } + else if (isColourByLabel()) + { + by = I18N_LABEL; + } + else + { + by = I18N_SCORE; + } + tt.append(MessageManager.formatMessage("action.by_title_param", by)); + + /* + * add threshold if any + */ + if (isAboveThreshold() || isBelowThreshold()) + { + tt.append(" ("); + if (isColourByLabel()) + { + /* + * Jalview features file supports the combination of + * colour by label or attribute text with score threshold + */ + tt.append(I18N_SCORE).append(" "); + } + tt.append(isAboveThreshold() ? "> " : "< "); + tt.append(getThreshold()).append(")"); + } + + return tt.toString(); + } + }