Clover icon

Coverage Report

  1. Project Clover database Wed Apr 1 2026 13:13:43 BST
  2. Package jalview.ext.jmol

File JmolParserTest.java

 
testStructurePAE: No PAE for second chain. expected:<1> but was:<0>
 

Code metrics

8
97
11
1
319
226
16
0.16
8.82
11
1.45

Classes

Class Line # Actions
JmolParserTest 55 97 16
0.844827684.5%
 

Contributing tests

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