Clover icon

jalviewX

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

File JmolParserTest.java

 
testFileParser: Problem opening 1GAQ.txt : FILE CANNOT BE OPENED FOR READING
 

Code metrics

8
83
10
1
285
198
15
0.18
8.3
10
1.5

Classes

Class Line # Actions
JmolParserTest 51 83 15 37
0.6336633663.4%
 

Contributing tests

This file is covered by 6 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.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertNotNull;
25    import static org.testng.AssertJUnit.assertTrue;
26   
27    import jalview.bin.Cache;
28    import jalview.datamodel.Alignment;
29    import jalview.datamodel.AlignmentI;
30    import jalview.datamodel.SequenceI;
31    import jalview.gui.AlignFrame;
32    import jalview.gui.JvOptionPane;
33    import jalview.io.DataSourceType;
34    import jalview.io.FileLoader;
35    import jalview.structure.StructureImportSettings;
36    import jalview.structure.StructureImportSettings.StructureParser;
37   
38    import java.util.Vector;
39   
40    import org.jmol.c.STR;
41    import org.testng.annotations.BeforeClass;
42    import org.testng.annotations.BeforeMethod;
43    import org.testng.annotations.Test;
44   
45    import mc_view.PDBfile;
46   
47    /**
48    * @author jimp
49    *
50    */
 
51    public class JmolParserTest
52    {
53   
 
54  1 toggle @BeforeClass(alwaysRun = true)
55    public void setUpJvOptionPane()
56    {
57  1 JvOptionPane.setInteractiveMode(false);
58  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
59    }
60   
61    /*
62    * 1GAQ has been reduced to alpha carbons only
63    * 1QCF is the full PDB file including headers, HETATM etc
64    */
65    String[] testFile = new String[] { "./examples/1GAQ.txt",
66    "./test/jalview/ext/jmol/1xyz.pdb",
67    "./test/jalview/ext/jmol/1qcf.pdb" };
68   
69    //@formatter:off
70    // a modified and very cut-down extract of 4UJ4
71    String pastePDBDataWithChainBreak =
72    "HEADER TRANSPORT PROTEIN 08-APR-15 4UJ4\n" +
73    // chain B has missing residues; these should all go in the same sequence:
74    "ATOM 1909 CA VAL B 358 21.329 -19.739 -67.740 1.00201.05 C\n" +
75    "ATOM 1916 CA GLY B 359 21.694 -23.563 -67.661 1.00198.09 C\n" +
76    "ATOM 1920 CA LYS B 367 32.471 -12.135 -77.100 1.00257.97 C\n" +
77    "ATOM 1925 CA ALA B 368 31.032 -9.324 -74.946 1.00276.01 C\n" +
78    // switch to chain C; should be a separate sequence
79    "ATOM 1930 CA SER C 369 32.589 -7.517 -71.978 1.00265.44 C\n" +
80    "ATOM 1936 CA ALA C 370 31.650 -6.849 -68.346 1.00249.48 C\n";
81    //@formatter:on
82   
83    //@formatter:off
84    // a very cut-down extract of 1ejg
85    String pdbWithAltLoc =
86    "HEADER TRANSPORT PROTEIN 08-APR-15 1EJG\n" +
87    "ATOM 448 CA ALA A 24 6.619 16.195 1.970 1.00 1.65 C\n" +
88    "ATOM 458 CA ALEU A 25 3.048 14.822 1.781 0.57 1.48 C\n" +
89    // alternative residue 25 entries (with ILE instead of LEU) should be ignored:
90    "ATOM 478 CA BILE A 25 3.048 14.822 1.781 0.21 1.48 C\n" +
91    // including the next altloc causes the unit test to fail but it works with the full file
92    // not sure why!
93    // "ATOM 479 CA CILE A 25 3.048 14.822 1.781 0.22 1.48 C\n" +
94    "ATOM 512 CA CYS A 26 4.137 11.461 3.154 1.00 1.52 C\n";
95    //@formatter:on
96   
 
97  6 toggle @BeforeMethod(alwaysRun = true)
98    public void setUp()
99    {
100  6 Cache.loadProperties("test/jalview/io/testProps.jvprops");
101  6 Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
102    Boolean.TRUE.toString());
103  6 Cache.applicationProperties.setProperty("ADD_TEMPFACT_ANN",
104    Boolean.FALSE.toString());
105  6 Cache.applicationProperties.setProperty("ADD_SS_ANN",
106    Boolean.TRUE.toString());
107  6 StructureImportSettings.setDefaultStructureFileFormat("PDB");
108  6 StructureImportSettings
109    .setDefaultPDBFileParser(StructureParser.JALVIEW_PARSER);
110    }
111   
 
