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.structure.StructureImportSettings;
38 import org.testng.annotations.AfterClass;
39 import org.testng.annotations.BeforeClass;
40 import org.testng.annotations.BeforeMethod;
41 import org.testng.annotations.Test;
43 public class AnnotatedPDBFileInputTest
51 * Ensure 'process secondary structure from PDB and add annotations' are set
52 * in preferences, and load PDB example file 1gaq
56 @BeforeMethod(alwaysRun = true)
57 public void setup() throws Exception
59 Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
60 Boolean.TRUE.toString());
61 Cache.applicationProperties.setProperty("ADD_SS_ANN",
62 Boolean.TRUE.toString());
63 FileLoader loader = new FileLoader(false);
64 AlignFrame af = loader.LoadFileWaitTillLoaded("examples/1gaq.txt",
66 al = af.getViewport().getAlignment();
67 pdbId = al.getSequenceAt(0).getDatasetSequence().getAllPDBEntries()
69 StructureImportSettings.setDefaultStructureFileFormat("PDB");
70 // StructureImportSettings
71 // .setDefaultPDBFileParser(StructureParser.JALVIEW_PARSER);
74 @Test(groups = { "Functional" })
75 public void checkNoDuplicates()
77 // not strictly a requirement, but strange things may happen if multiple
78 // instances of the same annotation are placed in the alignment annotation
80 assertNotNull(al.getAlignmentAnnotation());
81 // verify that all sequence annotation is doubly referenced
82 AlignmentAnnotation[] avec = al.getAlignmentAnnotation();
83 for (int p = 0; p < avec.length; p++)
85 for (int q = p + 1; q < avec.length; q++)
87 assertTrue("Found a duplicate annotation row "
88 + avec[p].label, avec[p] != avec[q]);
93 @Test(groups = { "Functional" })
94 public void checkPDBannotationSource()
97 for (SequenceI asq : al.getSequences())
99 for (AlignmentAnnotation aa : asq.getAnnotation())
102 System.out.println("CalcId: " + aa.getCalcId());
103 // if (StructureImportSettings.getDefaultPDBFileParser().equals(
104 // StructureParser.JALVIEW_PARSER))
106 // assertTrue(MCview.PDBfile.isCalcIdForFile(aa, pdbId));
113 * Check sequence features have been added
115 @Test(groups = { "Functional" })
116 public void checkPDBSequenceFeatures()
121 SequenceFeature[] sf = al.getSequenceAt(0).getSequenceFeatures();
122 assertEquals(296, sf.length);
123 assertEquals("RESNUM", sf[0].getType());
124 assertEquals("GLU:19 1gaqA", sf[0].getDescription());
125 assertEquals("RESNUM", sf[295].getType());
126 assertEquals("TYR:314 1gaqA", sf[295].getDescription());
131 sf = al.getSequenceAt(1).getSequenceFeatures();
132 assertEquals(98, sf.length);
133 assertEquals("RESNUM", sf[0].getType());
134 assertEquals("ALA:1 1gaqB", sf[0].getDescription());
135 assertEquals("RESNUM", sf[97].getType());
136 assertEquals("ALA:98 1gaqB", sf[97].getDescription());
141 sf = al.getSequenceAt(2).getSequenceFeatures();
142 assertEquals(296, sf.length);
143 assertEquals("RESNUM", sf[0].getType());
144 assertEquals("GLU:19 1gaqC", sf[0].getDescription());
145 assertEquals("RESNUM", sf[295].getType());
146 assertEquals("TYR:314 1gaqC", sf[295].getDescription());
149 @Test(groups = { "Functional" })
150 public void checkAnnotationWiring()
152 assertTrue(al.getAlignmentAnnotation() != null);
153 // verify that all sequence annotation is doubly referenced
154 for (AlignmentAnnotation aa : al.getAlignmentAnnotation())
156 if (aa.sequenceRef != null)
158 assertTrue(al.getSequences().contains(aa.sequenceRef));
159 assertNotNull(aa.sequenceRef.getAnnotation());
160 boolean found = false;
161 for (AlignmentAnnotation sqan : aa.sequenceRef.getAnnotation())
170 "Couldn't find sequence associated annotation "
172 + " on the sequence it is associated with.\nSequence associated editing will fail.",
179 * @throws java.lang.Exception
181 @BeforeClass(alwaysRun = true)
182 public static void setUpBeforeClass() throws Exception
184 jalview.bin.Jalview.main(new String[] { "-props",
185 "test/jalview/io/testProps.jvprops" });
189 * @throws java.lang.Exception
191 @AfterClass(alwaysRun = true)
192 public static void tearDownAfterClass() throws Exception
194 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
198 @Test(groups = { "Functional" })
199 public void testJalviewProjectRelocationAnnotation() throws Exception
202 String inFile = "examples/1gaq.txt";
203 String tfile = File.createTempFile("JalviewTest", ".jvp")
205 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
206 inFile, FormatAdapter.FILE);
207 assertTrue("Didn't read input file " + inFile, af != null);
208 assertTrue("Failed to store as a project.",
209 af.saveAlignment(tfile, "Jalview"));
210 af.closeMenuItem_actionPerformed(true);
212 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
214 assertTrue("Failed to import new project", af != null);
215 for (SequenceI asq : af.getViewport().getAlignment().getSequences())
218 while (sq.getDatasetSequence() != null)
220 sq = sq.getDatasetSequence();
222 assertNotNull(sq.getAllPDBEntries());
223 assertEquals("Expected only one PDB ID", 1, sq.getAllPDBEntries()
225 for (PDBEntry pdbentry : sq.getAllPDBEntries())
227 System.err.println("PDB Entry " + pdbentry.getId() + " "
228 + pdbentry.getFile());
229 boolean exists = false, found = false;
230 for (AlignmentAnnotation ana : sq.getAnnotation())
232 System.err.println("CalcId " + ana.getCalcId());
233 if (ana.getCalcId() != null
234 && MCview.PDBfile.isCalcIdHandled(ana.getCalcId()))
237 if (MCview.PDBfile.isCalcIdForFile(ana, pdbentry.getId()))
245 assertTrue("Couldn't find any annotation for " + pdbentry.getId()
246 + " (file handle " + pdbentry.getFile() + ")", found);