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.SequenceI;
11 import jalview.gui.AlignFrame;
14 import java.util.Vector;
16 import org.junit.AfterClass;
17 import org.junit.Before;
18 import org.junit.BeforeClass;
19 import org.junit.Test;
21 public class AnnotatedPDBFileInputTest
26 String pdbStr = "examples/1gaq.txt";
31 public void setup() throws Exception
33 FileLoader loader = new FileLoader(false);
34 AlignFrame af = loader.LoadFileWaitTillLoaded(pdbStr,
36 al = af.getViewport().getAlignment();
37 pdbId = ((PDBEntry) al.getSequenceAt(0).getDatasetSequence().getPDBId()
42 public void checkNoDuplicates()
44 // not strictly a requirement, but strange things may happen if multiple
45 // instances of the same annotation are placed in the alignment annotation
47 assertNotNull(al.getAlignmentAnnotation());
48 // verify that all sequence annotation is doubly referenced
49 AlignmentAnnotation[] avec = al.getAlignmentAnnotation();
50 for (int p = 0; p < avec.length; p++)
52 for (int q = p + 1; q < avec.length; q++)
55 "Found a duplicate annotation row " + avec[p].label,
62 public void checkPDBannotationSource()
65 for (SequenceI asq : al.getSequences())
67 for (AlignmentAnnotation aa : asq.getAnnotation())
70 System.out.println("CalcId: " + aa.getCalcId());
71 assertTrue(MCview.PDBfile.isCalcIdForFile(aa, pdbId));
77 public void checkAnnotationWiring()
79 assertTrue(al.getAlignmentAnnotation() != null);
80 // verify that all sequence annotation is doubly referenced
81 for (AlignmentAnnotation aa : al.getAlignmentAnnotation())
83 if (aa.sequenceRef != null)
85 assertTrue(al.getSequences().contains(aa.sequenceRef));
86 assertNotNull(aa.sequenceRef.getAnnotation());
87 boolean found = false;
88 for (AlignmentAnnotation sqan : aa.sequenceRef.getAnnotation())
97 "Couldn't find sequence associated annotation "
99 + " on the sequence it is associated with.\nSequence associated editing will fail.",
106 * @throws java.lang.Exception
109 public static void setUpBeforeClass() throws Exception
111 jalview.bin.Jalview.main(new String[]
112 { "-props", "test/src/jalview/io/testProps.jvprops" });
116 * @throws java.lang.Exception
119 public static void tearDownAfterClass() throws Exception
121 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
126 public void testJalviewProjectRelocationAnnotation() throws Exception
129 String inFile = "examples/1gaq.txt";
130 String tfile = File.createTempFile("JalviewTest", ".jvp")
132 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
133 inFile, FormatAdapter.FILE);
134 assertTrue("Didn't read input file " + inFile, af != null);
135 assertTrue("Failed to store as a project.",
136 af.saveAlignment(tfile, "Jalview"));
137 af.closeMenuItem_actionPerformed(true);
139 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile,
141 assertTrue("Failed to import new project", af != null);
142 for (SequenceI asq : af.getViewport().getAlignment().getSequences())
145 while (sq.getDatasetSequence() != null)
147 sq = sq.getDatasetSequence();
149 assertNotNull(sq.getPDBId());
150 assertEquals("Expected only one PDB ID", sq.getPDBId().size(), 1);
151 for (PDBEntry pdbentry : (Vector<PDBEntry>) sq.getPDBId())
153 System.err.println("PDB Entry " + pdbentry.getId() + " "
154 + pdbentry.getFile());
155 boolean exists = false, found = false;
156 for (AlignmentAnnotation ana : sq.getAnnotation())
158 System.err.println("CalcId " + ana.getCalcId());
159 if (ana.getCalcId() != null
160 && MCview.PDBfile.isCalcIdHandled(ana.getCalcId()))
163 if (MCview.PDBfile.isCalcIdForFile(ana,
172 assertTrue("Couldn't find any annotation for " + pdbentry.getId()
173 + " (file handle " + pdbentry.getFile() + ")", found);