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.StructureSelectionManager;
38 import java.util.HashMap;
40 import org.testng.annotations.BeforeClass;
41 import org.testng.annotations.Test;
43 public class JmolCommandsTest
46 @BeforeClass(alwaysRun = true)
47 public void setUpJvOptionPane()
49 JvOptionPane.setInteractiveMode(false);
50 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
53 @Test(groups = { "Functional" })
54 public void testGetColourBySequenceCommand_noFeatures()
56 SequenceI seq1 = new Sequence("seq1", "MHRSQTRALK");
57 SequenceI seq2 = new Sequence("seq2", "MRLEITQSGD");
58 AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
59 AlignFrame af = new AlignFrame(al, 800, 500);
60 SequenceRenderer sr = new SequenceRenderer(af.getViewport());
61 SequenceI[][] seqs = new SequenceI[][] { { seq1 }, { seq2 } };
62 String[] files = new String[] { "seq1.pdb", "seq2.pdb" };
63 StructureSelectionManager ssm = new StructureSelectionManager();
65 // need some mappings!
67 String[] commands = new JmolCommands().colourBySequence(ssm, files,
68 seqs, sr, af.alignPanel);
69 assertEquals(commands.length, 0);
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<>();
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 String[] commands = new JmolCommands().colourBySequence(ssm, files,
111 seqs, sr, af.alignPanel);
112 assertEquals(commands.length, 2);
114 String chainACommand = commands[0];
115 // M colour is #82827d == (130, 130, 125) (see strand.html help page)
117 chainACommand.contains("select 21:A/1.1;color[130,130,125]")); // first
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)
126 chainACommand.contains(";select 26-30:A/1.1;color[73,73,182]"));
128 String chainBCommand = commands[1];
129 // M colour is #82827d == (130, 130, 125)
131 chainBCommand.contains("select 21:B/2.1;color[130,130,125]"));
132 // V colour is #ffff00 == (255, 255, 0)
133 assertTrue(chainBCommand.contains(";select 22:B/2.1;color[255,255,0]"));
134 // hidden columns are Gray (128, 128, 128)
135 assertTrue(chainBCommand
136 .contains(";select 23-25:B/2.1;color[128,128,128]"));
137 // S and G are both coloured #4949b6 == (73, 73, 182)
139 chainBCommand.contains(";select 26-30:B/2.1;color[73,73,182]"));