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(
65 "Found a duplicate annotation row " + avec[p].label,
71 @Test(groups ={ "Functional" })
72 public void checkPDBannotationSource()
75 for (SequenceI asq : al.getSequences())
77 for (AlignmentAnnotation aa : asq.getAnnotation())
80 System.out.println("CalcId: " + aa.getCalcId());
81 assertTrue(MCview.PDBfile.isCalcIdForFile(aa, pdbId));
87 * Check sequence features have been added
89 @Test(groups ={ "Functional" })
90 public void checkPDBSequenceFeatures()
95 SequenceFeature[] sf = al.getSequenceAt(0).getSequenceFeatures();
96 assertEquals(296, sf.length);
97 assertEquals("RESNUM", sf[0].getType());
98 assertEquals("GLU: 19 1gaqA", sf[0].getDescription());
99 assertEquals("RESNUM", sf[295].getType());
100 assertEquals("TYR: 314 1gaqA", sf[295].getDescription());
105 sf = al.getSequenceAt(1).getSequenceFeatures();
106 assertEquals(98, sf.length);
107 assertEquals("RESNUM", sf[0].getType());
108 assertEquals("ALA: 1 1gaqB", sf[0].getDescription());
109 assertEquals("RESNUM", sf[97].getType());
110 assertEquals("ALA: 98 1gaqB", sf[97].getDescription());
115 sf = al.getSequenceAt(2).getSequenceFeatures();
116 assertEquals(296, sf.length);
117 assertEquals("RESNUM", sf[0].getType());
118 assertEquals("GLU: 19 1gaqC", sf[0].getDescription());
119 assertEquals("RESNUM", sf[295].getType());
120 assertEquals("TYR: 314 1gaqC", sf[295].getDescription());
123 @Test(groups ={ "Functional" })
124 public void checkAnnotationWiring()
126 assertTrue(al.getAlignmentAnnotation() != null);
127 // verify that all sequence annotation is doubly referenced
128 for (AlignmentAnnotation aa : al.getAlignmentAnnotation())
130 if (aa.sequenceRef != null)
132 assertTrue(al.getSequences().contains(aa.sequenceRef));
133 assertNotNull(aa.sequenceRef.getAnnotation());
134 boolean found = false;
135 for (AlignmentAnnotation sqan : aa.sequenceRef.getAnnotation())
144 "Couldn't find sequence associated annotation "
146 + " on the sequence it is associated with.\nSequence associated editing will fail.",
153 * @throws java.lang.Exception
155 @BeforeClass(alwaysRun = true)
156 public static void setUpBeforeClass() throws Exception
158 jalview.bin.Jalview.main(new String[] { "-props",
159 "test/jalview/io/testProps.jvprops" });
163 * @throws java.lang.Exception
166 public static void tearDownAfterClass() throws Exception
168 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
172 @Test(groups ={ "Functional" })
173 public void testJalviewProjectRelocationAnnotation() throws Exception
176 String inFile = "examples/1gaq.txt";
177 String tfile = File.createTempFile("JalviewTest", ".jvp")
179 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
180 inFile, FormatAdapter.FILE);
181 assertTrue("Didn't read input file " + inFile, af != null);
182 assertTrue("Failed to store as a project.",
183 af.saveAlignment(tfile, "Jalview"));
184 af.closeMenuItem_actionPerformed(true);
186 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
188 assertTrue("Failed to import new project", af != null);
189 for (SequenceI asq : af.getViewport().getAlignment().getSequences())
192 while (sq.getDatasetSequence() != null)
194 sq = sq.getDatasetSequence();
196 assertNotNull(sq.getAllPDBEntries());
197 assertEquals("Expected only one PDB ID", 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,
219 assertTrue("Couldn't find any annotation for " + pdbentry.getId()
220 + " (file handle " + pdbentry.getFile() + ")", found);