import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
-import jalview.util.Comparison;
import java.awt.Color;
import java.util.Map;
{
Color colour = Color.white;
- if (!Comparison.isGap(c) && colors != null && symbolIndex != null
+ if (colors != null && symbolIndex != null
&& c < symbolIndex.length
&& symbolIndex[c] < colors.length)
{
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
+import jalview.util.Comparison;
import java.awt.Color;
import java.util.Map;
*/
public class ScoreColourScheme extends ResidueColourScheme
{
- /** DOCUMENT ME!! */
public double min;
- /** DOCUMENT ME!! */
public double max;
- /** DOCUMENT ME!! */
public double[] scores;
/**
// Make colours in constructor
// Why wasn't this done earlier?
- int i, iSize = scores.length;
+ int iSize = scores.length;
colors = new Color[scores.length];
- for (i = 0; i < iSize; i++)
+ for (int i = 0; i < iSize; i++)
{
- float red = (float) (scores[i] - (float) min) / (float) (max - min);
+ /*
+ * scale score between min and max to the range 0.0 - 1.0
+ */
+ float score = (float) (scores[i] - (float) min) / (float) (max - min);
- if (red > 1.0f)
+ if (score > 1.0f)
{
- red = 1.0f;
+ score = 1.0f;
}
- if (red < 0.0f)
+ if (score < 0.0f)
{
- red = 0.0f;
+ score = 0.0f;
}
- colors[i] = makeColour(red);
+ colors[i] = makeColour(score);
}
}
+ @Override
+ public Color findColour(char c, int j, SequenceI seq)
+ {
+ if (Comparison.isGap(c))
+ {
+ return Color.white;
+ }
+ return super.findColour(c);
+ }
+
/**
* DOCUMENT ME!
*
--- /dev/null
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+
+import java.awt.Color;
+
+import org.testng.annotations.Test;
+
+public class BuriedColourSchemeTest
+{
+ /**
+ * Turn colours are based on the scores in ResidueProperties.buried A = 1.7, R
+ * = 0.1, N = 0.4, D = 0.4... min = 0.05 max = 4.6
+ * <p>
+ * scores are scaled to c 0-1 between min and max and colour is (0, 1-c, c)
+ */
+ @Test(groups = "Functional")
+ public void testFindColour()
+ {
+ ScoreColourScheme scheme = new BuriedColourScheme();
+
+ float min = 0.05f;
+ float max = 4.6f;
+ float a = (1.7f - min) / (max - min);
+ assertEquals(scheme.findColour('A', 0, null), new Color(0, 1 - a, a));
+
+ float d = (0.4f - min) / (max - min);
+ assertEquals(scheme.findColour('D', 0, null), new Color(0, 1 - d, d));
+
+ assertEquals(scheme.findColour('-', 0, null), Color.WHITE);
+ }
+
+}
--- /dev/null
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+
+import java.awt.Color;
+
+import org.testng.annotations.Test;
+
+public class HelixColourSchemeTest
+{
+ /**
+ * Turn colours are based on the scores in ResidueProperties.helix A = 1.42, R
+ * = 0.98, N = 0.67, D = 1.01... min = 0.57 max = 1.51
+ * <p>
+ * scores are scaled to c 0-1 between min and max and colour is (c, 1-c, c)
+ */
+ @Test(groups = "Functional")
+ public void testFindColour()
+ {
+ ScoreColourScheme scheme = new HelixColourScheme();
+
+ float min = 0.57f;
+ float max = 1.51f;
+ float a = (1.42f - min) / (max - min);
+ assertEquals(scheme.findColour('A', 0, null), new Color(a, 1 - a, a));
+
+ float d = (1.01f - min) / (max - min);
+ assertEquals(scheme.findColour('D', 0, null), new Color(d, 1 - d, d));
+
+ assertEquals(scheme.findColour('-', 0, null), Color.WHITE);
+ }
+
+}
--- /dev/null
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+
+import java.awt.Color;
+
+import org.testng.annotations.Test;
+
+public class HydrophobicColourSchemeTest
+{
+ /**
+ * Turn colours are based on the scores in ResidueProperties.hyd A = 1.8, R =
+ * -4.5, N = -3.5, D = -3.5... min = -3.9 max = 4.5
+ * <p>
+ * scores are scaled to c 0-1 between min and max and colour is (c, 0, 1-c)
+ */
+ @Test(groups = "Functional")
+ public void testFindColour()
+ {
+ ScoreColourScheme scheme = new HydrophobicColourScheme();
+
+ float min = -3.9f;
+ float max = 4.5f;
+ float a = (1.8f - min) / (max - min);
+ assertEquals(scheme.findColour('A', 0, null),
+ new Color(a, 0, 1 - a));
+
+ float d = (-3.5f - min) / (max - min);
+ assertEquals(scheme.findColour('D', 0, null),
+ new Color(d, 0, 1 - d));
+
+ assertEquals(scheme.findColour('-', 0, null), Color.WHITE);
+ }
+
+}
--- /dev/null
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+
+import java.awt.Color;
+
+import org.testng.annotations.Test;
+
+public class StrandColourSchemeTest
+{
+ /**
+ * Turn colours are based on the scores in ResidueProperties.strand A = 0.83,
+ * R = 0.93, N = 0.89, D = 0.54... min = 0.37 max = 1.7
+ * <p>
+ * scores are scaled to c 0-1 between min and max and colour is (c, c, 1-c)
+ */
+ @Test(groups = "Functional")
+ public void testFindColour()
+ {
+ ScoreColourScheme scheme = new StrandColourScheme();
+
+ float min = 0.37f;
+ float max = 1.7f;
+ float a = (0.83f - min) / (max - min);
+ assertEquals(scheme.findColour('A', 0, null),
+ new Color(a, a, 1 - a));
+
+ float d = (0.54f - min) / (max - min);
+ assertEquals(scheme.findColour('D', 0, null),
+ new Color(d, d, 1 - d));
+
+ assertEquals(scheme.findColour('-', 0, null), Color.WHITE);
+ }
+
+}
--- /dev/null
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+
+import java.awt.Color;
+
+import org.testng.annotations.Test;
+
+public class TurnColourSchemeTest
+{
+ /**
+ * Turn colours are based on the scores in ResidueProperties.turn A = 0.66, R
+ * = 0.95, N = 1.56, D = 1.46... min = 0.47 max = 1.56
+ * <p>
+ * scores are scaled to c 0-1 between min and max and colour is (c, 1-c, 1-c)
+ */
+ @Test(groups = "Functional")
+ public void testFindColour()
+ {
+ ScoreColourScheme scheme = new TurnColourScheme();
+
+ float min = 0.47f;
+ float max = 1.56f;
+ float a = (0.66f - min) / (max - min);
+ assertEquals(scheme.findColour('A', 0, null),
+ new Color(a, 1 - a, 1 - a));
+
+ float d = (1.46f - min) / (max - min);
+ assertEquals(scheme.findColour('D', 0, null),
+ new Color(d, 1 - d, 1 - d));
+
+ assertEquals(scheme.findColour('-', 0, null), Color.WHITE);
+ }
+
+}
assertEquals(c1, cs.findColour('h'));
Color c2 = new Color(10, 20, 30);
assertEquals(c2, cs.findColour('c'));
+ assertEquals(Color.WHITE, cs.findColour('G'));
+ assertEquals(Color.WHITE, cs.findColour('-'));
+ assertEquals(Color.WHITE, cs.findColour('.'));
+ assertEquals(Color.WHITE, cs.findColour(' '));
cs = new UserColourScheme("white");
cs.parseAppletParameter("D,E=red; K,R,H=0022FF; c=10 , 20,30;t=orange;lowercase=blue;s=pink");
String param = cs.toAppletParameter();
assertEquals("D,E=ff0000;H,K,R=0022ff;c=0a141e", param);
}
+
+ /**
+ * Test for user colour scheme constructed with a colour per residue,
+ * including gap. Note this can currently be done from the User Defined
+ * Colours dialog, but not by parsing a colours parameter, as
+ * parseAppletParameter only recognises amino acid codes.
+ */
+ @Test(groups = "Functional")
+ public void testConstructor_coloursArray()
+ {
+ Color g = Color.green;
+ Color y = Color.yellow;
+ Color b = Color.blue;
+ Color r = Color.red;
+ // colours for ARNDCQEGHILKMFPSTWYVBZ and gap
+ Color[] colours = new Color[] { g, y, b, r, g, y, r, b, g, y, r, b, g,
+ y, r, b, g, y, r, b, g, y, r, g };
+ UserColourScheme cs = new UserColourScheme(colours);
+
+ assertEquals(g, cs.findColour('A'));
+ assertEquals(b, cs.findColour('n'));
+ assertEquals(g, cs.findColour('-'));
+ assertEquals(g, cs.findColour('.'));
+ assertEquals(g, cs.findColour(' '));
+ }
}