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.
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNotNull;
25 import static org.testng.AssertJUnit.assertTrue;
27 import jalview.bin.Cache;
28 import jalview.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.AlignmentI;
30 import jalview.datamodel.PDBEntry;
31 import jalview.datamodel.SequenceFeature;
32 import jalview.datamodel.SequenceI;
33 import jalview.datamodel.features.SequenceFeatures;
34 import jalview.gui.AlignFrame;
35 import jalview.gui.JvOptionPane;
36 import jalview.structure.StructureImportSettings;
37 import jalview.structure.StructureImportSettings.StructureParser;
40 import java.util.List;
42 import org.junit.Assert;
43 import org.testng.annotations.AfterClass;
44 import org.testng.annotations.BeforeClass;
45 import org.testng.annotations.BeforeMethod;
46 import org.testng.annotations.Test;
48 public class AnnotatedPDBFileInputTest
51 @BeforeClass(alwaysRun = true)
52 public void setUpJvOptionPane()
54 JvOptionPane.setInteractiveMode(false);
55 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
63 * Ensure 'process secondary structure from PDB and add annotations' are set
64 * in preferences, and load PDB example file 1gaq
68 @BeforeMethod(alwaysRun = true)
69 public void setup() throws Exception
71 Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
72 Boolean.TRUE.toString());
73 Cache.applicationProperties.setProperty("ADD_SS_ANN",
74 Boolean.TRUE.toString());
75 FileLoader loader = new FileLoader(false);
76 AlignFrame af = loader.LoadFileWaitTillLoaded("examples/1gaq.txt",
78 al = af.getViewport().getAlignment();
79 pdbId = al.getSequenceAt(0).getDatasetSequence().getAllPDBEntries()
81 StructureImportSettings.setDefaultStructureFileFormat("PDB");
82 // StructureImportSettings
83 // .setDefaultPDBFileParser(StructureParser.JALVIEW_PARSER);
86 @Test(groups = { "Functional" })
87 public void checkNoDuplicates()
89 // not strictly a requirement, but strange things may happen if multiple
90 // instances of the same annotation are placed in the alignment annotation
92 assertNotNull(al.getAlignmentAnnotation());
93 // verify that all sequence annotation is doubly referenced
94 AlignmentAnnotation[] avec = al.getAlignmentAnnotation();
95 for (int p = 0; p < avec.length; p++)
97 for (int q = p + 1; q < avec.length; q++)
99 assertTrue("Found a duplicate annotation row " + avec[p].label,
105 @Test(groups = { "Functional" }, enabled = false)
106 public void checkPDBannotationSource()
109 "This test is incorrect - does not verify that JmolParser's annotation rows can be recognised as generated by the Jmol parser.");
110 for (SequenceI asq : al.getSequences())
112 for (AlignmentAnnotation aa : asq.getAnnotation())
115 System.out.println("CalcId: " + aa.getCalcId());
116 if (StructureImportSettings.getDefaultPDBFileParser()
117 .equals(StructureParser.JALVIEW_PARSER))
119 assertTrue(MCview.PDBfile.isCalcIdForFile(aa, pdbId));
126 * Check sequence features have been added
128 @Test(groups = { "Functional" })
129 public void checkPDBSequenceFeatures()
134 List<SequenceFeature> sf = al.getSequenceAt(0).getSequenceFeatures();
135 SequenceFeatures.sortFeatures(sf, true);
136 assertEquals(296, sf.size());
137 assertEquals("RESNUM", sf.get(0).getType());
138 assertEquals("GLU: 19 1gaqA", sf.get(0).getDescription());
139 assertEquals("RESNUM", sf.get(295).getType());
140 assertEquals("TYR: 314 1gaqA", sf.get(295).getDescription());
145 sf = al.getSequenceAt(1).getSequenceFeatures();
146 SequenceFeatures.sortFeatures(sf, true);
147 assertEquals(98, sf.size());
148 assertEquals("RESNUM", sf.get(0).getType());
149 assertEquals("ALA: 1 1gaqB", sf.get(0).getDescription());
150 assertEquals("RESNUM", sf.get(97).getType());
151 assertEquals("ALA: 98 1gaqB", sf.get(97).getDescription());
156 sf = al.getSequenceAt(2).getSequenceFeatures();
157 SequenceFeatures.sortFeatures(sf, true);
158 assertEquals(296, sf.size());
159 assertEquals("RESNUM", sf.get(0).getType());
160 assertEquals("GLU: 19 1gaqC", sf.get(0).getDescription());
161 assertEquals("RESNUM", sf.get(295).getType());
162 assertEquals("TYR: 314 1gaqC", sf.get(295).getDescription());
165 @Test(groups = { "Functional" })
166 public void checkAnnotationWiring()
168 assertTrue(al.getAlignmentAnnotation() != null);
169 // verify that all sequence annotation is doubly referenced
170 for (AlignmentAnnotation aa : al.getAlignmentAnnotation())
172 if (aa.sequenceRef != null)
174 assertTrue(al.getSequences().contains(aa.sequenceRef));
175 assertNotNull(aa.sequenceRef.getAnnotation());
176 boolean found = false;
177 for (AlignmentAnnotation sqan : aa.sequenceRef.getAnnotation())
186 "Couldn't find sequence associated annotation "
188 + " on the sequence it is associated with.\nSequence associated editing will fail.",
195 * @throws java.lang.Exception
197 @BeforeClass(alwaysRun = true)
198 public static void setUpBeforeClass() throws Exception
200 jalview.bin.Jalview.main(new String[] { "-props",
201 "test/jalview/io/testProps.jvprops" });
205 * @throws java.lang.Exception
207 @AfterClass(alwaysRun = true)
208 public static void tearDownAfterClass() throws Exception
210 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
214 @Test(groups = { "Functional" })
215 public void testJalviewProjectRelocationAnnotation() throws Exception
218 String inFile = "examples/1gaq.txt";
219 String tfile = File.createTempFile("JalviewTest", ".jvp")
221 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
222 inFile, DataSourceType.FILE);
223 assertTrue("Didn't read input file " + inFile, af != null);
224 assertTrue("Failed to store as a project.",
225 af.saveAlignment(tfile, FileFormat.Jalview));
226 af.closeMenuItem_actionPerformed(true);
228 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
229 DataSourceType.FILE);
230 assertTrue("Failed to import new project", af != null);
231 for (SequenceI asq : af.getViewport().getAlignment().getSequences())
234 while (sq.getDatasetSequence() != null)
236 sq = sq.getDatasetSequence();
238 assertNotNull(sq.getAllPDBEntries());
239 assertEquals("Expected only one PDB ID", 1, sq.getAllPDBEntries()
241 for (PDBEntry pdbentry : sq.getAllPDBEntries())
243 System.err.println("PDB Entry " + pdbentry.getId() + " "
244 + pdbentry.getFile());
245 boolean exists = false, found = false;
246 for (AlignmentAnnotation ana : sq.getAnnotation())
248 System.err.println("CalcId " + ana.getCalcId());
249 if (ana.getCalcId() != null
250 && MCview.PDBfile.isCalcIdHandled(ana.getCalcId()))
253 if (MCview.PDBfile.isCalcIdForFile(ana, pdbentry.getId()))
261 assertTrue("Couldn't find any annotation for " + pdbentry.getId()
262 + " (file handle " + pdbentry.getFile() + ")", found);