+
+ @Test(groups = "Functional")
+ public void testRestorePCAViewAssociation() throws IOException
+ {
+ Desktop.instance.closeAll_actionPerformed(null);
+ final String PCAVIEWNAME = "With PCA";
+ // create a new tempfile
+ File tempfile = File.createTempFile("testRestorePCAViewAssociation",
+ "jvp");
+
+ {
+ String exampleFile = "examples/uniref50.fa";
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
+ DataSourceType.FILE);
+ assertNotNull(af, "Didn't read in the example file correctly.");
+ AlignmentPanel origView = (AlignmentPanel) af.getAlignPanels().get(0);
+ AlignmentPanel newview = af.newView(PCAVIEWNAME, true);
+ // create another for good measure
+ af.newView("Not the PCA View", true);
+ PCAPanel pcaPanel = new PCAPanel(origView, "BLOSUM62",
+ new SimilarityParams(true, true, true, false));
+ // we're in the test exec thread, so we can just run synchronously here
+ pcaPanel.run();
+
+ // now switch the linked view
+ pcaPanel.selectAssociatedView(newview);
+
+ assertTrue(pcaPanel.getAlignViewport() == newview.getAlignViewport(),
+ "PCA should be associated with 'With PCA' view: test is broken");
+
+ // now save and reload project
+ Jalview2XML jv2xml = new jalview.project.Jalview2XML(false);
+ tempfile.delete();
+ jv2xml.saveState(tempfile);
+ assertTrue(jv2xml.errorMessage == null,
+ "Failed to save dummy project with PCA: test broken");
+ }
+
+ // load again.
+ Desktop.instance.closeAll_actionPerformed(null);
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
+ tempfile.getCanonicalPath(), DataSourceType.FILE);
+ JInternalFrame[] frames = Desktop.instance.getAllFrames();
+ // PCA and the tabbed alignment view should be the only two windows on the
+ // desktop
+ assertEquals(frames.length, 2,
+ "PCA and the tabbed alignment view should be the only two windows on the desktop");
+ PCAPanel pcaPanel = (PCAPanel) frames[frames[0] == af ? 1 : 0];
+
+ AlignmentViewPanel restoredNewView = null;
+ for (AlignmentViewPanel alignpanel : Desktop.getAlignmentPanels(null))
+ {
+ if (alignpanel.getAlignViewport() == pcaPanel.getAlignViewport())
+ {
+ restoredNewView = alignpanel;
+ }
+ }
+ assertEquals(restoredNewView.getViewName(), PCAVIEWNAME);
+ assertTrue(
+ restoredNewView.getAlignViewport() == pcaPanel
+ .getAlignViewport(),
+ "Didn't restore correct view association for the PCA view");
+ }
+
+ /**
+ * Test that annotation ordering is faithfully restored
+ *
+ * @throws Exception
+ */
+ @Test(groups = { "Functional" })
+ public void testRestoreAnnotationOrdering() throws Exception
+ {
+ Desktop.instance.closeAll_actionPerformed(null);
+ Cache.setProperty("SHOW_ANNOTATION", "true");
+ Cache.setProperty("SHOW_CONSERVATION", "true");
+ Cache.setProperty("SHOW_QUALITY", "false");
+ Cache.setProperty("SHOW_IDENTITY", "false");
+ Cache.setProperty("SHOW_OCCUPANCY", "true");
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
+ "examples/uniref50.fa", DataSourceType.FILE);
+ assertNotNull(af, "Didn't read in the example file correctly.");
+
+ AlignFrame[] afs = Desktop.getAlignFrames();
+ assertEquals(afs.length, 1);
+ AlignmentI alignment = afs[0].getViewport().getAlignment();
+ AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
+ assertEquals(anns.length, 2);
+
+ /*
+ * this order is hard wired in AlignmentViewport.initAutoAnnotation()
+ */
+ assertEquals(anns[0].label, "Conservation");
+ assertEquals(anns[1].label, "Occupancy");
+
+ /*
+ * add two user annotations, adjust order, height and visibility
+ */
+ AlignmentAnnotation tmp = anns[0];
+ anns[0] = anns[1];
+ anns[1] = tmp;
+ Annotation[] an1 = new Annotation[] { new Annotation(2f) };
+ Annotation[] an2 = new Annotation[] { new Annotation(3f) };
+ alignment.addAnnotation(new AlignmentAnnotation("hello", "desc1", an1),
+ 1);
+ alignment.addAnnotation(new AlignmentAnnotation("world", "desc2", an2),
+ 3);
+ anns = alignment.getAlignmentAnnotation();
+ assertEquals(anns[0].label, "Occupancy");
+ assertEquals(anns[1].label, "hello");
+ assertEquals(anns[2].label, "Conservation");
+ assertEquals(anns[3].label, "world");
+ anns[0].graphHeight = 60;
+ anns[0].visible = false;
+ anns[1].graphHeight = 70;
+ anns[2].graphHeight = 80;
+ anns[3].graphHeight = 90;
+ anns[3].visible = false;
+
+ /*
+ * save project to temporary file and reload on to an empty desktop,
+ * verify annotation order, height and visibility is restored
+ */
+ File projectFile = File.createTempFile("jvTest", ".jvp");
+ new Jalview2XML(false).saveState(projectFile);
+ Desktop.instance.closeAll_actionPerformed(null);
+ if (Desktop.getAlignFrames() != null)
+ {
+ Assert.assertEquals(Desktop.getAlignFrames().length, 0);
+ }
+
+ af = new FileLoader().LoadFileWaitTillLoaded(
+ projectFile.getAbsolutePath(),
+ DataSourceType.FILE);
+ anns = af.getViewport().getAlignment().getAlignmentAnnotation();
+ assertEquals(anns.length, 4);
+ assertEquals(anns[0].label, "Occupancy");
+ assertEquals(anns[1].label, "hello");
+ assertEquals(anns[2].label, "Conservation");
+ assertEquals(anns[3].label, "world");
+ assertEquals(anns[0].graphHeight, 60);
+ assertEquals(anns[1].graphHeight, 70);
+ assertEquals(anns[2].graphHeight, 80);
+ assertEquals(anns[3].graphHeight, 90);
+ assertFalse(anns[0].visible);
+ assertTrue(anns[1].visible);
+ assertTrue(anns[2].visible);
+ assertFalse(anns[3].visible);
+
+ /*
+ * make a new view of the alignment (uses project save/load code)
+ * and verify annotations are ordered the same
+ */
+ AlignmentPanel newPanel = af.newView("new", true);
+ AlignmentAnnotation[] newAnns = newPanel.getAlignment()
+ .getAlignmentAnnotation();
+ assertEquals(newAnns.length, 4);
+ assertEquals(newAnns[0].label, "Occupancy");
+ assertEquals(newAnns[1].label, "hello");
+ assertEquals(newAnns[2].label, "Conservation");
+ assertEquals(newAnns[3].label, "world");
+ assertEquals(newAnns[0].graphHeight, 60);
+ assertEquals(newAnns[1].graphHeight, 70);
+ assertEquals(newAnns[2].graphHeight, 80);
+ assertEquals(newAnns[3].graphHeight, 90);
+ assertFalse(newAnns[0].visible);
+ assertTrue(newAnns[1].visible);
+ assertTrue(newAnns[2].visible);
+ assertFalse(newAnns[3].visible);
+ newPanel.closePanel();
+
+ /*
+ * reload the project with Preferences set to not create Occupancy;
+ * this should still appear, as it is in the saved project
+ */
+ Desktop.instance.closeAll_actionPerformed(null);
+ Cache.setProperty("SHOW_OCCUPANCY", "false");
+ af = new FileLoader().LoadFileWaitTillLoaded(
+ projectFile.getAbsolutePath(), DataSourceType.FILE);
+ anns = af.getViewport().getAlignment().getAlignmentAnnotation();
+ assertEquals(anns.length, 4);
+ assertEquals(anns[0].label, "Occupancy");
+ assertEquals(anns[1].label, "hello");
+ assertEquals(anns[2].label, "Conservation");
+ assertEquals(anns[3].label, "world");
+
+ /*
+ * reload the project with Preferences set to create Quality annotation;
+ * this should not appear, as it is not in the saved project
+ */
+ Desktop.instance.closeAll_actionPerformed(null);
+ Cache.setProperty("SHOW_OCCUPANCY", "false");
+ Cache.setProperty("SHOW_QUALITY", "true");
+ af = new FileLoader().LoadFileWaitTillLoaded(
+ projectFile.getAbsolutePath(), DataSourceType.FILE);
+ anns = af.getViewport().getAlignment().getAlignmentAnnotation();
+ assertEquals(anns.length, 4);
+ assertEquals(anns[0].label, "Occupancy");
+ assertEquals(anns[1].label, "hello");
+ assertEquals(anns[2].label, "Conservation");
+ assertEquals(anns[3].label, "world");
+ }