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.gui.AlignFrame;
34 import jalview.gui.JvOptionPane;
35 import jalview.structure.StructureImportSettings;
36 import jalview.structure.StructureImportSettings.StructureParser;
40 import org.testng.annotations.AfterClass;
41 import org.testng.annotations.BeforeClass;
42 import org.testng.annotations.BeforeMethod;
43 import org.testng.annotations.Test;
45 public class AnnotatedPDBFileInputTest
48 @BeforeClass(alwaysRun = true)
49 public void setUpJvOptionPane()
51 JvOptionPane.setInteractiveMode(false);
52 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
60 * Ensure 'process secondary structure from PDB and add annotations' are set
61 * in preferences, and load PDB example file 1gaq
65 @BeforeMethod(alwaysRun = true)
66 public void setup() throws Exception
68 Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
69 Boolean.TRUE.toString());
70 Cache.applicationProperties.setProperty("ADD_SS_ANN",
71 Boolean.TRUE.toString());
72 FileLoader loader = new FileLoader(false);
73 AlignFrame af = loader.LoadFileWaitTillLoaded("examples/1gaq.txt",
75 al = af.getViewport().getAlignment();
76 pdbId = al.getSequenceAt(0).getDatasetSequence().getAllPDBEntries()
78 StructureImportSettings.setDefaultStructureFileFormat("PDB");
79 // StructureImportSettings
80 // .setDefaultPDBFileParser(StructureParser.JALVIEW_PARSER);
83 @Test(groups = { "Functional" })
84 public void checkNoDuplicates()
86 // not strictly a requirement, but strange things may happen if multiple
87 // instances of the same annotation are placed in the alignment annotation
89 assertNotNull(al.getAlignmentAnnotation());
90 // verify that all sequence annotation is doubly referenced
91 AlignmentAnnotation[] avec = al.getAlignmentAnnotation();
92 for (int p = 0; p < avec.length; p++)
94 for (int q = p + 1; q < avec.length; q++)
96 assertTrue("Found a duplicate annotation row " + avec[p].label,
102 @Test(groups = { "Functional" })
103 public void checkPDBannotationSource()
106 for (SequenceI asq : al.getSequences())
108 for (AlignmentAnnotation aa : asq.getAnnotation())
111 System.out.println("CalcId: " + aa.getCalcId());
112 if (StructureImportSettings.getDefaultPDBFileParser().equals(
113 StructureParser.JALVIEW_PARSER))
115 assertTrue(MCview.PDBfile.isCalcIdForFile(aa, pdbId));
122 * Check sequence features have been added
124 @Test(groups = { "Functional" })
125 public void checkPDBSequenceFeatures()
130 SequenceFeature[] sf = al.getSequenceAt(0).getSequenceFeatures();
131 assertEquals(296, sf.length);
132 assertEquals("RESNUM", sf[0].getType());
133 assertEquals("GLU: 19 1gaqA", sf[0].getDescription());
134 assertEquals("RESNUM", sf[295].getType());
135 assertEquals("TYR: 314 1gaqA", sf[295].getDescription());
140 sf = al.getSequenceAt(1).getSequenceFeatures();
141 assertEquals(98, sf.length);
142 assertEquals("RESNUM", sf[0].getType());
143 assertEquals("ALA: 1 1gaqB", sf[0].getDescription());
144 assertEquals("RESNUM", sf[97].getType());
145 assertEquals("ALA: 98 1gaqB", sf[97].getDescription());
150 sf = al.getSequenceAt(2).getSequenceFeatures();
151 assertEquals(296, sf.length);
152 assertEquals("RESNUM", sf[0].getType());
153 assertEquals("GLU: 19 1gaqC", sf[0].getDescription());
154 assertEquals("RESNUM", sf[295].getType());
155 assertEquals("TYR: 314 1gaqC", sf[295].getDescription());
158 @Test(groups = { "Functional" })
159 public void checkAnnotationWiring()
161 assertTrue(al.getAlignmentAnnotation() != null);
162 // verify that all sequence annotation is doubly referenced
163 for (AlignmentAnnotation aa : al.getAlignmentAnnotation())
165 if (aa.sequenceRef != null)
167 assertTrue(al.getSequences().contains(aa.sequenceRef));
168 assertNotNull(aa.sequenceRef.getAnnotation());
169 boolean found = false;
170 for (AlignmentAnnotation sqan : aa.sequenceRef.getAnnotation())
179 "Couldn't find sequence associated annotation "
181 + " on the sequence it is associated with.\nSequence associated editing will fail.",
188 * @throws java.lang.Exception
190 @BeforeClass(alwaysRun = true)
191 public static void setUpBeforeClass() throws Exception
193 jalview.bin.Jalview.main(new String[] { "-props",
194 "test/jalview/io/testProps.jvprops" });
198 * @throws java.lang.Exception
200 @AfterClass(alwaysRun = true)
201 public static void tearDownAfterClass() throws Exception
203 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
207 @Test(groups = { "Functional" })
208 public void testJalviewProjectRelocationAnnotation() throws Exception
211 String inFile = "examples/1gaq.txt";
212 String tfile = File.createTempFile("JalviewTest", ".jvp")
214 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
215 inFile, DataSourceType.FILE);
216 assertTrue("Didn't read input file " + inFile, af != null);
217 assertTrue("Failed to store as a project.",
218 af.saveAlignment(tfile, FileFormat.Jalview));
219 af.closeMenuItem_actionPerformed(true);
221 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
222 DataSourceType.FILE);
223 assertTrue("Failed to import new project", af != null);
224 for (SequenceI asq : af.getViewport().getAlignment().getSequences())
227 while (sq.getDatasetSequence() != null)
229 sq = sq.getDatasetSequence();
231 assertNotNull(sq.getAllPDBEntries());
232 assertEquals("Expected only one PDB ID", 1, sq.getAllPDBEntries()
234 for (PDBEntry pdbentry : sq.getAllPDBEntries())
236 System.err.println("PDB Entry " + pdbentry.getId() + " "
237 + pdbentry.getFile());
238 boolean exists = false, found = false;
239 for (AlignmentAnnotation ana : sq.getAnnotation())
241 System.err.println("CalcId " + ana.getCalcId());
242 if (ana.getCalcId() != null
243 && MCview.PDBfile.isCalcIdHandled(ana.getCalcId()))
246 if (MCview.PDBfile.isCalcIdForFile(ana, pdbentry.getId()))
254 assertTrue("Couldn't find any annotation for " + pdbentry.getId()
255 + " (file handle " + pdbentry.getFile() + ")", found);