2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ext.jmol;
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertTrue;
26 import jalview.datamodel.Alignment;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.ColumnSelection;
29 import jalview.datamodel.Sequence;
30 import jalview.datamodel.SequenceI;
31 import jalview.gui.AlignFrame;
32 import jalview.gui.JvOptionPane;
33 import jalview.gui.SequenceRenderer;
34 import jalview.schemes.JalviewColourScheme;
35 import jalview.structure.StructureMapping;
36 import jalview.structure.StructureMappingcommandSet;
37 import jalview.structure.StructureSelectionManager;
39 import java.util.HashMap;
41 import org.testng.annotations.BeforeClass;
42 import org.testng.annotations.Test;
44 public class JmolCommandsTest
47 @BeforeClass(alwaysRun = true)
48 public void setUpJvOptionPane()
50 JvOptionPane.setInteractiveMode(false);
51 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
54 @Test(groups = { "Functional" })
55 public void testGetColourBySequenceCommand_noFeatures()
57 SequenceI seq1 = new Sequence("seq1", "MHRSQTRALK");
58 SequenceI seq2 = new Sequence("seq2", "MRLEITQSGD");
59 AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
60 AlignFrame af = new AlignFrame(al, 800, 500);
61 SequenceRenderer sr = new SequenceRenderer(af.getViewport());
62 SequenceI[][] seqs = new SequenceI[][] { { seq1 }, { seq2 } };
63 String[] files = new String[] { "seq1.pdb", "seq2.pdb" };
64 StructureSelectionManager ssm = new StructureSelectionManager();
66 // need some mappings!
68 StructureMappingcommandSet[] commands = JmolCommands
69 .getColourBySequenceCommand(ssm, files, seqs, sr, af.alignPanel);
72 @Test(groups = { "Functional" })
73 public void testGetColourBySequenceCommands_hiddenColumns()
76 * load these sequences, coloured by Strand propensity,
77 * with columns 2-4 hidden
79 SequenceI seq1 = new Sequence("seq1", "MHRSQSSSGG");
80 SequenceI seq2 = new Sequence("seq2", "MVRSNGGSSS");
81 AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
82 AlignFrame af = new AlignFrame(al, 800, 500);
83 af.changeColour_actionPerformed(JalviewColourScheme.Strand.toString());
84 ColumnSelection cs = new ColumnSelection();
88 af.getViewport().setColumnSelection(cs);
89 af.hideSelColumns_actionPerformed(null);
90 SequenceRenderer sr = new SequenceRenderer(af.getViewport());
91 SequenceI[][] seqs = new SequenceI[][] { { seq1 }, { seq2 } };
92 String[] files = new String[] { "seq1.pdb", "seq2.pdb" };
93 StructureSelectionManager ssm = new StructureSelectionManager();
96 * map residues 1-10 to residues 21-30 (atoms 105-150) in structures
98 HashMap<Integer, int[]> map = new HashMap<Integer, int[]>();
99 for (int pos = 1; pos <= seq1.getLength(); pos++)
101 map.put(pos, new int[] { 20 + pos, 5 * (20 + pos) });
103 StructureMapping sm1 = new StructureMapping(seq1, "seq1.pdb", "pdb1",
105 ssm.addStructureMapping(sm1);
106 StructureMapping sm2 = new StructureMapping(seq2, "seq2.pdb", "pdb2",
108 ssm.addStructureMapping(sm2);
110 StructureMappingcommandSet[] commands = JmolCommands
111 .getColourBySequenceCommand(ssm, files, seqs, sr, af.alignPanel);
112 assertEquals(commands.length, 2);
113 assertEquals(commands[0].commands.length, 1);
115 String chainACommand = commands[0].commands[0];
116 // M colour is #82827d == (130, 130, 125) (see strand.html help page)
117 assertTrue(chainACommand
118 .contains(";select 21:A/1.1;color[130,130,125]"));
119 // H colour is #60609f == (96, 96, 159)
120 assertTrue(chainACommand.contains(";select 22:A/1.1;color[96,96,159]"));
121 // hidden columns are Gray (128, 128, 128)
122 assertTrue(chainACommand
123 .contains(";select 23-25:A/1.1;color[128,128,128]"));
124 // S and G are both coloured #4949b6 == (73, 73, 182)
125 assertTrue(chainACommand
126 .contains(";select 26-30:A/1.1;color[73,73,182]"));
128 String chainBCommand = commands[1].commands[0];
129 // M colour is #82827d == (130, 130, 125)
130 assertTrue(chainBCommand
131 .contains(";select 21:B/2.1;color[130,130,125]"));
132 // V colour is #ffff00 == (255, 255, 0)
133 assertTrue(chainBCommand
134 .contains(";select 22:B/2.1;color[255,255,0]"));
135 // hidden columns are Gray (128, 128, 128)
136 assertTrue(chainBCommand
137 .contains(";select 23-25:B/2.1;color[128,128,128]"));
138 // S and G are both coloured #4949b6 == (73, 73, 182)
139 assertTrue(chainBCommand
140 .contains(";select 26-30:B/2.1;color[73,73,182]"));