/*
* Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
* Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Jalview. If not, see
* 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(alntestFile, DataSourceType.PASTE); AlignmentI al = alf.getViewport().getAlignment(); Assert.assertEquals(al.getHeight(), 4); Assert.assertEquals(al.getWidth(), 5); 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[i * 2], sf1[i * 2 + 1], "sf1")); } if (sf2[i * 2] > 0) { ds.addSequenceFeature(new SequenceFeature("sf2", "sf2", sf2[i * 2], sf2[i * 2 + 1], "sf2")); } if (sf3[i * 2] > 0) { ds.addSequenceFeature(new SequenceFeature("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( alf.getFeatureRenderer().getDisplayedFeatureTypes().size(), 3, "Number of feature types"); assertTrue(alf.getCurrentView().areFeaturesDisplayed()); return alf; } /** * Verify computed distances of sequences with similar secondary structures */ @Test(groups = "Functional") public void testFindDistances_AllSimilar() { AlignFrame af = setupAlignmentView("All Similar"); AlignViewport viewport = af.getViewport(); AlignmentView view = viewport.getAlignmentView(false); ScoreModelI sm = new SecondaryStructureDistanceModel(); sm = ScoreModels.getInstance().getScoreModel(sm.getName(), af.alignPanel); /* * feature distance model always normalises by region width */ SimilarityParamsI params = new SimilarityParams(false, true, true, true); MatrixI distances = sm.findDistances(view, params); assertEquals(distances.getValue(0, 0), 0d); assertEquals(distances.getValue(1, 1), 0d); assertEquals(distances.getValue(0, 1), 0d / 4); assertEquals(distances.getValue(1, 0), 0d / 4); } /** * Verify computed distances of sequences with partially similar secondary structures */ @Test(groups = "Functional") public void testFindDistances_PartiallySimilar() { AlignFrame af = setupAlignmentView("Partially Similar"); AlignViewport viewport = af.getViewport(); AlignmentView view = viewport.getAlignmentView(false); ScoreModelI sm = new SecondaryStructureDistanceModel(); sm = ScoreModels.getInstance().getScoreModel(sm.getName(), af.alignPanel); /* * score = 0 + 0 + 2 + 2 = 4/4 */ SimilarityParamsI params = new SimilarityParams(false, true, true, true); MatrixI distances = sm.findDistances(view, params); assertEquals(distances.getValue(0, 0), 0d); assertEquals(distances.getValue(1, 1), 0d); assertEquals(distances.getValue(0, 1), 1d); // should be 13d/6 assertEquals(distances.getValue(1, 0), 1d); } /** * Verify computed distances of sequences with dissimilar secondary structures */ @Test(groups = "Functional") public void testFindDistances_notSimilar() { AlignFrame af = setupAlignmentView("Not Similar"); AlignViewport viewport = af.getViewport(); AlignmentView view = viewport.getAlignmentView(false); ScoreModelI sm = new SecondaryStructureDistanceModel(); sm = ScoreModels.getInstance().getScoreModel(sm.getName(), af.alignPanel); /* * score = 2 + 2 + 2 + 2 = 8/4 */ SimilarityParamsI params = new SimilarityParams(false, true, true, true); MatrixI distances = sm.findDistances(view, params); assertEquals(distances.getValue(0, 0), 0d); assertEquals(distances.getValue(1, 1), 0d); assertEquals(distances.getValue(0, 1), 2d); assertEquals(distances.getValue(1, 0), 2d); } /** * Verify computed distances of sequences with dissimilar secondary structures * with coil structure represented as null */ @Test(groups = "Functional") public void testFindDistances_withCoil() { AlignFrame af = setupAlignmentView("With Coil"); AlignViewport viewport = af.getViewport(); AlignmentView view = viewport.getAlignmentView(false); ScoreModelI sm = new SecondaryStructureDistanceModel(); sm = ScoreModels.getInstance().getScoreModel(sm.getName(), af.alignPanel); /* * score = 2 + 2 + 2 + 2 = 8/4 */ SimilarityParamsI params = new SimilarityParams(false, true, true, true); MatrixI distances = sm.findDistances(view, params); assertEquals(distances.getValue(0, 0), 0d); assertEquals(distances.getValue(1, 1), 0d); assertEquals(distances.getValue(0, 1), 2d); assertEquals(distances.getValue(1, 0), 2d); } /** * Verify computed distances of sequences with gap */ @Test(groups = "Functional") public void testFindDistances_withGap() { AlignFrame af = setupAlignmentViewWithGap(); AlignViewport viewport = af.getViewport(); AlignmentView view = viewport.getAlignmentView(false); ScoreModelI sm = new SecondaryStructureDistanceModel(); sm = ScoreModels.getInstance().getScoreModel(sm.getName(), af.alignPanel); /* * feature distance model always normalises by region width * gap-gap is always included (but scores zero) * the only variable parameter is 'includeGaps' */ /* * include gaps * score = 0 + 0 + 1 + 0 = 1/4 */ SimilarityParamsI params = new SimilarityParams(false, true, true, true); MatrixI distances = sm.findDistances(view, params); assertEquals(distances.getValue(0, 0), 0d); assertEquals(distances.getValue(1, 1), 0d); assertEquals(distances.getValue(0, 1), 1d/4); assertEquals(distances.getValue(1, 0), 1d/4); /* * exclude gaps * score = 0 + 0 + 0 + 0 = 0/4 */ SimilarityParamsI params2 = new SimilarityParams(false, true, false, true); MatrixI distances2 = sm.findDistances(view, params2); assertEquals(distances2.getValue(0, 1), 0d); assertEquals(distances2.getValue(1, 0), 0d); } /** * Verify computed distances of sequences with gap */ @Test(groups = "Functional") public void testFindDistances_withSSUndefinedInEitherOneSeq() { AlignFrame af = setupAlignmentViewWithoutSS("either"); AlignViewport viewport = af.getViewport(); AlignmentView view = viewport.getAlignmentView(false); ScoreModelI sm = new SecondaryStructureDistanceModel(); sm = ScoreModels.getInstance().getScoreModel(sm.getName(), af.alignPanel); /* * feature distance model always normalises by region width * gap-gap is always included (but scores zero) * the only variable parameter is 'includeGaps' */ /* * include gaps * score = 0 + 0 + 2 + 2 = 2/4 */ SimilarityParamsI params = new SimilarityParams(false, true, true, true); MatrixI distances = sm.findDistances(view, params); assertEquals(distances.getValue(0, 0), 0d); assertEquals(distances.getValue(1, 1), 0d); assertEquals(distances.getValue(0, 1), 2d); assertEquals(distances.getValue(1, 0), 2d); /* * exclude gaps * score = 0 + 0 + 2 + 2 = 2/4 */ SimilarityParamsI params2 = new SimilarityParams(false, true, false, true); MatrixI distances2 = sm.findDistances(view, params2); assertEquals(distances2.getValue(0, 1), 2d); assertEquals(distances2.getValue(1, 0), 2d); } /** * Verify computed distances of sequences with gap */ @Test(groups = "Functional") public void testFindDistances_withSSUndefinedInBothSeqs() { AlignFrame af = setupAlignmentViewWithoutSS("both"); AlignViewport viewport = af.getViewport(); AlignmentView view = viewport.getAlignmentView(false); ScoreModelI sm = new SecondaryStructureDistanceModel(); sm = ScoreModels.getInstance().getScoreModel(sm.getName(), af.alignPanel); /* * feature distance model always normalises by region width * gap-gap is always included (but scores zero) * the only variable parameter is 'includeGaps' */ /* * include gaps * score = 0 + 0 + 2 + 2 = 2/4 */ SimilarityParamsI params = new SimilarityParams(false, true, true, true); MatrixI distances = sm.findDistances(view, params); assertEquals(distances.getValue(0, 0), 0d); assertEquals(distances.getValue(1, 1), 0d); assertEquals(distances.getValue(0, 1), 0d); assertEquals(distances.getValue(1, 0), 0d); /* * exclude gaps * score = 0 + 0 + 2 + 2 = 2/4 */ SimilarityParamsI params2 = new SimilarityParams(false, true, false, true); MatrixI distances2 = sm.findDistances(view, params2); assertEquals(distances2.getValue(0, 1), 0d); assertEquals(distances2.getValue(1, 0), 0d); } /** *
* Set up * column 1 2 3 4 * seq s1 F R K S * * seq s2 F S J L ** * @return */ protected AlignFrame setupAlignmentView(String similar) { /* * sequences without gaps */ SequenceI s1 = new Sequence("s1", "FRKS"); SequenceI s2 = new Sequence("s2", "FSJL"); s1.addSequenceFeature( new SequenceFeature("chain", null, 1, 4, 0f, null)); s1.addSequenceFeature( new SequenceFeature("domain", null, 1, 4, 0f, null)); s2.addSequenceFeature( new SequenceFeature("chain", null, 1, 4, 0f, null)); s2.addSequenceFeature( new SequenceFeature("metal", null, 1, 4, 0f, null)); s2.addSequenceFeature( new SequenceFeature("Pfam", null, 1, 4, 0f, null)); /* * Set up secondary structure annotations */ Annotation ssE = new Annotation("","",'E',0); Annotation ssH = new Annotation("","",'H',0); Annotation ssC = new Annotation(".","",' ',0); Annotation[] anns1; Annotation[] anns2; /* All secondary structure annotations are similar for each column * Set up * column 1 2 3 4 * seq s1 F R K S * ss E H S E * * seq s2 F S J L * ss E H S E */ if(similar == "All Similar") { anns1 = new Annotation[] { ssE, ssH, ssC, ssE}; anns2 = new Annotation[] { ssE, ssH, ssC, ssE}; } /* All secondary structure annotations are dissimilar for each column * Set up * column 1 2 3 4 * seq s1 F R K S * ss E E C E * * seq s2 F S J L * ss H E E C */ else if(similar == "Not Similar") { anns1 = new Annotation[] { ssE, ssE, ssC, ssE}; anns2 = new Annotation[] { ssH, ssH, ssE, ssC}; } /* All secondary structure annotations are dissimilar for each column * Set up * column 1 2 3 4 * seq s1 F R K S * ss E E C E * * seq s2 F S J L * ss H E E C */ else if(similar == "With Coil") { anns1 = new Annotation[] { ssE, ssE, null, ssE}; anns2 = new Annotation[] { ssH, ssH, ssE, null}; } /* Set up * column 1 2 3 4 * seq s1 F R K S * ss H E C E * * seq s2 F S J L * ss H E E C */ else { anns1 = new Annotation[] { ssH, ssE, ssC, ssE}; anns2 = new Annotation[] { ssH, ssE, ssE, ssC}; } AlignmentAnnotation ann1 = new AlignmentAnnotation("Secondary Structure", "Secondary Structure", anns1); AlignmentAnnotation ann2 = new AlignmentAnnotation("Secondary Structure", "Secondary Structure", anns2); s1.addAlignmentAnnotation(ann1); s2.addAlignmentAnnotation(ann2); AlignmentI al = new Alignment(new SequenceI[] { s1, s2 }); AlignFrame af = new AlignFrame(al, 300, 300); af.setShowSeqFeatures(true); af.getFeatureRenderer().findAllFeatures(true); return af; } /** *
* Set up * column 1 2 3 4 * seq s1 F R S * SS H E C * * seq s2 F S J L * ss H E E C ** * @return */ protected AlignFrame setupAlignmentViewWithGap() { SequenceI s1 = new Sequence("s1", "FR S"); SequenceI s2 = new Sequence("s2", "FSJL"); s1.addSequenceFeature( new SequenceFeature("chain", null, 1, 3, 0f, null)); s1.addSequenceFeature( new SequenceFeature("domain", null, 1, 3, 0f, null)); s2.addSequenceFeature( new SequenceFeature("chain", null, 1, 4, 0f, null)); s2.addSequenceFeature( new SequenceFeature("metal", null, 1, 4, 0f, null)); s2.addSequenceFeature( new SequenceFeature("Pfam", null, 1, 4, 0f, null)); Annotation ssE = new Annotation("","",'E',0); Annotation ssH = new Annotation("","",'H',0); Annotation ssC = new Annotation(".","",' ',0); Annotation[] anns1; Annotation[] anns2; anns1 = new Annotation[] { ssH, ssE, ssC}; anns2 = new Annotation[] { ssH, ssE, ssE, ssC}; AlignmentAnnotation ann1 = new AlignmentAnnotation("Secondary Structure", "Secondary Structure", anns1); AlignmentAnnotation ann2 = new AlignmentAnnotation("Secondary Structure", "Secondary Structure", anns2); s1.addAlignmentAnnotation(ann1); s2.addAlignmentAnnotation(ann2); AlignmentI al = new Alignment(new SequenceI[] { s1, s2 }); AlignFrame af = new AlignFrame(al, 300, 300); af.setShowSeqFeatures(true); af.getFeatureRenderer().findAllFeatures(true); return af; } protected AlignFrame setupAlignmentViewWithoutSS(String type) { SequenceI s1 = new Sequence("s1", "FR S"); SequenceI s2 = new Sequence("s2", "FSJL"); s1.addSequenceFeature( new SequenceFeature("chain", null, 1, 3, 0f, null)); s1.addSequenceFeature( new SequenceFeature("domain", null, 1, 3, 0f, null)); s2.addSequenceFeature( new SequenceFeature("chain", null, 1, 4, 0f, null)); s2.addSequenceFeature( new SequenceFeature("metal", null, 1, 4, 0f, null)); s2.addSequenceFeature( new SequenceFeature("Pfam", null, 1, 4, 0f, null)); if(!type.equals("both")) { Annotation ssE = new Annotation("","",'E',0); Annotation ssH = new Annotation("","",'H',0); Annotation ssC = new Annotation(".","",' ',0); Annotation[] anns1; anns1 = new Annotation[] { ssH, ssE, ssC}; AlignmentAnnotation ann1 = new AlignmentAnnotation("Secondary Structure", "Secondary Structure", anns1); s1.addAlignmentAnnotation(ann1); } AlignmentI al = new Alignment(new SequenceI[] { s1, s2 }); AlignFrame af = new AlignFrame(al, 300, 300); af.setShowSeqFeatures(true); af.getFeatureRenderer().findAllFeatures(true); return af; } }