+
+ /**
+ * Load an HMM profile to an alignment, and confirm it is correctly restored
+ * when reloaded from project
+ *
+ * @throws IOException
+ */
+ @Test(groups = { "Functional" })
+ public void testStoreAndRecoverHmmProfile() throws IOException
+ {
+ Desktop.getInstance().closeAll_actionPerformed(null);
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
+ "examples/uniref50.fa", DataSourceType.FILE);
+
+ AlignViewportI av = af.getViewport();
+ AlignmentI al = av.getAlignment();
+
+ /*
+ * mimic drag and drop of hmm file on to alignment
+ */
+ AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
+ "examples/uniref50.hmm", DataSourceType.FILE);
+ al.insertSequenceAt(0,
+ af2.getViewport().getAlignment().getSequenceAt(0));
+
+ /*
+ * check it loaded in
+ */
+ SequenceI hmmSeq = al.getSequenceAt(0);
+ assertTrue(hmmSeq.hasHMMProfile());
+ HiddenMarkovModel hmm = hmmSeq.getHMM();
+ assertSame(hmm.getConsensusSequence(), hmmSeq);
+
+ /*
+ * save project, close windows, reload project, verify
+ */
+ File tfile = File.createTempFile("testStoreAndRecoverHmmProfile",
+ ".jvp");
+ tfile.deleteOnExit();
+ new Jalview2XML(false).saveState(tfile);
+ Desktop.getInstance().closeAll_actionPerformed(null);
+ af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
+ DataSourceType.FILE);
+ Assert.assertNotNull(af, "Failed to reload project");
+
+ hmmSeq = al.getSequenceAt(0);
+ assertTrue(hmmSeq.hasHMMProfile());
+ assertSame(hmm.getConsensusSequence(), hmmSeq);
+ Mapping mapToHmmConsensus = (Mapping) PA.getValue(hmm,
+ "mapToHmmConsensus");
+ assertNotNull(mapToHmmConsensus);
+ assertSame(mapToHmmConsensus.getTo(), hmmSeq.getDatasetSequence());
+ }
+
+ /**
+ * pre 2.11 - jalview 2.10 erroneously created new dataset entries for each
+ * view (JAL-3171) this test ensures we can import and merge those views
+ */
+ @Test(groups = { "Functional" })
+ public void testMergeDatasetsforViews() throws IOException
+ {
+ // simple project - two views on one alignment
+ AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
+ "examples/testdata/projects/twoViews.jvp", DataSourceType.FILE);
+ assertNotNull(af);
+ assertTrue(af.getAlignPanels().size() > 1);
+ verifyDs(af);
+ }
+
+ /**
+ * pre 2.11 - jalview 2.10 erroneously created new dataset entries for each
+ * view (JAL-3171) this test ensures we can import and merge those views This
+ * is a more complex project
+ */
+ @Test(groups = { "Functional" })
+ public void testMergeDatasetsforManyViews() throws IOException
+ {
+ Desktop.getInstance().closeAll_actionPerformed(null);
+
+ // complex project - one dataset, several views on several alignments
+ AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
+ "examples/testdata/projects/manyViews.jvp",
+ DataSourceType.FILE);
+ assertNotNull(af);
+
+ AlignmentI ds = null;
+ for (AlignFrame alignFrame : Desktop.getAlignFrames())
+ {
+ if (ds == null)
+ {
+ ds = verifyDs(alignFrame);
+ }
+ else
+ {
+ // check that this frame's dataset matches the last
+ assertTrue(ds == verifyDs(alignFrame));
+ }
+ }
+ }
+
+ private AlignmentI verifyDs(AlignFrame af)
+ {
+ AlignmentI ds = null;
+ for (AlignmentViewPanel ap : af.getAlignPanels())
+ {
+ if (ds == null)
+ {
+ ds = ap.getAlignment().getDataset();
+ }
+ else
+ {
+ assertTrue(ap.getAlignment().getDataset() == ds,
+ "Dataset was not the same for imported 2.10.5 project with several alignment views");
+ }
+ }
+ return ds;
+ }
+
+ @Test(groups = "Functional")
+ public void testPcaViewAssociation() throws IOException
+ {
+ Desktop.getInstance().closeAll_actionPerformed(null);
+ final String PCAVIEWNAME = "With PCA";
+ // create a new tempfile
+ File tempfile = File.createTempFile("jvPCAviewAssoc", "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.getInstance().closeAll_actionPerformed(null);
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
+ tempfile.getCanonicalPath(), DataSourceType.FILE);
+ JInternalFrame[] frames = Desktop.getInstance().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 save and reload of DBRefEntry including GeneLocus in project
+ *
+ * @throws Exception
+ */
+ @Test(groups = { "Functional" })
+ public void testStoreAndRecoverGeneLocus() throws Exception
+ {
+ Desktop.getInstance().closeAll_actionPerformed(null);
+ String seqData = ">P30419\nACDE\n>X1235\nGCCTGTGACGAA";
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqData,
+ DataSourceType.PASTE);
+ assertNotNull(af, "Didn't read in the example file correctly.");
+
+ AlignmentViewPanel ap = Desktop.getAlignmentPanels(null)[0];
+ SequenceI pep = ap.getAlignment().getSequenceAt(0);
+ SequenceI cds = ap.getAlignment().getSequenceAt(1);
+
+ /*
+ * give 'protein' a dbref to self, a dbref with map to CDS,
+ * and a dbref with map to gene 'locus'
+ */
+ DBRefEntry dbref1 = new DBRefEntry("Uniprot", "1", "P30419", null);
+ pep.addDBRef(dbref1);
+ Mapping cdsmap = new Mapping(cds,
+ new MapList(new int[]
+ { 1, 4 }, new int[] { 1, 12 }, 1, 3));
+ DBRefEntry dbref2 = new DBRefEntry("EMBLCDS", "2", "X1235", cdsmap);
+ pep.addDBRef(dbref2);
+ Mapping locusmap = new Mapping(null,
+ new MapList(new int[]
+ { 1, 4 }, new int[] { 2674123, 2674135 }, 1, 3));
+ DBRefEntry dbref3 = new GeneLocus("human", "GRCh38", "5", locusmap);
+ pep.addDBRef(dbref3);
+
+ File tfile = File.createTempFile("testStoreAndRecoverGeneLocus",
+ ".jvp");
+ try
+ {
+ new Jalview2XML(false).saveState(tfile);
+ } catch (Throwable e)
+ {
+ Assert.fail("Didn't save the state", e);
+ }
+ Desktop.getInstance().closeAll_actionPerformed(null);
+
+ new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
+ DataSourceType.FILE);
+ AlignmentViewPanel rap = Desktop.getAlignmentPanels(null)[0];
+ SequenceI rpep = rap.getAlignment().getSequenceAt(0);
+ DBModList<DBRefEntry> dbrefs = rpep.getDBRefs();
+ assertEquals(rpep.getName(), "P30419");
+ assertEquals(dbrefs.size(), 3);
+ DBRefEntry dbRef = dbrefs.get(0);
+ assertFalse(dbRef instanceof GeneLocus);
+ assertNull(dbRef.getMap());
+ assertEquals(dbRef, dbref1);
+
+ /*
+ * restored dbrefs with mapping have a different 'map to'
+ * sequence but otherwise match the original dbrefs
+ */
+ dbRef = dbrefs.get(1);
+ assertFalse(dbRef instanceof GeneLocus);
+ assertTrue(dbRef.equalRef(dbref2));
+ assertNotNull(dbRef.getMap());
+ SequenceI rcds = rap.getAlignment().getSequenceAt(1);
+ assertSame(dbRef.getMap().getTo(), rcds);
+ // compare MapList but not map.to
+ assertEquals(dbRef.getMap().getMap(), dbref2.getMap().getMap());
+
+ /*
+ * GeneLocus map.to is null so can compare Mapping objects
+ */
+ dbRef = dbrefs.get(2);
+ assertTrue(dbRef instanceof GeneLocus);
+ assertEquals(dbRef, dbref3);
+ }