From 13fd7bc6175d7aa66d8e161d21183e7e33c9150a Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 31 Mar 2017 10:40:58 +0100 Subject: [PATCH] JAL-2430 code tidy, unit test for Jmol hidden column colours --- src/jalview/ext/jmol/JmolCommands.java | 1 - src/jalview/ext/rbvi/chimera/ChimeraCommands.java | 1 - test/jalview/ext/jmol/JmolCommandsTest.java | 79 ++++++++++++++++++++ .../ext/rbvi/chimera/ChimeraCommandsTest.java | 2 +- 4 files changed, 80 insertions(+), 3 deletions(-) diff --git a/src/jalview/ext/jmol/JmolCommands.java b/src/jalview/ext/jmol/JmolCommands.java index 4212749..23e0a6f 100644 --- a/src/jalview/ext/jmol/JmolCommands.java +++ b/src/jalview/ext/jmol/JmolCommands.java @@ -110,7 +110,6 @@ public class JmolCommands */ if (!cs.isVisible(r)) { - // col = ColorUtils.darkerThan(col); col = Color.GRAY; } diff --git a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java index 1d8b944..95757fd 100644 --- a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java +++ b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java @@ -240,7 +240,6 @@ public class ChimeraCommands */ if (!cs.isVisible(r)) { - // colour = ColorUtils.darkerThan(colour); colour = Color.GRAY; } diff --git a/test/jalview/ext/jmol/JmolCommandsTest.java b/test/jalview/ext/jmol/JmolCommandsTest.java index 2c23311..3309adf 100644 --- a/test/jalview/ext/jmol/JmolCommandsTest.java +++ b/test/jalview/ext/jmol/JmolCommandsTest.java @@ -20,16 +20,24 @@ */ package jalview.ext.jmol; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; +import jalview.datamodel.ColumnSelection; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; import jalview.gui.JvOptionPane; import jalview.gui.SequenceRenderer; +import jalview.schemes.JalviewColourScheme; +import jalview.structure.StructureMapping; import jalview.structure.StructureMappingcommandSet; import jalview.structure.StructureSelectionManager; +import java.util.HashMap; + import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -60,4 +68,75 @@ public class JmolCommandsTest StructureMappingcommandSet[] commands = JmolCommands .getColourBySequenceCommand(ssm, files, seqs, sr, af.alignPanel); } + + @Test(groups = { "Functional" }) + public void testGetColourBySequenceCommands_hiddenColumns() + { + /* + * load these sequences, coloured by Strand propensity, + * with columns 2-4 hidden + */ + SequenceI seq1 = new Sequence("seq1", "MHRSQSSSGG"); + SequenceI seq2 = new Sequence("seq2", "MVRSNGGSSS"); + AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 }); + AlignFrame af = new AlignFrame(al, 800, 500); + af.changeColour_actionPerformed(JalviewColourScheme.Strand.toString()); + ColumnSelection cs = new ColumnSelection(); + cs.addElement(2); + cs.addElement(3); + cs.addElement(4); + af.getViewport().setColumnSelection(cs); + af.hideSelColumns_actionPerformed(null); + SequenceRenderer sr = new SequenceRenderer(af.getViewport()); + SequenceI[][] seqs = new SequenceI[][] { { seq1 }, { seq2 } }; + String[] files = new String[] { "seq1.pdb", "seq2.pdb" }; + StructureSelectionManager ssm = new StructureSelectionManager(); + + /* + * map residues 1-10 to residues 21-30 (atoms 105-150) in structures + */ + HashMap map = new HashMap(); + for (int pos = 1; pos <= seq1.getLength(); pos++) + { + map.put(pos, new int[] { 20 + pos, 5 * (20 + pos) }); + } + StructureMapping sm1 = new StructureMapping(seq1, "seq1.pdb", "pdb1", + "A", map, null); + ssm.addStructureMapping(sm1); + StructureMapping sm2 = new StructureMapping(seq2, "seq2.pdb", "pdb2", + "B", map, null); + ssm.addStructureMapping(sm2); + + StructureMappingcommandSet[] commands = JmolCommands + .getColourBySequenceCommand(ssm, files, seqs, sr, af.alignPanel); + assertEquals(commands.length, 2); + assertEquals(commands[0].commands.length, 1); + + String chainACommand = commands[0].commands[0]; + // M colour is #82827d == (130, 130, 125) (see strand.html help page) + assertTrue(chainACommand + .contains(";select 21:A/1.1;color[130,130,125]")); + // H colour is #60609f == (96, 96, 159) + assertTrue(chainACommand.contains(";select 22:A/1.1;color[96,96,159]")); + // hidden columns are Gray (128, 128, 128) + assertTrue(chainACommand + .contains(";select 23-25:A/1.1;color[128,128,128]")); + // S and G are both coloured #4949b6 == (73, 73, 182) + assertTrue(chainACommand + .contains(";select 26-30:A/1.1;color[73,73,182]")); + + String chainBCommand = commands[1].commands[0]; + // M colour is #82827d == (130, 130, 125) + assertTrue(chainBCommand + .contains(";select 21:B/2.1;color[130,130,125]")); + // V colour is #ffff00 == (255, 255, 0) + assertTrue(chainBCommand +.contains(";select 22:B/2.1;color[255,255,0]")); + // hidden columns are Gray (128, 128, 128) + assertTrue(chainBCommand + .contains(";select 23-25:B/2.1;color[128,128,128]")); + // S and G are both coloured #4949b6 == (73, 73, 182) + assertTrue(chainBCommand + .contains(";select 26-30:B/2.1;color[73,73,182]")); + } } diff --git a/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java b/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java index 49a951e..2c973ca 100644 --- a/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java +++ b/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java @@ -210,7 +210,7 @@ public class ChimeraCommandsTest assertTrue(theCommand.contains("color #82827d #0:21.A|#1:21.B")); // H colour is #60609f assertTrue(theCommand.contains("color #60609f #0:22.A")); - // V colour is ##ffff00 + // V colour is #ffff00 assertTrue(theCommand.contains("color #ffff00 #1:22.B")); // hidden columns are Gray (128, 128, 128) assertTrue(theCommand.contains("color #808080 #0:23-25.A|#1:23-25.B")); -- 1.7.10.2