Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.ext.jmol

File JmolCommandsTest.java

 

Code metrics

2
46
3
1
142
92
4
0.09
15.33
3
1.33

Classes

Class Line # Actions
JmolCommandsTest 44 46 4 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

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  1 toggle @BeforeClass(alwaysRun = true)
48    public void setUpJvOptionPane()
49    {
50  1 JvOptionPane.setInteractiveMode(false);
51  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
52    }
53   
 
54  1 toggle @Test(groups = { "Functional" })
55    public void testGetColourBySequenceCommand_noFeatures()
56    {
57  1 SequenceI seq1 = new Sequence("seq1", "MHRSQTRALK");
58  1 SequenceI seq2 = new Sequence("seq2", "MRLEITQSGD");
59  1 AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
60  1 AlignFrame af = new AlignFrame(al, 800, 500);
61  1 SequenceRenderer sr = new SequenceRenderer(af.getViewport());
62  1 SequenceI[][] seqs = new SequenceI[][] { { seq1 }, { seq2 } };
63  1 String[] files = new String[] { "seq1.pdb", "seq2.pdb" };
64  1 StructureSelectionManager ssm = new StructureSelectionManager();
65   
66    // need some mappings!
67   
68  1 StructureMappingcommandSet[] commands = JmolCommands
69    .getColourBySequenceCommand(ssm, files, seqs, sr, af.alignPanel);
70    }
71   
 
72  1 toggle @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  1 SequenceI seq1 = new Sequence("seq1", "MHRSQSSSGG");
80  1 SequenceI seq2 = new Sequence("seq2", "MVRSNGGSSS");
81  1 AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
82  1 AlignFrame af = new AlignFrame(al, 800, 500);
83  1 af.changeColour_actionPerformed(JalviewColourScheme.Strand.toString());
84  1 ColumnSelection cs = new ColumnSelection();
85  1 cs.addElement(2);
86  1 cs.addElement(3);
87  1 cs.addElement(4);
88  1 af.getViewport().setColumnSelection(cs);
89  1 af.hideSelColumns_actionPerformed(null);
90  1 SequenceRenderer sr = new SequenceRenderer(af.getViewport());
91  1 SequenceI[][] seqs = new SequenceI[][] { { seq1 }, { seq2 } };
92  1 String[] files = new String[] { "seq1.pdb", "seq2.pdb" };
93  1 StructureSelectionManager ssm = new StructureSelectionManager();
94   
95    /*
96    * map residues 1-10 to residues 21-30 (atoms 105-150) in structures
97    */
98  1 HashMap<Integer, int[]> map = new HashMap<Integer, int[]>();
99  11 for (int pos = 1; pos <= seq1.getLength(); pos++)
100    {
101  10 map.put(pos, new int[] { 20 + pos, 5 * (20 + pos) });
102    }
103  1 StructureMapping sm1 = new StructureMapping(seq1, "seq1.pdb", "pdb1",
104    "A", map, null);
105  1 ssm.addStructureMapping(sm1);
106  1 StructureMapping sm2 = new StructureMapping(seq2, "seq2.pdb", "pdb2",
107    "B", map, null);
108  1 ssm.addStructureMapping(sm2);
109   
110  1 StructureMappingcommandSet[] commands = JmolCommands
111    .getColourBySequenceCommand(ssm, files, seqs, sr, af.alignPanel);
112  1 assertEquals(commands.length, 2);
113  1 assertEquals(commands[0].commands.length, 1);
114   
115  1 String chainACommand = commands[0].commands[0];
116    // M colour is #82827d == (130, 130, 125) (see strand.html help page)
117  1 assertTrue(chainACommand
118    .contains("select 21:A/1.1;color[130,130,125]")); // first one
119    // H colour is #60609f == (96, 96, 159)
120  1 assertTrue(chainACommand.contains(";select 22:A/1.1;color[96,96,159]"));
121    // hidden columns are Gray (128, 128, 128)
122  1 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  1 assertTrue(chainACommand
126    .contains(";select 26-30:A/1.1;color[73,73,182]"));
127   
128  1 String chainBCommand = commands[1].commands[0];
129    // M colour is #82827d == (130, 130, 125)
130  1 assertTrue(chainBCommand
131    .contains("select 21:B/2.1;color[130,130,125]"));
132    // V colour is #ffff00 == (255, 255, 0)
133  1 assertTrue(chainBCommand
134    .contains(";select 22:B/2.1;color[255,255,0]"));
135    // hidden columns are Gray (128, 128, 128)
136  1 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  1 assertTrue(chainBCommand
140    .contains(";select 26-30:B/2.1;color[73,73,182]"));
141    }
142    }