112  0 toggle @Test(groups = { "Functional" })
113    public void testAlignmentLoader() throws Exception
114    {
115  0 for (String f : testFile)
116    {
117  0 FileLoader fl = new jalview.io.FileLoader(false);
118  0 AlignFrame af = fl.LoadFileWaitTillLoaded(f, DataSourceType.FILE);
119  0 Test failure here validateSecStrRows(af.getViewport().getAlignment());
120    }
121    }
122   
 
123  0 toggle @Test(groups = { "Functional" })
124    public void testFileParser() throws Exception
125    {
126  0 for (String pdbStr : testFile)
127    {
128  0 Test failure here PDBfile mctest = new PDBfile(false, false, false, pdbStr,
129    DataSourceType.FILE);
130  0 JmolParser jtest = new JmolParser(pdbStr, DataSourceType.FILE);
131  0 Vector<SequenceI> seqs = jtest.getSeqs(), mcseqs = mctest.getSeqs();
132   
133  0 assertTrue(
134    "No sequences extracted from testfile\n"
135  0 + (jtest.hasWarningMessage() ? jtest.getWarningMessage()
136    : "(No warnings raised)"), seqs != null
137    && seqs.size() > 0);
138  0 for (SequenceI sq : seqs)
139    {
140  0 assertEquals("JMol didn't process " + pdbStr
141    + " to the same sequence as MCView",
142    sq.getSequenceAsString(), mcseqs.remove(0)
143    .getSequenceAsString());
144  0 AlignmentI al = new Alignment(new SequenceI[] { sq });
145  0 validateSecStrRows(al);
146    }
147    }
148   
149    }
150   
 
151  0 toggle private void validateSecStrRows(AlignmentI al)
152    {
153  0 if (!al.isNucleotide())
154    {
155  0 for (SequenceI asq : al.getSequences())
156    {
157  0 SequenceI sq = asq;
158  0 boolean hasDs = false;
159  0 while (sq.getDatasetSequence() != null
160    && sq.getAnnotation() == null)
161    {
162  0 sq = sq.getDatasetSequence();
163  0 hasDs = true;
164    }
165  0 checkFirstAAIsAssoc(sq);
166  0 if (hasDs)
167    {
168    // also verify if alignment sequence has annotation on it
169    // that is correctly mapped
170  0 checkFirstAAIsAssoc(asq);
171    }
172    }
173    }
174    }
175   
 
176  0 toggle private void checkFirstAAIsAssoc(SequenceI sq)
177    {
178  0 assertTrue("No secondary structure assigned for protein sequence for "
179    + sq.getName(),
180    sq.getAnnotation() != null && sq.getAnnotation().length >= 1
181    && sq.getAnnotation()[0].hasIcons);
182  0 assertTrue(
183    "Secondary structure not associated for sequence "
184    + sq.getName(), sq.getAnnotation()[0].sequenceRef == sq);
185    }
186   
187    /**
188    * Test parsing a chain with missing residues
189    *
190    * @throws Exception
191    */
 
