X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fdatamodel%2FAlignmentAnnotationTests.java;h=a2c62568c22afac1768c8c95ffcaa7ead0860214;hb=6d183feafe3e566501af586286bbd1d2107ee5a9;hp=4c9eabead412c49706a2285854446050fda5d77b;hpb=c93b9ad2ebfab4cad4608a8890132918589576be;p=jalview.git diff --git a/test/jalview/datamodel/AlignmentAnnotationTests.java b/test/jalview/datamodel/AlignmentAnnotationTests.java index 4c9eabe..a2c6256 100644 --- a/test/jalview/datamodel/AlignmentAnnotationTests.java +++ b/test/jalview/datamodel/AlignmentAnnotationTests.java @@ -1,16 +1,47 @@ +/* + * 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 . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.datamodel; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertNull; import jalview.analysis.AlignSeq; +import jalview.gui.JvOptionPane; import jalview.io.AppletFormatAdapter; +import jalview.io.FileFormat; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class AlignmentAnnotationTests { - @Test + + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + + @Test(groups = { "Functional" }) public void testCopyConstructor() { SequenceI sq = new Sequence("Foo", "ARAARARARAWEAWEAWRAWEAWE"); @@ -23,6 +54,7 @@ public class AlignmentAnnotationTests alc.getProperty(key)); } } + /** * create some dummy annotation derived from the sequence * @@ -74,7 +106,7 @@ public class AlignmentAnnotationTests * different dataset frames (annotation transferred by mapping between * sequences) */ - @Test + @Test(groups = { "Functional" }) public void testLiftOver() { SequenceI sqFrom = new Sequence("fromLong", "QQQCDEWGH"); @@ -97,9 +129,10 @@ public class AlignmentAnnotationTests alSeq2.setStart(sqTo.getStart() + align.getSeq2Start() - 1); alSeq2.setEnd(sqTo.getStart() + align.getSeq2End() - 1); alSeq2.setDatasetSequence(sqTo); - System.out.println(new AppletFormatAdapter().formatSequences("STH", - new Alignment(new SequenceI[] - { sqFrom, alSeq1, sqTo, alSeq2 }), true)); + System.out.println(new AppletFormatAdapter() +.formatSequences( + FileFormat.Stockholm, new Alignment(new SequenceI[] { sqFrom, + alSeq1, sqTo, alSeq2 }), true)); Mapping mp = align.getMappingFromS1(false); @@ -119,11 +152,11 @@ public class AlignmentAnnotationTests almap2.setSequenceRef(alSeq2); almap2.adjustForAlignment(); - AlignmentI all = new Alignment(new SequenceI[] - { alSeq1, alSeq2 }); + AlignmentI all = new Alignment(new SequenceI[] { alSeq1, alSeq2 }); all.addAnnotation(almap1); all.addAnnotation(almap2); - System.out.println(new AppletFormatAdapter().formatSequences("STH", + System.out.println(new AppletFormatAdapter().formatSequences( + FileFormat.Stockholm, all, true)); for (int p = 0; p < alSeq1.getLength(); p++) @@ -157,7 +190,7 @@ public class AlignmentAnnotationTests } } - @Test + @Test(groups = { "Functional" }) public void testAdjustForAlignment() { SequenceI seq = new Sequence("TestSeq", "ABCDEFG"); @@ -166,8 +199,8 @@ public class AlignmentAnnotationTests /* * Annotate positions 3/4/5 (CDE) with values 1/2/3 */ - Annotation[] anns = new Annotation[] - { null, null, new Annotation(1), new Annotation(2), new Annotation(3) }; + Annotation[] anns = new Annotation[] { null, null, new Annotation(1), + new Annotation(2), new Annotation(3) }; AlignmentAnnotation ann = new AlignmentAnnotation("SS", "secondary structure", anns); seq.addAlignmentAnnotation(ann); @@ -199,4 +232,65 @@ public class AlignmentAnnotationTests assertEquals(1, ann.annotations[1].value, 0.001); assertEquals(2, ann.annotations[2].value, 0.001); } + + /** + * Test the method that defaults rna symbol to the one matching the preceding + * unmatched opening bracket (if any) + */ + @Test(groups = { "Functional" }) + public void testGetDefaultRnaHelixSymbol() + { + AlignmentAnnotation ann = new AlignmentAnnotation("SS", + "secondary structure", null); + assertEquals("(", ann.getDefaultRnaHelixSymbol(4)); + + Annotation[] anns = new Annotation[20]; + ann.annotations = anns; + assertEquals("(", ann.getDefaultRnaHelixSymbol(4)); + + anns[1] = new Annotation("(", "S", '(', 0f); + assertEquals("(", ann.getDefaultRnaHelixSymbol(0)); + assertEquals("(", ann.getDefaultRnaHelixSymbol(1)); + assertEquals(")", ann.getDefaultRnaHelixSymbol(2)); + assertEquals(")", ann.getDefaultRnaHelixSymbol(3)); + + /* + * .(.[.{.<.}.>.).]. + */ + anns[1] = new Annotation("(", "S", '(', 0f); + anns[3] = new Annotation("[", "S", '[', 0f); + anns[5] = new Annotation("{", "S", '{', 0f); + anns[7] = new Annotation("<", "S", '<', 0f); + anns[9] = new Annotation("}", "S", '}', 0f); + anns[11] = new Annotation(">", "S", '>', 0f); + anns[13] = new Annotation(")", "S", ')', 0f); + anns[15] = new Annotation("]", "S", ']', 0f); + + String expected = "(())]]}}>>>>]]]]("; + for (int i = 0; i < expected.length(); i++) + { + assertEquals("column " + i, String.valueOf(expected.charAt(i)), + ann.getDefaultRnaHelixSymbol(i)); + } + + /* + * .(.[.(.).{.}.<.].D. + */ + anns[1] = new Annotation("(", "S", '(', 0f); + anns[3] = new Annotation("[", "S", '[', 0f); + anns[5] = new Annotation("(", "S", '(', 0f); + anns[7] = new Annotation(")", "S", ')', 0f); + anns[9] = new Annotation("{", "S", '{', 0f); + anns[11] = new Annotation("}", "S", '}', 0f); + anns[13] = new Annotation("<", "S", '>', 0f); + anns[15] = new Annotation("]", "S", ']', 0f); + anns[17] = new Annotation("D", "S", 'D', 0f); + + expected = "(())]]))]]}}]]>>>>dd"; + for (int i = 0; i < expected.length(); i++) + { + assertEquals("column " + i, String.valueOf(expected.charAt(i)), + ann.getDefaultRnaHelixSymbol(i)); + } + } }