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;
14 import jalview.gui.Desktop;
15 import jalview.structure.StructureMapping;
16 import jalview.structure.StructureSelectionManager;
20 import org.junit.Assert;
21 import org.testng.annotations.AfterClass;
22 import org.testng.annotations.BeforeClass;
23 import org.testng.annotations.BeforeMethod;
24 import org.testng.annotations.Test;
26 public class AnnotatedPDBFileInputTest
31 String pdbStr = "examples/1gaq.txt";
36 public void setup() throws Exception
38 Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
39 Boolean.TRUE.toString());
40 Cache.applicationProperties.setProperty("ADD_SS_ANN",
41 Boolean.TRUE.toString());
42 FileLoader loader = new FileLoader(false);
43 AlignFrame af = loader.LoadFileWaitTillLoaded(pdbStr,
45 al = af.getViewport().getAlignment();
46 pdbId = al.getSequenceAt(0).getDatasetSequence().getPDBId()
51 public void checkNoDuplicates()
53 // not strictly a requirement, but strange things may happen if multiple
54 // instances of the same annotation are placed in the alignment annotation
56 assertNotNull(al.getAlignmentAnnotation());
57 // verify that all sequence annotation is doubly referenced
58 AlignmentAnnotation[] avec = al.getAlignmentAnnotation();
59 for (int p = 0; p < avec.length; p++)
61 for (int q = p + 1; q < avec.length; q++)
63 Assert.assertNotEquals(
64 "Found a duplicate annotation row " + avec[p].label,
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
89 public void checkPDBSequenceFeatures()
91 StructureSelectionManager ssm = StructureSelectionManager
92 .getStructureSelectionManager(Desktop.instance);
93 StructureMapping[] mappings = ssm.getMapping("1gaq");
94 // suspect we really want to make assertions on sequence features
95 // in these mappings' sequencess
99 SequenceFeature[] sf = al.getSequenceAt(0).getSequenceFeatures();
100 assertEquals(296, sf.length);
101 assertEquals("RESNUM", sf[0].getType());
102 assertEquals("GLU:19 1gaqA", sf[0].getDescription());
103 assertEquals("RESNUM", sf[295].getType());
104 assertEquals("TYR:314 1gaqA", sf[295].getDescription());
109 sf = al.getSequenceAt(1).getSequenceFeatures();
110 assertEquals(98, sf.length);
111 assertEquals("RESNUM", sf[0].getType());
112 assertEquals("ALA:1 1gaqB", sf[0].getDescription());
113 assertEquals("RESNUM", sf[97].getType());
114 assertEquals("ALA:98 1gaqB", sf[97].getDescription());
119 sf = al.getSequenceAt(2).getSequenceFeatures();
120 assertEquals(296, sf.length);
121 assertEquals("RESNUM", sf[0].getType());
122 assertEquals("GLU:19 1gaqC", sf[0].getDescription());
123 assertEquals("RESNUM", sf[295].getType());
124 assertEquals("TYR:314 1gaqC", sf[295].getDescription());
128 public void checkAnnotationWiring()
130 assertTrue(al.getAlignmentAnnotation() != null);
131 // verify that all sequence annotation is doubly referenced
132 for (AlignmentAnnotation aa : al.getAlignmentAnnotation())
134 if (aa.sequenceRef != null)
136 assertTrue(al.getSequences().contains(aa.sequenceRef));
137 assertNotNull(aa.sequenceRef.getAnnotation());
138 boolean found = false;
139 for (AlignmentAnnotation sqan : aa.sequenceRef.getAnnotation())
148 "Couldn't find sequence associated annotation "
150 + " on the sequence it is associated with.\nSequence associated editing will fail.",
157 * @throws java.lang.Exception
160 public static void setUpBeforeClass() throws Exception
162 jalview.bin.Jalview.main(new String[]
163 { "-props", "test/src/jalview/io/testProps.jvprops" });
167 * @throws java.lang.Exception
170 public static void tearDownAfterClass() throws Exception
172 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
177 public void testJalviewProjectRelocationAnnotation() throws Exception
180 String inFile = "examples/1gaq.txt";
181 String tfile = File.createTempFile("JalviewTest", ".jvp")
183 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
184 inFile, FormatAdapter.FILE);
185 assertTrue("Didn't read input file " + inFile, af != null);
186 assertTrue("Failed to store as a project.",
187 af.saveAlignment(tfile, "Jalview"));
188 af.closeMenuItem_actionPerformed(true);
190 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
192 assertTrue("Failed to import new project", af != null);
193 for (SequenceI asq : af.getViewport().getAlignment().getSequences())
196 while (sq.getDatasetSequence() != null)
198 sq = sq.getDatasetSequence();
200 assertNotNull(sq.getPDBId());
201 assertEquals("Expected only one PDB ID", sq.getPDBId().size(), 1);
202 for (PDBEntry pdbentry : sq.getPDBId())
204 System.err.println("PDB Entry " + pdbentry.getId() + " "
205 + pdbentry.getFile());
206 boolean exists = false, found = false;
207 for (AlignmentAnnotation ana : sq.getAnnotation())
209 System.err.println("CalcId " + ana.getCalcId());
210 if (ana.getCalcId() != null
211 && MCview.PDBfile.isCalcIdHandled(ana.getCalcId()))
214 if (MCview.PDBfile.isCalcIdForFile(ana,
223 assertTrue("Couldn't find any annotation for " + pdbentry.getId()
224 + " (file handle " + pdbentry.getFile() + ")", found);