From: James Procter Date: Wed, 22 Feb 2023 14:23:56 +0000 (+0000) Subject: JAL-3858 simple test for PAE matrix recovery X-Git-Tag: Release_2_11_3_0~18^2~6 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=97725e865411eec548a4b400ed9277b591f3fb6e;p=jalview.git JAL-3858 simple test for PAE matrix recovery --- diff --git a/test/jalview/project/Jalview2xmlTests.java b/test/jalview/project/Jalview2xmlTests.java index c070edb..84af3e4 100644 --- a/test/jalview/project/Jalview2xmlTests.java +++ b/test/jalview/project/Jalview2xmlTests.java @@ -54,6 +54,8 @@ import jalview.bin.Cache; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; +import jalview.datamodel.ContactListI; +import jalview.datamodel.ContactMatrixI; import jalview.datamodel.DBRefEntry; import jalview.datamodel.GeneLocus; import jalview.datamodel.HiddenSequences; @@ -97,6 +99,7 @@ import jalview.util.MapList; import jalview.util.matcher.Condition; import jalview.viewmodel.AlignmentViewport; import jalview.viewmodel.seqfeatures.FeatureRendererModel; +import jalview.ws.datamodel.alphafold.PAEContactMatrix; @Test(singleThreaded = true) public class Jalview2xmlTests extends Jalview2xmlBase @@ -1526,4 +1529,57 @@ public class Jalview2xmlTests extends Jalview2xmlBase // af exists still but isn't shown assertTrue(af.isClosed()); } + + @Test(groups = { "Functional" }) + public void testPAEsaveRestore() throws Exception + { + Desktop.instance.closeAll_actionPerformed(null); + AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( + ">seq1\nMATRSQFLVNF\n", DataSourceType.PASTE); + AlignmentI al = af.getViewport().getAlignment(); + SequenceI sq = al.getSequenceAt(0); + int i = sq.getLength(); + float[][] paevals = new float[i][i]; + for (i = i - 1; i >= 0; i--) + { + for (int j = 0; j <= i; j++) + { + paevals[i][j] = ((i - j < 2) + || ((i > 1 && i < 5) && (j > 1 && i < 5))) ? 1 : 0f; + paevals[j][i] = paevals[i][j]; + } + } + PAEContactMatrix dummyMat = new PAEContactMatrix(sq, paevals); + AlignmentAnnotation paeCm = sq.addContactList(dummyMat); + al.addAnnotation(paeCm); + File tfile = File.createTempFile("testStoreAndRecoverPAEmatrix", + ".jvp"); + new Jalview2XML(false).saveState(tfile); + Desktop.instance.closeAll_actionPerformed(null); + + af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(), + DataSourceType.FILE); + AlignmentI newAl = af.getViewport().getAlignment(); + SequenceI newSeq = newAl.getSequenceAt(0); + // check annotation of the expected type exists + Assert.assertEquals(newSeq.getAnnotation().length, 1); + Assert.assertEquals(newSeq.getAnnotation()[0].graph, paeCm.graph); + + // check a contact matrix was recovered + Assert.assertEquals(newSeq.getContactMaps().size(), 1); + // and can be found for the annotation + ContactMatrixI restoredMat = al + .getContactMatrixFor(newSeq.getAnnotation()[0]); + Assert.assertNotNull(restoredMat); + for (i = sq.getLength() - 1; i >= 0; i--) + { + ContactListI oldCM = dummyMat.getContactList(i), + newCM = restoredMat.getContactList(i); + for (int j = oldCM.getContactHeight(); j >= 0; j--) + { + Assert.assertEquals(oldCM.getContactAt(j), newCM.getContactAt(j)); + } + } + } + }