X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fproject%2FJalview2xmlTests.java;h=f0fbfc4be423995c23b4f7031af445d35176cc20;hb=f698f77999a9039aa485a6262357432928012479;hp=eb664164e613baf81698847e8ae41fcb0709b096;hpb=65740880573a48adc758bec3939ece9d9ae104dd;p=jalview.git diff --git a/test/jalview/project/Jalview2xmlTests.java b/test/jalview/project/Jalview2xmlTests.java index eb66416..f0fbfc4 100644 --- a/test/jalview/project/Jalview2xmlTests.java +++ b/test/jalview/project/Jalview2xmlTests.java @@ -39,6 +39,7 @@ import javax.swing.JInternalFrame; import org.testng.Assert; import org.testng.AssertJUnit; +import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -51,6 +52,7 @@ import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.DBRefEntry; import jalview.datamodel.GeneLocus; +import jalview.datamodel.HiddenMarkovModel; import jalview.datamodel.HiddenSequences; import jalview.datamodel.Mapping; import jalview.datamodel.PDBEntry; @@ -64,7 +66,6 @@ import jalview.datamodel.features.FeatureMatcher; import jalview.datamodel.features.FeatureMatcherSet; import jalview.datamodel.features.FeatureMatcherSetI; import jalview.gui.AlignFrame; -import jalview.gui.AlignViewport; import jalview.gui.AlignmentPanel; import jalview.gui.Desktop; import jalview.gui.JvOptionPane; @@ -91,9 +92,16 @@ import jalview.util.matcher.Condition; import jalview.viewmodel.AlignmentViewport; import jalview.viewmodel.seqfeatures.FeatureRendererModel; +import junit.extensions.PA; + @Test(singleThreaded = true) public class Jalview2xmlTests extends Jalview2xmlBase { + @AfterMethod(alwaysRun = true) + public void tearDown() + { + Desktop.getInstance().closeAll_actionPerformed(null); + } @Override @BeforeClass(alwaysRun = true) @@ -153,7 +161,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase DataSourceType.FILE); assertNotNull(af, "Didn't read input file " + inFile); af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null); - AlignViewport viewport = af.getViewport(); + AlignViewportI viewport = af.getViewport(); assertSame(viewport.getGlobalColourScheme().getClass(), TCoffeeColourScheme.class, "Didn't set T-coffee colourscheme"); assertNotNull( @@ -276,9 +284,9 @@ public class Jalview2xmlTests extends Jalview2xmlBase AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/exampleFile_2_7.jar", DataSourceType.FILE); assertNotNull(af, "Didn't read in the example file correctly."); - assertTrue(Desktop.getAlignFrames().length == 1 + origCount, + assertEquals(Desktop.getAlignFrames().length, + 1 + origCount, "Didn't gather the views in the example file."); - } /** @@ -410,7 +418,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }, enabled = true) public void testStoreAndRecoverExpandedviews() throws Exception { - Desktop.instance.closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/exampleFile_2_7.jar", DataSourceType.FILE); @@ -438,7 +446,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase { Assert.fail("Didn't save the expanded view state", e); } - Desktop.instance.closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); if (Desktop.getAlignFrames() != null) { Assert.assertEquals(Desktop.getAlignFrames().length, 0); @@ -464,7 +472,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }) public void testStoreAndRecoverReferenceSeqSettings() throws Exception { - Desktop.instance.closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/exampleFile_2_7.jar", DataSourceType.FILE); assertNotNull(af, "Didn't read in the example file correctly."); @@ -503,7 +511,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase { Assert.fail("Didn't save the expanded view state", e); } - Desktop.instance.closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); if (Desktop.getAlignFrames() != null) { Assert.assertEquals(Desktop.getAlignFrames().length, 0); @@ -597,7 +605,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }) public void testStoreAndRecoverGroupRepSeqs() throws Exception { - Desktop.instance.closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/uniref50.fa", DataSourceType.FILE); assertNotNull(af, "Didn't read in the example file correctly."); @@ -672,7 +680,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase { Assert.fail("Didn't save the expanded view state", e); } - Desktop.instance.closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); if (Desktop.getAlignFrames() != null) { Assert.assertEquals(Desktop.getAlignFrames().length, 0); @@ -717,7 +725,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }) public void testStoreAndRecoverPDBEntry() throws Exception { - Desktop.instance.closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); String exampleFile = "examples/3W5V.pdb"; AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile, DataSourceType.FILE); @@ -766,7 +774,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase { Assert.fail("Didn't save the state", e); } - Desktop.instance.closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); if (Desktop.getAlignFrames() != null) { Assert.assertEquals(Desktop.getAlignFrames().length, 0); @@ -817,11 +825,11 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }) public void testStoreAndRecoverColourThresholds() throws IOException { - Desktop.instance.closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/uniref50.fa", DataSourceType.FILE); - AlignViewport av = af.getViewport(); + AlignViewportI av = af.getViewport(); AlignmentI al = av.getAlignment(); /* @@ -880,7 +888,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase ".jvp"); tfile.deleteOnExit(); new Jalview2XML(false).saveState(tfile); - Desktop.instance.closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(), DataSourceType.FILE); Assert.assertNotNull(af, "Failed to reload project"); @@ -1067,6 +1075,59 @@ public class Jalview2xmlTests extends Jalview2xmlBase } /** + * 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 */ @@ -1089,7 +1150,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }) public void testMergeDatasetsforManyViews() throws IOException { - Desktop.instance.closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); // complex project - one dataset, several views on several alignments AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded( @@ -1133,7 +1194,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = "Functional") public void testPcaViewAssociation() throws IOException { - Desktop.instance.closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); final String PCAVIEWNAME = "With PCA"; // create a new tempfile File tempfile = File.createTempFile("jvPCAviewAssoc", "jvp"); @@ -1167,10 +1228,10 @@ public class Jalview2xmlTests extends Jalview2xmlBase } // load again. - Desktop.instance.closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( tempfile.getCanonicalPath(), DataSourceType.FILE); - JInternalFrame[] frames = Desktop.instance.getAllFrames(); + JInternalFrame[] frames = Desktop.getInstance().getAllFrames(); // PCA and the tabbed alignment view should be the only two windows on the // desktop assertEquals(frames.length, 2, @@ -1200,7 +1261,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }) public void testStoreAndRecoverGeneLocus() throws Exception { - Desktop.instance.closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); String seqData = ">P30419\nACDE\n>X1235\nGCCTGTGACGAA"; AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqData, DataSourceType.PASTE); @@ -1236,7 +1297,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase { Assert.fail("Didn't save the state", e); } - Desktop.instance.closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(), DataSourceType.FILE);