X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fschemes%2FFeatureColour.java;h=f1bade151686ca674cfd23fae878ea45e64e9270;hb=a7169b1c72607f3c9357195b4999869650a2a891;hp=51e7645de48a7d63df8c2c9d3f3d714dd3de2119;hpb=4c43b10447a141c73446fc2bc368b06245a675c3;p=jalview.git diff --git a/src/jalview/schemes/FeatureColour.java b/src/jalview/schemes/FeatureColour.java index 51e7645..f1bade1 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; @@ -45,11 +48,18 @@ import java.util.StringTokenizer; *
+ * This sets the colour scheme to 'graduated' by default. Override this if
+ * wanted by calling setGraduatedColour(false)
for a simple
+ * colour, or setColourByLabel(true)
for colour by label.
*
+ * @param myColour
* @param low
* @param high
* @param noValueColour
* @param min
* @param max
*/
- public FeatureColour(Color low, Color high, Color noValueColour,
- float min, float max)
+ public FeatureColour(Color myColour, Color low, Color high,
+ Color noValueColour, float min, float max)
{
if (low == null)
{
@@ -523,10 +516,10 @@ public class FeatureColour implements FeatureColourI
{
high = Color.black;
}
- graduatedColour = true;
- colour = null;
+ colour = myColour;
minColour = low;
maxColour = high;
+ setGraduatedColour(true);
noColour = noValueColour;
threshold = Float.NaN;
isHighToLow = min >= max;
@@ -558,7 +551,7 @@ public class FeatureColour implements FeatureColourI
* Sets the 'graduated colour' flag. If true, also sets 'colour by label' to
* false.
*/
- void setGraduatedColour(boolean b)
+ public void setGraduatedColour(boolean b)
{
graduatedColour = b;
if (b)
@@ -689,9 +682,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 @@ -703,8 +699,8 @@ public class FeatureColour implements FeatureColourI { String label = attributeName == null ? feature.getDescription() : feature.getValueAsString(attributeName); - return label == null ? noColour : ColorUtils - .createColourFromName(label); + return label == null ? noColour + : ColorUtils.createColourFromName(label); } if (!isGraduatedColour()) @@ -830,9 +826,20 @@ public class FeatureColour implements FeatureColourI sb.append(BAR).append(Format.getHexString(getMinColour())) .append(BAR); sb.append(Format.getHexString(getMaxColour())).append(BAR); - String noValue = minColour.equals(noColour) ? NO_VALUE_MIN - : (maxColour.equals(noColour) ? NO_VALUE_MAX - : NO_VALUE_NONE); + + /* + * 'no value' colour should be null, min or max colour; + * if none of these, coerce to minColour + */ + String noValue = NO_VALUE_MIN; + if (maxColour.equals(noColour)) + { + noValue = NO_VALUE_MAX; + } + if (noColour == null) + { + noValue = NO_VALUE_NONE; + } sb.append(noValue).append(BAR); if (!isAutoScaled()) { @@ -890,4 +897,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(); + } + }