Revert "Merge branch 'bug/JAL-3807_jpred-with-slivka' into alpha/JAL-3066_Jalview_212...
[jalview.git] / test / jalview / ext / jmol / JmolCommandsTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21 package jalview.ext.jmol;
22
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertTrue;
25
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;
38
39 import java.util.HashMap;
40
41 import org.testng.annotations.BeforeClass;
42 import org.testng.annotations.Test;
43
44 public class JmolCommandsTest
45 {
46
47   @BeforeClass(alwaysRun = true)
48   public void setUpJvOptionPane()
49   {
50     JvOptionPane.setInteractiveMode(false);
51     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
52   }
53
54   @Test(groups = { "Functional" })
55   public void testGetColourBySequenceCommand_noFeatures()
56   {
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 = StructureSelectionManager.getStructureSelectionManager(null);
65
66     // need some mappings!
67
68     StructureMappingcommandSet[] commands = JmolCommands
69             .getColourBySequenceCommand(ssm, files, seqs, sr, af.alignPanel);
70   }
71
72   @Test(groups = { "Functional" })
73   public void testGetColourBySequenceCommands_hiddenColumns()
74   {
75     /*
76      * load these sequences, coloured by Strand propensity,
77      * with columns 2-4 hidden
78      */
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();
85     cs.addElement(2);
86     cs.addElement(3);
87     cs.addElement(4);
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 = StructureSelectionManager.getStructureSelectionManager(null);
94   
95     /*
96      * map residues 1-10 to residues 21-30 (atoms 105-150) in structures
97      */
98     HashMap<Integer, int[]> map = new HashMap<Integer, int[]>();
99     for (int pos = 1; pos <= seq1.getLength(); pos++)
100     {
101       map.put(pos, new int[] { 20 + pos, 5 * (20 + pos) });
102     }
103     StructureMapping sm1 = new StructureMapping(seq1, "seq1.pdb", "pdb1",
104             "A", map, null);
105     ssm.addStructureMapping(sm1);
106     StructureMapping sm2 = new StructureMapping(seq2, "seq2.pdb", "pdb2",
107             "B", map, null);
108     ssm.addStructureMapping(sm2);
109   
110     StructureMappingcommandSet[] commands = JmolCommands
111             .getColourBySequenceCommand(ssm, files, seqs, sr, af.alignPanel);
112     assertEquals(commands.length, 2);
113     assertEquals(commands[0].commands.length, 1);
114
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]")); // first one
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]"));
127
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]"));
141   }
142 }