X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fschemes%2FFeatureColour.java;h=b748d9e3e5d4498b5970f6e11f42b0b3e294d04c;hb=00918171094ad58563bd0b82e18ecf19537ba132;hp=bd58273faa3b795e5b8d4bb4c9ad8b0cacefc3b7;hpb=3e943322f9d66e8718316ba8bd03669adce65149;p=jalview.git diff --git a/src/jalview/schemes/FeatureColour.java b/src/jalview/schemes/FeatureColour.java index bd58273..b748d9e 100644 --- a/src/jalview/schemes/FeatureColour.java +++ b/src/jalview/schemes/FeatureColour.java @@ -1,7 +1,28 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.schemes; import jalview.api.FeatureColourI; import jalview.datamodel.SequenceFeature; +import jalview.util.ColorUtils; import jalview.util.Format; import java.awt.Color; @@ -101,7 +122,7 @@ public class FeatureColour implements FeatureColourI /* * only a simple colour specification - parse it */ - Color colour = UserColourScheme.getColourFromString(descriptor); + Color colour = ColorUtils.parseColourString(descriptor); if (colour == null) { throw new IllegalArgumentException("Invalid colour descriptor: " @@ -111,10 +132,10 @@ public class FeatureColour implements FeatureColourI } /* - * autoScaled == true: colours range over actual score range; autoScaled == - * false ('abso'): colours range over min/max range + * autoScaled == true: colours range over actual score range + * autoScaled == false ('abso'): colours range over min/max range */ - boolean autoScaled = false; + boolean autoScaled = true; String tok = null, minval, maxval; if (mincol != null) { @@ -138,15 +159,15 @@ public class FeatureColour implements FeatureColourI } tok = gcol.nextToken(); gcol.nextToken(); // skip next '|' - if (tok.toLowerCase().indexOf("abso") != 0) + if (tok.toLowerCase().startsWith("abso")) { - minval = tok; - autoScaled = true; + minval = gcol.nextToken(); + gcol.nextToken(); // skip next '|' + autoScaled = false; } else { - minval = gcol.nextToken(); - gcol.nextToken(); // skip next '|' + minval = tok; } maxval = gcol.nextToken(); if (gcol.hasMoreTokens()) @@ -192,9 +213,9 @@ public class FeatureColour implements FeatureColourI FeatureColour featureColour; try { - featureColour = new FeatureColour( - new UserColourScheme(mincol).findColour('A'), - new UserColourScheme(maxcol).findColour('A'), min, max); + Color minColour = ColorUtils.parseColourString(mincol); + Color maxColour = ColorUtils.parseColourString(maxcol); + featureColour = new FeatureColour(minColour, maxColour, min, max); featureColour.setColourByLabel(labelColour); featureColour.setAutoScaled(autoScaled); // add in any additional parameters @@ -286,6 +307,14 @@ public class FeatureColour implements FeatureColourI */ public FeatureColour(Color low, Color high, float min, float max) { + if (low == null) + { + low = Color.white; + } + if (high == null) + { + high = Color.black; + } graduatedColour = true; colour = null; minColour = low; @@ -317,6 +346,7 @@ public class FeatureColour implements FeatureColourI */ public FeatureColour(FeatureColour fc) { + graduatedColour = fc.graduatedColour; colour = fc.colour; minColour = fc.minColour; maxColour = fc.maxColour; @@ -335,9 +365,10 @@ public class FeatureColour implements FeatureColourI setAutoScaled(fc.isAutoScaled()); setColourByLabel(fc.isColourByLabel()); } - + /** * Copy constructor with new min/max ranges + * * @param fc * @param min * @param max @@ -359,8 +390,7 @@ public class FeatureColour implements FeatureColourI * Sets the 'graduated colour' flag. If true, also sets 'colour by label' to * false. */ - @Override - public void setGraduatedColour(boolean b) + void setGraduatedColour(boolean b) { graduatedColour = b; if (b) @@ -406,6 +436,7 @@ public class FeatureColour implements FeatureColourI setGraduatedColour(false); } } + @Override public boolean isBelowThreshold() { @@ -511,7 +542,7 @@ public class FeatureColour implements FeatureColourI { if (isColourByLabel()) { - return UserColourScheme + return ColorUtils .createColourFromName(feature.getDescription()); } @@ -520,16 +551,27 @@ public class FeatureColour implements FeatureColourI return getColour(); } - // todo should we check for above/below threshold here? - if (range == 0.0) - { - return getMaxColour(); - } + /* + * graduated colour case, optionally with threshold + * Float.NaN is assigned minimum visible score colour + */ float scr = feature.getScore(); if (Float.isNaN(scr)) { return getMinColour(); } + if (isAboveThreshold() && scr <= threshold) + { + return null; + } + if (isBelowThreshold() && scr >= threshold) + { + return null; + } + if (range == 0.0) + { + return getMaxColour(); + } float scl = (scr - base) / range; if (isHighToLow) { @@ -543,7 +585,8 @@ public class FeatureColour implements FeatureColourI { scl = 1f; } - return new Color(minRed + scl * deltaRed, minGreen + scl * deltaGreen, minBlue + scl * deltaBlue); + return new Color(minRed + scl * deltaRed, minGreen + scl * deltaGreen, + minBlue + scl * deltaBlue); } /** @@ -570,44 +613,6 @@ public class FeatureColour implements FeatureColourI return (isHighToLow) ? (base + range) : base; } - /** - * Answers true if the feature has a simple colour, or is coloured by label, - * or has a graduated colour and the score of this feature instance is within - * the range to render (if any), i.e. does not lie below or above any - * threshold set. - * - * @param feature - * @return - */ - @Override - public boolean isColored(SequenceFeature feature) - { - if (isColourByLabel() || !isGraduatedColour()) - { - return true; - } - - float val = feature.getScore(); - if (Float.isNaN(val)) - { - return true; - } - if (Float.isNaN(this.threshold)) - { - return true; - } - - if (isAboveThreshold() && val <= threshold) - { - return false; - } - if (isBelowThreshold() && val >= threshold) - { - return false; - } - return true; - } - @Override public boolean isSimpleColour() { @@ -643,7 +648,7 @@ public class FeatureColour implements FeatureColourI { sb.append(Format.getHexString(getMinColour())).append(BAR); sb.append(Format.getHexString(getMaxColour())).append(BAR); - if (isAutoScaled()) + if (!isAutoScaled()) { sb.append("abso").append(BAR); }