From: Jim Procter Date: Wed, 7 Jan 2015 18:02:10 +0000 (+0000) Subject: JAL-1483 basic test of sequence similarity score model (also gives the refactored... X-Git-Tag: Jalview_2_9~123^2~2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=75e40ab321a1487d9123276f48ceb93e67d9ba18;p=jalview.git JAL-1483 basic test of sequence similarity score model (also gives the refactored sequence feature components a workout) --- diff --git a/test/jalview/analysis/scoremodels/FeatureScoreModelTest.java b/test/jalview/analysis/scoremodels/FeatureScoreModelTest.java new file mode 100644 index 0000000..1dbaa4a --- /dev/null +++ b/test/jalview/analysis/scoremodels/FeatureScoreModelTest.java @@ -0,0 +1,74 @@ +package jalview.analysis.scoremodels; + +import jalview.datamodel.AlignmentI; +import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceI; +import jalview.gui.AlignFrame; +import jalview.io.FileLoader; +import jalview.io.FormatAdapter; + +import org.junit.Assert; +import org.junit.Test; + +public class FeatureScoreModelTest +{ + 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 }; + + int[] sf2 = new int[] + { -1, -1, 74, 75, -1, -1, 76, 77 }; + + int[] sf3 = new int[] + { -1, -1, -1, -1, -1, -1, 76, 77 }; + + @Test + public void testFeatureScoreModel() throws Exception + { + AlignFrame alf = new FileLoader(false).LoadFileWaitTillLoaded(alntestFile, + FormatAdapter.PASTE); + AlignmentI al = alf.getViewport().getAlignment(); + Assert.assertEquals(4, al.getHeight()); + Assert.assertEquals(5, al.getWidth()); + for (int i = 0; i < 4; i++) + { + SequenceI ds = al.getSequenceAt(i).getDatasetSequence(); + if (sf1[i * 2] > 0) + { + ds.addSequenceFeature(new SequenceFeature("sf1", "sf1", "sf1", + sf1[i * 2], sf1[i * 2 + 1], "sf1")); + } + if (sf2[i * 2] > 0) + { + ds.addSequenceFeature(new SequenceFeature("sf2", "sf2", "sf2", + sf2[i * 2], sf2[i * 2 + 1], "sf2")); + } + if (sf3[i * 2] > 0) + { + ds.addSequenceFeature(new SequenceFeature("sf3", "sf3", "sf3", + sf3[i * 2], sf3[i * 2 + 1], "sf3")); + } + } + alf.setShowSeqFeatures(true); + alf.getFeatureRenderer().setVisible("sf1"); + alf.getFeatureRenderer().setVisible("sf2"); + alf.getFeatureRenderer().setVisible("sf3"); + alf.getFeatureRenderer().findAllFeatures(true); + Assert.assertEquals("Number of feature types", 3, alf + .getFeatureRenderer().getDisplayedFeatureTypes().length); + Assert.assertTrue(alf.getCurrentView().areFeaturesDisplayed()); + FeatureScoreModel fsm = new FeatureScoreModel(); + Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView() + .getAlignPanel())); + alf.selectAllSequenceMenuItem_actionPerformed(null); + float[][] dm = fsm.findDistances(alf.getViewport().getAlignmentView( + true)); + Assert.assertTrue("FER1_MESCR should be identical with RAPSA (2)", + dm[0][2] == 0f); + Assert.assertTrue( + "FER1_MESCR should be further from SPIOL (1) than it is from RAPSA (2)", + dm[0][1] > dm[0][2]); + + } +}