From 34a74c039cd9126c5ad7b2b0675481d0f9cb9420 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 24 Apr 2018 08:06:03 +0100 Subject: [PATCH] JAL-2956 unit test --- test/jalview/io/Jalview2xmlTests.java | 60 ++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/test/jalview/io/Jalview2xmlTests.java b/test/jalview/io/Jalview2xmlTests.java index 41a6b89..9c5ab00 100644 --- a/test/jalview/io/Jalview2xmlTests.java +++ b/test/jalview/io/Jalview2xmlTests.java @@ -33,7 +33,9 @@ import jalview.api.FeatureColourI; import jalview.api.ViewStyleI; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; +import jalview.datamodel.HiddenMarkovModel; import jalview.datamodel.HiddenSequences; +import jalview.datamodel.Mapping; import jalview.datamodel.PDBEntry; import jalview.datamodel.PDBEntry.Type; import jalview.datamodel.SequenceCollectionI; @@ -78,6 +80,8 @@ import org.testng.AssertJUnit; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import junit.extensions.PA; + @Test(singleThreaded = true) public class Jalview2xmlTests extends Jalview2xmlBase { @@ -857,7 +861,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase * @throws IOException */ @Test(groups = { "Functional" }) - public void testSaveLoadFeatureColoursAndFilters() throws IOException + public void testStoreAndRecoverFeatureColoursAndFilters() + throws IOException { AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE); @@ -1009,4 +1014,57 @@ public class Jalview2xmlTests extends Jalview2xmlBase addFeature(seq, featureType, score++); addFeature(seq, featureType, score); } + + /** + * 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.instance.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.instance.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()); + } } -- 1.7.10.2