JAL-2360 test added
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 14 Dec 2016 15:36:52 +0000 (15:36 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 14 Dec 2016 15:36:52 +0000 (15:36 +0000)
test/jalview/schemes/ClustalxColourSchemeTest.java [new file with mode: 0644]

diff --git a/test/jalview/schemes/ClustalxColourSchemeTest.java b/test/jalview/schemes/ClustalxColourSchemeTest.java
new file mode 100644 (file)
index 0000000..16317d9
--- /dev/null
@@ -0,0 +1,88 @@
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.datamodel.AlignmentI;
+import jalview.gui.AlignFrame;
+import jalview.io.DataSourceType;
+import jalview.io.FileLoader;
+
+import java.awt.Color;
+
+import org.testng.annotations.Test;
+
+public class ClustalxColourSchemeTest
+{
+  // @formatter:off
+  private static final String FASTA = 
+          ">seq1\nAAANNNRQ\n" + 
+          ">seq2\nAAANNNRQ\n" + 
+          ">seq3\nAAANNNRQ\n" + 
+          ">seq4\nAAANNNRQ\n" + 
+          ">seq5\nAAANYYKQ\n" + 
+          ">seq6\nAAANYYKQ\n" + 
+          ">seq7\nAVKWYYKQ\n" + 
+          ">seq8\nKKKWYYQQ\n" + 
+          ">seq9\nKKKWWYQQ\n" + 
+          ">seq0\nKKKWWWQW\n";
+  // @formatter:on
+
+  @Test
+  public void testFindColour()
+  {
+    AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(FASTA,
+            DataSourceType.PASTE);
+    AlignmentI al = af.getViewport().getAlignment();
+    ColourSchemeI cs = new ClustalxColourScheme(al, null);
+
+    /*
+     * column 1 is 70% A which is above Clustalx threshold of 60%
+     */
+    Color clustalBlue = new Color(0.5f, 0.7f, 0.9f);
+    assertEquals(cs.findColour('A', 0, al.getSequenceAt(0)), clustalBlue);
+
+    /*
+     * column 2 is 70% A or V which is above Clustalx threshold for group
+     */
+    assertEquals(cs.findColour('A', 0, al.getSequenceAt(1)), clustalBlue);
+
+    /*
+     * column 3 is 60% A which is not above Clustalx threshold
+     * the Ks in the other rows are not in the same Clustalx group
+     */
+    assertEquals(cs.findColour('A', 2, al.getSequenceAt(1)), Color.white);
+
+    /*
+     * column 4 is 60% N which is above Clustalx threshold of 50%
+     */
+    Color clustalGreen = new Color(0.1f, 0.8f, 0.1f);
+    assertEquals(cs.findColour('N', 3, al.getSequenceAt(1)), clustalGreen);
+
+    /*
+     * column 5 is 40% N and 40% Y which fails to pass the threshold of
+     * 50% N or 85% either
+     */
+    assertEquals(cs.findColour('N', 4, al.getSequenceAt(1)), Color.white);
+
+    /*
+     * column 6 is 40% N and 50% Y which fails to pass the threshold of
+     * 85% for either
+     */
+    assertEquals(cs.findColour('N', 5, al.getSequenceAt(1)), Color.white);
+
+    /*
+     * column 7 is 40% R and 30% K which combine to make > 60%
+     */
+    Color clustalRed = new Color(0.9f, 0.2f, 0.1f);
+    assertEquals(cs.findColour('R', 6, al.getSequenceAt(1)), clustalRed);
+    assertEquals(cs.findColour('K', 6, al.getSequenceAt(7)), clustalRed);
+
+    /*
+     * column 8 is >85% Q which qualifies K and R to be red
+     */
+    assertEquals(cs.findColour('R', 7, al.getSequenceAt(1)), clustalRed);
+    assertEquals(cs.findColour('K', 7, al.getSequenceAt(1)), clustalRed);
+
+    // TODO more test cases; check if help documentation matches implementation
+  }
+}