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.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertTrue;
26 import jalview.bin.Cache;
27 import jalview.datamodel.Alignment;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.SequenceI;
30 import jalview.gui.AlignFrame;
31 import jalview.io.AppletFormatAdapter;
32 import jalview.io.FileLoader;
34 import java.util.Vector;
36 import org.jmol.c.STR;
37 import org.testng.annotations.BeforeMethod;
38 import org.testng.annotations.Test;
40 import MCview.PDBfile;
46 public class JmolParserTest
49 * 1GAQ has been reduced to alpha carbons only
50 * 1QCF is the full PDB file including headers, HETATM etc
52 String[] testFile = new String[] { "./examples/1GAQ.txt",
53 "./test/jalview/ext/jmol/1xyz.pdb",
54 "./test/jalview/ext/jmol/1qcf.pdb" };
57 // a modified and very cut-down extract of 4UJ4
58 String pdbWithChainBreak =
59 "HEADER TRANSPORT PROTEIN 08-APR-15 4UJ4\n" +
60 // chain B has missing residues; these should all go in the same sequence:
61 "ATOM 1909 CA VAL B 358 21.329 -19.739 -67.740 1.00201.05 C\n" +
62 "ATOM 1916 CA GLY B 359 21.694 -23.563 -67.661 1.00198.09 C\n" +
63 "ATOM 1920 CA LYS B 367 32.471 -12.135 -77.100 1.00257.97 C\n" +
64 "ATOM 1925 CA ALA B 368 31.032 -9.324 -74.946 1.00276.01 C\n" +
65 // switch to chain C; should be a separate sequence
66 "ATOM 1930 CA SER C 369 32.589 -7.517 -71.978 1.00265.44 C\n" +
67 "ATOM 1936 CA ALA C 370 31.650 -6.849 -68.346 1.00249.48 C\n";
71 // a very cut-down extract of 1ejg
72 String pdbWithAltLoc =
73 "HEADER TRANSPORT PROTEIN 08-APR-15 1EJG\n" +
74 "ATOM 448 CA ALA A 24 6.619 16.195 1.970 1.00 1.65 C\n" +
75 "ATOM 458 CA ALEU A 25 3.048 14.822 1.781 0.57 1.48 C\n" +
76 // alternative residue 25 entries (with ILE instead of LEU) should be ignored:
77 "ATOM 478 CA BILE A 25 3.048 14.822 1.781 0.21 1.48 C\n" +
78 // including the next altloc causes the unit test to fail but it works with the full file
80 // "ATOM 479 CA CILE A 25 3.048 14.822 1.781 0.22 1.48 C\n" +
81 "ATOM 512 CA CYS A 26 4.137 11.461 3.154 1.00 1.52 C\n";
84 @BeforeMethod(alwaysRun = true)
87 Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
88 Boolean.TRUE.toString());
89 Cache.applicationProperties.setProperty("ADD_SS_ANN",
90 Boolean.TRUE.toString());
93 @Test(groups = { "Functional" })
94 public void testAlignmentLoader() throws Exception
96 for (String f : testFile)
98 FileLoader fl = new jalview.io.FileLoader(false);
100 .LoadFileWaitTillLoaded(f, AppletFormatAdapter.FILE);
101 validateSecStrRows(af.getViewport().getAlignment());
105 @Test(groups = { "Functional" })
106 public void testFileParser() throws Exception
108 for (String pdbStr : testFile)
110 PDBfile mctest = new PDBfile(false, false, false, pdbStr,
111 AppletFormatAdapter.FILE);
112 JmolParser jtest = new JmolParser(false, false, false, pdbStr,
113 jalview.io.AppletFormatAdapter.FILE);
114 Vector<SequenceI> seqs = jtest.getSeqs(), mcseqs = mctest.getSeqs();
117 "No sequences extracted from testfile\n"
118 + (jtest.hasWarningMessage() ? jtest.getWarningMessage()
119 : "(No warnings raised)"), seqs != null
121 for (SequenceI sq : seqs)
123 assertEquals("JMol didn't process " + pdbStr
124 + " to the same sequence as MCView",
125 sq.getSequenceAsString(), mcseqs.remove(0)
126 .getSequenceAsString());
127 AlignmentI al = new Alignment(new SequenceI[] { sq });
128 validateSecStrRows(al);
133 private void validateSecStrRows(AlignmentI al)
135 if (!al.isNucleotide())
137 for (SequenceI asq : al.getSequences())
140 boolean hasDs = false;
141 while (sq.getDatasetSequence() != null
142 && sq.getAnnotation() == null)
144 sq = sq.getDatasetSequence();
147 checkFirstAAIsAssoc(sq);
150 // also verify if alignment sequence has annotation on it
151 // that is correctly mapped
152 checkFirstAAIsAssoc(asq);
158 private void checkFirstAAIsAssoc(SequenceI sq)
160 assertTrue("No secondary structure assigned for protein sequence.",
161 sq.getAnnotation() != null && sq.getAnnotation().length >= 1
162 && sq.getAnnotation()[0].hasIcons);
164 "Secondary structure not associated for sequence "
165 + sq.getName(), sq.getAnnotation()[0].sequenceRef == sq);
169 * Test parsing a chain with missing residues
173 @Test(groups = { "Functional" })
174 public void testParse_missingResidues() throws Exception
176 PDBfile mctest = new PDBfile(false, false, false, pdbWithChainBreak,
177 AppletFormatAdapter.PASTE);
178 boolean annotFromStructure = false;
179 boolean localSecondaryStruct = false;
180 boolean serviceSecondaryStruct = false;
181 JmolParser jtest = new JmolParser(annotFromStructure,
182 localSecondaryStruct, serviceSecondaryStruct,
184 jalview.io.AppletFormatAdapter.PASTE);
185 Vector<SequenceI> seqs = jtest.getSeqs();
186 Vector<SequenceI> mcseqs = mctest.getSeqs();
188 assertEquals("Failed to find 2 sequences\n", 2, seqs.size());
189 assertEquals("Failed to find 2 sequences\n", 2, mcseqs.size());
190 assertEquals("VGKA", seqs.get(0).getSequenceAsString());
191 assertEquals("VGKA", mcseqs.get(0).getSequenceAsString());
192 assertEquals("SA", seqs.get(1).getSequenceAsString());
193 assertEquals("SA", mcseqs.get(1).getSequenceAsString());
197 * Test parsing a chain with 'altloc' residues
201 @Test(groups = { "Functional" })
202 public void testParse_alternativeResidues() throws Exception
204 PDBfile mctest = new PDBfile(false, false, false, pdbWithAltLoc,
205 AppletFormatAdapter.PASTE);
206 boolean annotFromStructure = false;
207 boolean localSecondaryStruct = false;
208 boolean serviceSecondaryStruct = false;
209 JmolParser jtest = new JmolParser(annotFromStructure,
210 localSecondaryStruct, serviceSecondaryStruct, pdbWithAltLoc,
211 jalview.io.AppletFormatAdapter.PASTE);
212 Vector<SequenceI> seqs = jtest.getSeqs();
213 Vector<SequenceI> mcseqs = mctest.getSeqs();
215 assertEquals("Failed to find 1 sequence\n", 1, seqs.size());
216 assertEquals("Failed to find 1 sequence\n", 1, mcseqs.size());
217 assertEquals("ALC", seqs.get(0).getSequenceAsString());
218 assertEquals("ALC", mcseqs.get(0).getSequenceAsString());
221 @Test(groups = "Functional")
222 public void testSetSecondaryStructure()
224 JmolParser testee = new JmolParser();
225 char[] struct = new char[10];
226 char[] structCode = new char[10];
230 testee.setSecondaryStructure(STR.NONE, 0, struct, structCode);
231 testee.setSecondaryStructure(STR.HELIX, 1, struct, structCode);
232 testee.setSecondaryStructure(STR.HELIX310, 2, struct, structCode);
233 testee.setSecondaryStructure(STR.HELIXALPHA, 3, struct, structCode);
234 testee.setSecondaryStructure(STR.HELIXPI, 4, struct, structCode);
235 testee.setSecondaryStructure(STR.SHEET, 5, struct, structCode);
237 assertEquals(0, struct[0]);
238 assertEquals('H', struct[1]);
239 assertEquals('3', struct[2]);
240 assertEquals('H', struct[3]);
241 assertEquals('P', struct[4]);
242 assertEquals('E', struct[5]);
244 assertEquals(0, structCode[0]);
245 assertEquals('H', structCode[1]);
246 assertEquals('H', structCode[2]);
247 assertEquals('H', structCode[3]);
248 assertEquals('H', structCode[4]);
249 assertEquals('E', structCode[5]);