192  1 toggle @Test(groups = { "Functional" })
193    public void testParse_missingResidues() throws Exception
194    {
195  1 PDBfile mctest = new PDBfile(false, false, false,
196    pastePDBDataWithChainBreak, DataSourceType.PASTE);
197  1 JmolParser jtest = new JmolParser(pastePDBDataWithChainBreak, DataSourceType.PASTE);
198  1 Vector<SequenceI> seqs = jtest.getSeqs();
199  1 Vector<SequenceI> mcseqs = mctest.getSeqs();
200   
201  1 assertEquals("Failed to find 2 sequences\n", 2, seqs.size());
202  1 assertEquals("Failed to find 2 sequences\n", 2, mcseqs.size());
203  1 assertEquals("VGKA", seqs.get(0).getSequenceAsString());
204  1 assertEquals("VGKA", mcseqs.get(0).getSequenceAsString());
205  1 assertEquals("SA", seqs.get(1).getSequenceAsString());
206  1 assertEquals("SA", mcseqs.get(1).getSequenceAsString());
207    }
208   
209    /**
210    * Test parsing a chain with 'altloc' residues
211    *
212    * @throws Exception
213    */
 
214  1 toggle @Test(groups = { "Functional" })
215    public void testParse_alternativeResidues() throws Exception
216    {
217  1 PDBfile mctest = new PDBfile(false, false, false, pdbWithAltLoc,
218    DataSourceType.PASTE);
219  1 JmolParser jtest = new JmolParser(pdbWithAltLoc,
220    DataSourceType.PASTE);
221  1 Vector<SequenceI> seqs = jtest.getSeqs();
222  1 Vector<SequenceI> mcseqs = mctest.getSeqs();
223   
224  1 assertEquals("Failed to find 1 sequence\n", 1, seqs.size());
225  1 assertEquals("Failed to find 1 sequence\n", 1, mcseqs.size());
226  1 assertEquals("ALC", seqs.get(0).getSequenceAsString());
227  1 assertEquals("ALC", mcseqs.get(0).getSequenceAsString());
228    }
229   
 
230  1 toggle @Test(groups = "Functional")
231    public void testSetSecondaryStructure()
232    {
233  1 JmolParser testee = new JmolParser();
234  1 char[] struct = new char[10];
235  1 char[] structCode = new char[10];
236  1 struct[0] = '1';
237  1 structCode[0] = '1';
238   
239  1 testee.setSecondaryStructure(STR.NONE, 0, struct, structCode);
240  1 testee.setSecondaryStructure(STR.HELIX, 1, struct, structCode);
241  1 testee.setSecondaryStructure(STR.HELIX310, 2, struct, structCode);
242  1 testee.setSecondaryStructure(STR.HELIXALPHA, 3, struct, structCode);
243  1 testee.setSecondaryStructure(STR.HELIXPI, 4, struct, structCode);
244  1 testee.setSecondaryStructure(STR.SHEET, 5, struct, structCode);
245   
246  1 assertEquals(0, struct[0]);
247  1 assertEquals('H', struct[1]);
248  1 assertEquals('3', struct[2]);
249  1 assertEquals('H', struct[3]);
250  1 assertEquals('P', struct[4]);
251  1 assertEquals('E', struct[5]);
252   
253  1 assertEquals(0, structCode[0]);
254  1 assertEquals('H', structCode[1]);
255  1 assertEquals('H', structCode[2]);
256  1 assertEquals('H', structCode[3]);
257  1 assertEquals('H', structCode[4]);
258  1 assertEquals('E', structCode[5]);
259    }
260   
 
261  1 toggle @Test(groups = "Functional")
262    public void testLocalPDBId() throws Exception
263    {
264  1 JmolParser structureData;
265    /*
266    * reads a local structure
267    */
268  1 structureData = new JmolParser("examples/testdata/localstruct.pdb",
269    DataSourceType.FILE);
270  1 assertNotNull(structureData);
271    /*
272    * local structure files should yield a false ID based on the filename
273    */
274  1 assertNotNull(structureData.getId());
275  1 assertEquals(structureData.getId(), "localstruct");
276  1 assertNotNull(structureData.getSeqs());
277    /*
278    * the ID is also the group for features derived from structure data
279    */
280  1 String featureGroup = structureData.getSeqs().get(0)
281    .getSequenceFeatures().get(0).featureGroup;
282  1 assertNotNull(featureGroup);
283  1 assertEquals(featureGroup, "localstruct");
284    }
285    }