3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotEquals;
5 import static org.junit.Assert.assertNotNull;
6 import static org.junit.Assert.assertTrue;
7 import jalview.datamodel.AlignmentAnnotation;
8 import jalview.datamodel.AlignmentI;
9 import jalview.datamodel.PDBEntry;
10 import jalview.datamodel.SequenceFeature;
11 import jalview.datamodel.SequenceI;
12 import jalview.gui.AlignFrame;
13 import jalview.gui.Desktop;
14 import jalview.structure.StructureMapping;
15 import jalview.structure.StructureSelectionManager;
18 import java.util.Vector;
20 import org.junit.AfterClass;
21 import org.junit.Before;
22 import org.junit.BeforeClass;
23 import org.junit.Test;
25 public class AnnotatedPDBFileInputTest
30 String pdbStr = "examples/1gaq.txt";
35 public void setup() throws Exception
37 FileLoader loader = new FileLoader(false);
38 AlignFrame af = loader.LoadFileWaitTillLoaded(pdbStr,
40 al = af.getViewport().getAlignment();
41 pdbId = ((PDBEntry) al.getSequenceAt(0).getDatasetSequence().getPDBId()
46 public void checkNoDuplicates()
48 // not strictly a requirement, but strange things may happen if multiple
49 // instances of the same annotation are placed in the alignment annotation
51 assertNotNull(al.getAlignmentAnnotation());
52 // verify that all sequence annotation is doubly referenced
53 AlignmentAnnotation[] avec = al.getAlignmentAnnotation();
54 for (int p = 0; p < avec.length; p++)
56 for (int q = p + 1; q < avec.length; q++)
59 "Found a duplicate annotation row " + avec[p].label,
66 public void checkPDBannotationSource()
69 for (SequenceI asq : al.getSequences())
71 for (AlignmentAnnotation aa : asq.getAnnotation())
74 System.out.println("CalcId: " + aa.getCalcId());
75 assertTrue(MCview.PDBfile.isCalcIdForFile(aa, pdbId));
81 * Check sequence features have been added
84 public void checkPDBSequenceFeatures()
86 StructureSelectionManager ssm = StructureSelectionManager
87 .getStructureSelectionManager(Desktop.instance);
88 StructureMapping[] mappings = ssm.getMapping("1gaq");
89 // suspect we really want to make assertions on sequence features
90 // in these mappings' sequencess
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());
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
155 public static void setUpBeforeClass() throws Exception
157 jalview.bin.Jalview.main(new String[]
158 { "-props", "test/src/jalview/io/testProps.jvprops" });
162 * @throws java.lang.Exception
165 public static void tearDownAfterClass() throws Exception
167 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
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.getPDBId());
196 assertEquals("Expected only one PDB ID", sq.getPDBId().size(), 1);
197 for (PDBEntry pdbentry : (Vector<PDBEntry>) sq.getPDBId())
199 System.err.println("PDB Entry " + pdbentry.getId() + " "
200 + pdbentry.getFile());
201 boolean exists = false, found = false;
202 for (AlignmentAnnotation ana : sq.getAnnotation())
204 System.err.println("CalcId " + ana.getCalcId());
205 if (ana.getCalcId() != null
206 && MCview.PDBfile.isCalcIdHandled(ana.getCalcId()))
209 if (MCview.PDBfile.isCalcIdForFile(ana,
218 assertTrue("Couldn't find any annotation for " + pdbentry.getId()
219 + " (file handle " + pdbentry.getFile() + ")", found);