3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertNotNull;
5 import static org.testng.AssertJUnit.assertTrue;
7 import jalview.bin.Cache;
8 import jalview.datamodel.AlignmentAnnotation;
9 import jalview.datamodel.AlignmentI;
10 import jalview.datamodel.PDBEntry;
11 import jalview.datamodel.SequenceFeature;
12 import jalview.datamodel.SequenceI;
13 import jalview.gui.AlignFrame;
17 import org.junit.Assert;
18 import org.testng.annotations.AfterClass;
19 import org.testng.annotations.BeforeClass;
20 import org.testng.annotations.BeforeMethod;
21 import org.testng.annotations.Test;
23 public class AnnotatedPDBFileInputTest
31 * Ensure 'process secondary structure from PDB and add annotations' are set
32 * in preferences, and load PDB example file 1gaq
36 @BeforeMethod(alwaysRun = true)
37 public void setup() throws Exception
39 Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
40 Boolean.TRUE.toString());
41 Cache.applicationProperties.setProperty("ADD_SS_ANN",
42 Boolean.TRUE.toString());
43 FileLoader loader = new FileLoader(false);
44 AlignFrame af = loader.LoadFileWaitTillLoaded("examples/1gaq.txt",
46 al = af.getViewport().getAlignment();
47 pdbId = al.getSequenceAt(0).getDatasetSequence().getAllPDBEntries()
51 @Test(groups = { "Functional" })
52 public void checkNoDuplicates()
54 // not strictly a requirement, but strange things may happen if multiple
55 // instances of the same annotation are placed in the alignment annotation
57 assertNotNull(al.getAlignmentAnnotation());
58 // verify that all sequence annotation is doubly referenced
59 AlignmentAnnotation[] avec = al.getAlignmentAnnotation();
60 for (int p = 0; p < avec.length; p++)
62 for (int q = p + 1; q < avec.length; q++)
64 Assert.assertNotEquals("Found a duplicate annotation row "
65 + avec[p].label, avec[p], avec[q]);
70 @Test(groups = { "Functional" })
71 public void checkPDBannotationSource()
74 for (SequenceI asq : al.getSequences())
76 for (AlignmentAnnotation aa : asq.getAnnotation())
79 System.out.println("CalcId: " + aa.getCalcId());
80 assertTrue(MCview.PDBfile.isCalcIdForFile(aa, pdbId));
86 * Check sequence features have been added
88 @Test(groups = { "Functional" })
89 public void checkPDBSequenceFeatures()
94 SequenceFeature[] sf = al.getSequenceAt(0).getSequenceFeatures();
95 assertEquals(296, sf.length);
96 assertEquals("RESNUM", sf[0].getType());
97 assertEquals("GLU: 19 1gaqA", sf[0].getDescription());
98 assertEquals("RESNUM", sf[295].getType());
99 assertEquals("TYR: 314 1gaqA", sf[295].getDescription());
104 sf = al.getSequenceAt(1).getSequenceFeatures();
105 assertEquals(98, sf.length);
106 assertEquals("RESNUM", sf[0].getType());
107 assertEquals("ALA: 1 1gaqB", sf[0].getDescription());
108 assertEquals("RESNUM", sf[97].getType());
109 assertEquals("ALA: 98 1gaqB", sf[97].getDescription());
114 sf = al.getSequenceAt(2).getSequenceFeatures();
115 assertEquals(296, sf.length);
116 assertEquals("RESNUM", sf[0].getType());
117 assertEquals("GLU: 19 1gaqC", sf[0].getDescription());
118 assertEquals("RESNUM", sf[295].getType());
119 assertEquals("TYR: 314 1gaqC", sf[295].getDescription());
122 @Test(groups = { "Functional" })
123 public void checkAnnotationWiring()
125 assertTrue(al.getAlignmentAnnotation() != null);
126 // verify that all sequence annotation is doubly referenced
127 for (AlignmentAnnotation aa : al.getAlignmentAnnotation())
129 if (aa.sequenceRef != null)
131 assertTrue(al.getSequences().contains(aa.sequenceRef));
132 assertNotNull(aa.sequenceRef.getAnnotation());
133 boolean found = false;
134 for (AlignmentAnnotation sqan : aa.sequenceRef.getAnnotation())
143 "Couldn't find sequence associated annotation "
145 + " on the sequence it is associated with.\nSequence associated editing will fail.",
152 * @throws java.lang.Exception
154 @BeforeClass(alwaysRun = true)
155 public static void setUpBeforeClass() throws Exception
157 jalview.bin.Jalview.main(new String[] { "-props",
158 "test/jalview/io/testProps.jvprops" });
162 * @throws java.lang.Exception
165 public static void tearDownAfterClass() throws Exception
167 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
171 @Test(groups = { "Functional" })
172 public void testJalviewProjectRelocationAnnotation() throws Exception
175 String inFile = "examples/1gaq.txt";
176 String tfile = File.createTempFile("JalviewTest", ".jvp")
178 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
179 inFile, FormatAdapter.FILE);
180 assertTrue("Didn't read input file " + inFile, af != null);
181 assertTrue("Failed to store as a project.",
182 af.saveAlignment(tfile, "Jalview"));
183 af.closeMenuItem_actionPerformed(true);
185 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
187 assertTrue("Failed to import new project", af != null);
188 for (SequenceI asq : af.getViewport().getAlignment().getSequences())
191 while (sq.getDatasetSequence() != null)
193 sq = sq.getDatasetSequence();
195 assertNotNull(sq.getAllPDBEntries());
196 assertEquals("Expected only one PDB ID",
197 sq.getAllPDBEntries().size(), 1);
198 for (PDBEntry pdbentry : sq.getAllPDBEntries())
200 System.err.println("PDB Entry " + pdbentry.getId() + " "
201 + pdbentry.getFile());
202 boolean exists = false, found = false;
203 for (AlignmentAnnotation ana : sq.getAnnotation())
205 System.err.println("CalcId " + ana.getCalcId());
206 if (ana.getCalcId() != null
207 && MCview.PDBfile.isCalcIdHandled(ana.getCalcId()))
210 if (MCview.PDBfile.isCalcIdForFile(ana, pdbentry.getId()))
218 assertTrue("Couldn't find any annotation for " + pdbentry.getId()
219 + " (file handle " + pdbentry.getFile() + ")", found);