X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fanalysis%2Fscoremodels%2FFeatureScoreModelTest.java;h=14254f79bdf2ead7f7b0206a97d3c131cd47b84b;hb=4724cafdcdcc4f3acc77c09261afe56f518a1e87;hp=1a9508151aa3e7a722209e2115adbf3685e89fac;hpb=ee198b3ca3687f18a2ee186f4e7c7330f4ea30f0;p=jalview.git diff --git a/test/jalview/analysis/scoremodels/FeatureScoreModelTest.java b/test/jalview/analysis/scoremodels/FeatureScoreModelTest.java index 1a95081..14254f7 100644 --- a/test/jalview/analysis/scoremodels/FeatureScoreModelTest.java +++ b/test/jalview/analysis/scoremodels/FeatureScoreModelTest.java @@ -20,18 +20,32 @@ */ package jalview.analysis.scoremodels; +import static org.testng.Assert.assertEquals; + import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; +import jalview.gui.JvOptionPane; import jalview.io.DataSourceType; import jalview.io.FileLoader; +import java.util.Arrays; + import org.testng.Assert; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class FeatureScoreModelTest { + + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + public static String alntestFile = "FER1_MESCR/72-76 DVYIL\nFER1_SPIOL/71-75 DVYIL\nFER3_RAPSA/21-25 DVYVL\nFER1_MAIZE/73-77 DVYIL\n"; int[] sf1 = new int[] { 74, 74, 73, 73, 23, 23, -1, -1 }; @@ -40,6 +54,17 @@ public class FeatureScoreModelTest int[] sf3 = new int[] { -1, -1, -1, -1, -1, -1, 76, 77 }; + /** + *
+   * Load test alignment and add features to sequences: 
+   *      FER1_MESCR FER1_SPIOL FER3_RAPSA FER1_MAIZE 
+   *  sf1     X          X          X  
+   *  sf2                X                     X 
+   *  sf3                                      X
+   * 
+ * + * @return + */ public AlignFrame getTestAlignmentFrame() { AlignFrame alf = new FileLoader(false).LoadFileWaitTillLoaded( @@ -82,9 +107,10 @@ public class FeatureScoreModelTest { AlignFrame alf = getTestAlignmentFrame(); FeatureScoreModel fsm = new FeatureScoreModel(); - Assert.assertTrue(fsm.configureFromAlignmentView(alf - .getCurrentView().getAlignPanel())); + Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView() + .getAlignPanel())); alf.selectAllSequenceMenuItem_actionPerformed(null); + float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView( true)); Assert.assertTrue(dm[0][2] == 0f, @@ -124,15 +150,110 @@ public class FeatureScoreModelTest alf.selectAllSequenceMenuItem_actionPerformed(null); float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView( true)); - Assert.assertTrue(dm[0][2] == 0f, + Assert.assertTrue( + dm[0][2] == 0f, "After hiding last two columns FER1_MESCR (0) should still be identical with RAPSA (2)"); - Assert.assertTrue(dm[0][1] == 0f, + Assert.assertTrue( + dm[0][1] == 0f, "After hiding last two columns FER1_MESCR (0) should now also be identical with SPIOL (1)"); - for (int s=0;s<3;s++) + for (int s = 0; s < 3; s++) { Assert.assertTrue(dm[s][3] > 0f, "After hiding last two columns " + alf.getViewport().getAlignment().getSequenceAt(s).getName() + "(" + s + ") should still be distinct from FER1_MAIZE (3)"); } } + + /** + * Check findFeatureAt doesn't return contact features except at contact + * points TODO:move to under the FeatureRendererModel test suite + */ + @Test(groups = { "Functional" }) + public void testFindFeatureAt_PointFeature() throws Exception + { + String alignment = "a CCCCCCGGGGGGCCCCCC\n" + "b CCCCCCGGGGGGCCCCCC\n" + + "c CCCCCCGGGGGGCCCCCC\n"; + AlignFrame af = new jalview.io.FileLoader(false) + .LoadFileWaitTillLoaded(alignment, DataSourceType.PASTE); + SequenceI aseq = af.getViewport().getAlignment().getSequenceAt(0); + SequenceFeature sf = null; + sf = new SequenceFeature("disulphide bond", "", 2, 5, Float.NaN, ""); + aseq.addSequenceFeature(sf); + Assert.assertTrue(sf.isContactFeature()); + af.refreshFeatureUI(true); + af.getFeatureRenderer().setAllVisible(Arrays.asList("disulphide bond")); + Assert.assertEquals(af.getFeatureRenderer().getDisplayedFeatureTypes() + .size(), 1, "Should be just one feature type displayed"); + // step through and check for pointwise feature presence/absence + Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 1) + .size(), 0); + // step through and check for pointwise feature presence/absence + Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 2) + .size(), 1); + // step through and check for pointwise feature presence/absence + Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 3) + .size(), 0); + // step through and check for pointwise feature presence/absence + Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 4) + .size(), 0); + // step through and check for pointwise feature presence/absence + Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 5) + .size(), 1); + // step through and check for pointwise feature presence/absence + Assert.assertEquals(af.getFeatureRenderer().findFeaturesAtRes(aseq, 6) + .size(), 0); + } + + @Test(groups = { "Functional" }) + public void testFindDistances() throws Exception + { + String seqs = ">s1\nABCDE\n>seq2\nABCDE\n"; + AlignFrame alf = new FileLoader().LoadFileWaitTillLoaded(seqs, + DataSourceType.PASTE); + SequenceI s1 = alf.getViewport().getAlignment().getSequenceAt(0); + SequenceI s2 = alf.getViewport().getAlignment().getSequenceAt(1); + + /* + * set domain and variant features thus: + * ----5 + * s1 ddd.. + * s1 .vvv. + * s1 ..vvv + * s2 .ddd. + * s2 vv..v + * The number of unshared feature types per column is + * 20120 (two features of the same type doesn't affect score) + * giving an average (pairwise distance) of 5/5 or 1.0 + */ + s1.addSequenceFeature(new SequenceFeature("domain", null, 1, 3, 0f, + null)); + s1.addSequenceFeature(new SequenceFeature("variant", null, 2, 4, 0f, + null)); + s1.addSequenceFeature(new SequenceFeature("variant", null, 3, 5, 0f, + null)); + s2.addSequenceFeature(new SequenceFeature("domain", null, 2, 4, 0f, + null)); + s2.addSequenceFeature(new SequenceFeature("variant", null, 1, 2, 0f, + null)); + s2.addSequenceFeature(new SequenceFeature("variant", null, 5, 5, 0f, + null)); + alf.setShowSeqFeatures(true); + alf.getFeatureRenderer().findAllFeatures(true); + + FeatureScoreModel fsm = new FeatureScoreModel(); + Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView() + .getAlignPanel())); + alf.selectAllSequenceMenuItem_actionPerformed(null); + + float[][] distances = fsm.findDistances(alf.getViewport() + .getAlignmentView(true)); + assertEquals(distances.length, 2); + assertEquals(distances[0][0], 0f); + assertEquals(distances[1][1], 0f); + // these left to fail pending resolution of + // JAL-2424 (dividing score by 6, not 5) + assertEquals(distances[0][1], 1f); + assertEquals(distances[1][0], 1f); + } + }