X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fdatamodel%2FAlignmentAnnotationTests.java;h=19a725ecfb1fd3ddc09edc3e627b085dea18ad0a;hb=bc07c82cde95d498cf6919422baf7ad3994e1bf2;hp=dc86f78d553ab330a36a68f9440553ca49108c8b;hpb=5f4e1e4c330b045e9c8bce28ee132a0fca3834d8;p=jalview.git diff --git a/test/jalview/datamodel/AlignmentAnnotationTests.java b/test/jalview/datamodel/AlignmentAnnotationTests.java index dc86f78..19a725e 100644 --- a/test/jalview/datamodel/AlignmentAnnotationTests.java +++ b/test/jalview/datamodel/AlignmentAnnotationTests.java @@ -20,13 +20,15 @@ */ package jalview.datamodel; +import static org.testng.Assert.assertNull; 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.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -129,7 +131,8 @@ public class AlignmentAnnotationTests alSeq2.setEnd(sqTo.getStart() + align.getSeq2End() - 1); alSeq2.setDatasetSequence(sqTo); System.out.println(new AppletFormatAdapter() - .formatSequences("STH", new Alignment(new SequenceI[] { sqFrom, +.formatSequences( + FileFormat.Stockholm, new Alignment(new SequenceI[] { sqFrom, alSeq1, sqTo, alSeq2 }), true)); Mapping mp = align.getMappingFromS1(false); @@ -153,7 +156,8 @@ public class AlignmentAnnotationTests 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++) @@ -290,4 +294,133 @@ public class AlignmentAnnotationTests ann.getDefaultRnaHelixSymbol(i)); } } -} \ No newline at end of file + + public static Annotation newAnnotation(String ann) + { + float val = 0f; + try + { + val = Float.parseFloat(ann); + } catch (NumberFormatException q) + { + } + ; + return new Annotation(ann, ann, '\0', val); + } + + @Test(groups = { "Functional" }) + public void testIsQuantitative() + { + AlignmentAnnotation ann = null; + + ann = new AlignmentAnnotation("an", "some an", null); + Assert.assertFalse(ann.isQuantitative(), + "Empty annotation set should not be quantitative."); + + ann = new AlignmentAnnotation("an", "some an", new Annotation[] { + newAnnotation("4"), newAnnotation("1"), newAnnotation("1"), + newAnnotation("0.1"), newAnnotation("0.3") }); + Assert.assertTrue(ann.isQuantitative(), + "All numbers annotation set should be quantitative."); + + ann = new AlignmentAnnotation("an", "some an", new Annotation[] { + newAnnotation("E"), newAnnotation("E"), newAnnotation("E"), + newAnnotation("E"), newAnnotation("E") }); + Assert.assertFalse(ann.isQuantitative(), + "All 'E' annotation set should not be quantitative."); + + ann = new AlignmentAnnotation("an", "some an", new Annotation[] { + newAnnotation("E"), newAnnotation("1"), newAnnotation("2"), + newAnnotation("3"), newAnnotation("E") }); + Assert.assertTrue(ann.isQuantitative(), + "Mixed 'E' annotation set should be quantitative."); + } + + @Test(groups = "Functional") + public void testMakeVisibleAnnotation() + { + HiddenColumns h = new HiddenColumns(); + Annotation[] anns = new Annotation[] { null, null, new Annotation(1), + new Annotation(2), new Annotation(3), null, null, new Annotation(4), + new Annotation(5), new Annotation(6), new Annotation(7), + new Annotation(8) }; + AlignmentAnnotation ann = new AlignmentAnnotation("an", "some an", + anns); + + // null annotations + AlignmentAnnotation emptyann = new AlignmentAnnotation("an", "some ann", + null); + emptyann.makeVisibleAnnotation(h); + assertNull(emptyann.annotations); + + emptyann.makeVisibleAnnotation(3, 4, h); + assertNull(emptyann.annotations); + + // without bounds, does everything + ann.makeVisibleAnnotation(h); + assertEquals(12, ann.annotations.length); + assertNull(ann.annotations[0]); + assertNull(ann.annotations[1]); + assertEquals(1.0f, ann.annotations[2].value); + assertEquals(2.0f, ann.annotations[3].value); + assertEquals(3.0f, ann.annotations[4].value); + assertNull(ann.annotations[5]); + assertNull(ann.annotations[6]); + assertEquals(4.0f, ann.annotations[7].value); + assertEquals(5.0f, ann.annotations[8].value); + assertEquals(6.0f, ann.annotations[9].value); + assertEquals(7.0f, ann.annotations[10].value); + assertEquals(8.0f, ann.annotations[11].value); + + // without hidden cols, just truncates + ann.makeVisibleAnnotation(3, 5, h); + assertEquals(3, ann.annotations.length); + assertEquals(2.0f, ann.annotations[0].value); + assertEquals(3.0f, ann.annotations[1].value); + assertNull(ann.annotations[2]); + + anns = new Annotation[] { null, null, new Annotation(1), + new Annotation(2), new Annotation(3), null, null, new Annotation(4), + new Annotation(5), new Annotation(6), new Annotation(7), + new Annotation(8) }; + ann = new AlignmentAnnotation("an", "some an", anns); + h.hideColumns(4, 7); + ann.makeVisibleAnnotation(1, 9, h); + assertEquals(5, ann.annotations.length); + assertNull(ann.annotations[0]); + assertEquals(1.0f, ann.annotations[1].value); + assertEquals(2.0f, ann.annotations[2].value); + assertEquals(5.0f, ann.annotations[3].value); + assertEquals(6.0f, ann.annotations[4].value); + + anns = new Annotation[] { null, null, new Annotation(1), + new Annotation(2), new Annotation(3), null, null, new Annotation(4), + new Annotation(5), new Annotation(6), new Annotation(7), + new Annotation(8) }; + ann = new AlignmentAnnotation("an", "some an", anns); + h.hideColumns(1, 2); + ann.makeVisibleAnnotation(1, 9, h); + assertEquals(3, ann.annotations.length); + assertEquals(2.0f, ann.annotations[0].value); + assertEquals(5.0f, ann.annotations[1].value); + assertEquals(6.0f, ann.annotations[2].value); + + anns = new Annotation[] { null, null, new Annotation(1), + new Annotation(2), new Annotation(3), null, null, new Annotation(4), + new Annotation(5), new Annotation(6), new Annotation(7), + new Annotation(8), new Annotation(9), new Annotation(10), + new Annotation(11), new Annotation(12), new Annotation(13), + new Annotation(14), new Annotation(15) }; + ann = new AlignmentAnnotation("an", "some an", anns); + h = new HiddenColumns(); + h.hideColumns(5, 18); + h.hideColumns(20, 21); + ann.makeVisibleAnnotation(1, 21, h); + assertEquals(5, ann.annotations.length); + assertEquals(1.0f, ann.annotations[1].value); + assertEquals(2.0f, ann.annotations[2].value); + assertEquals(3.0f, ann.annotations[3].value); + assertNull(ann.annotations[0]); + assertNull(ann.annotations[4]); + } +}