X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=test%2Fjalview%2Fanalysis%2FAlignmentUtilsTests.java;fp=test%2Fjalview%2Fanalysis%2FAlignmentUtilsTests.java;h=eee5e87502b63ea08cca1a5638be50032aa32250;hb=9f21fcf9df545f0900a0f86250a14f15c448e30a;hp=f017662081eda164e5a0605f6c28743c97d82ec5;hpb=fccc58b804b576fcd39f3e7f2c9699c0ba75d5f9;p=jalview.git diff --git a/test/jalview/analysis/AlignmentUtilsTests.java b/test/jalview/analysis/AlignmentUtilsTests.java index f017662..eee5e87 100644 --- a/test/jalview/analysis/AlignmentUtilsTests.java +++ b/test/jalview/analysis/AlignmentUtilsTests.java @@ -28,16 +28,20 @@ import static org.testng.AssertJUnit.assertNull; import static org.testng.AssertJUnit.assertSame; import static org.testng.AssertJUnit.assertTrue; +import java.awt.Color; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; +import org.testng.Assert; import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import jalview.datamodel.AlignedCodonFrame; @@ -78,6 +82,25 @@ public class AlignmentUtilsTests { JvOptionPane.setInteractiveMode(false); JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + + AlignmentAnnotation ann1 = new AlignmentAnnotation("Secondary Structure", "Secondary Structure", + new Annotation[] {}); + AlignmentAnnotation ann2 = new AlignmentAnnotation("jnetpred", "jnetpred", + new Annotation[] {}); + AlignmentAnnotation ann3 = new AlignmentAnnotation("Temp", "Temp", + new Annotation[] {}); + AlignmentAnnotation ann4 = new AlignmentAnnotation("Temp", "Temp", + new Annotation[] {}); + + AlignmentAnnotation[] anns1 = new AlignmentAnnotation[] {ann1, ann3, ann4}; + + AlignmentAnnotation[] anns2 = new AlignmentAnnotation[] {ann2, ann3, ann4}; + + AlignmentAnnotation[] anns3 = new AlignmentAnnotation[] {ann3, ann4}; + + AlignmentAnnotation[] anns4 = new AlignmentAnnotation[0]; + + AlignmentAnnotation[] anns5 = new AlignmentAnnotation[] {ann1, ann2, ann3, ann4}; } @Test(groups = { "Functional" }) @@ -2751,4 +2774,140 @@ public class AlignmentUtilsTests && al.getAlignmentAnnotation().length == 2); } + + @Test(groups = "Functional", dataProvider = "SecondaryStructureAnnotations") + public void testSecondaryStructurePresentAndSources(AlignmentAnnotation[] annotations, boolean expectedSSPresent, ArrayList expectedSSSources) { + Assert.assertEquals(expectedSSPresent, AlignmentUtils.isSecondaryStructurePresent(annotations)); + Assert.assertEquals(expectedSSSources, AlignmentUtils.getSecondaryStructureSources(annotations)); + } + + @DataProvider(name = "SecondaryStructureAnnotations") + public static Object[][] provideSecondaryStructureAnnotations() { + AlignmentAnnotation ann1 = new AlignmentAnnotation("Secondary Structure", "Secondary Structure", new Annotation[]{}); + AlignmentAnnotation ann2 = new AlignmentAnnotation("jnetpred", "jnetpred", new Annotation[]{}); + AlignmentAnnotation ann3 = new AlignmentAnnotation("Temp", "Temp", new Annotation[]{}); + AlignmentAnnotation ann4 = new AlignmentAnnotation("Temp", "Temp", new Annotation[]{}); + + List ssSources1 = new ArrayList<>(Arrays.asList("3D Structures")); + List ssSources2 = new ArrayList<>(Arrays.asList("JPred")); + List ssSources3 = new ArrayList<>(Arrays.asList("3D Structures", "JPred")); + List ssSources4 = new ArrayList<>(); + + return new Object[][]{ + {new AlignmentAnnotation[]{ann1, ann3, ann4}, true, ssSources1}, + {new AlignmentAnnotation[]{ann2, ann3, ann4}, true, ssSources2}, + {new AlignmentAnnotation[]{ann3, ann4}, false, ssSources4}, + {new AlignmentAnnotation[]{}, false, ssSources4}, + {new AlignmentAnnotation[]{ann1, ann2, ann3, ann4}, true, ssSources3} + }; + } + + @Test(dataProvider = "SecondaryStructureAnnotationColours") + public void testSecondaryStructureAnnotationColour(char symbol, Color expectedColor) { + Color actualColor = AlignmentUtils.getSecondaryStructureAnnotationColour(symbol); + Assert.assertEquals(actualColor, expectedColor); + } + + @DataProvider(name = "SecondaryStructureAnnotationColours") + public static Object[][] provideSecondaryStructureAnnotationColours() { + return new Object[][]{ + {'C', Color.gray}, + {'E', Color.green}, + {'H', Color.red}, + {'-', Color.gray} + }; + } + + @Test(dataProvider = "SSAnnotationPresence") + public void testIsSSAnnotationPresent(Map> annotations, boolean expectedPresence) { + boolean actualPresence = AlignmentUtils.isSSAnnotationPresent(annotations); + Assert.assertEquals(actualPresence, expectedPresence); + } + + @DataProvider(name = "SSAnnotationPresence") + public static Object[][] provideSSAnnotationPresence() { + Map> annotations1 = new HashMap<>(); + SequenceI seq1 = new Sequence("Seq1", "ASD---ASD---ASD", 37, 45); + List annotationsList1 = new ArrayList<>(); + annotationsList1.add(new AlignmentAnnotation("Secondary Structure", "Secondary Structure", new Annotation[]{})); + annotations1.put(seq1, annotationsList1); // Annotation present secondary structure for seq1 + + Map> annotations2 = new HashMap<>(); + SequenceI seq2 = new Sequence("Seq2", "ASD---ASD------", 37, 42); + List annotationsList2 = new ArrayList<>(); + annotationsList2.add(new AlignmentAnnotation("Other Annotation", "Other Annotation", new Annotation[]{})); + annotations2.put(seq2, annotationsList2); // Annotation not related to any of secondary structure for seq2 + + Map> annotations3 = new HashMap<>(); + // Empty annotation map + + Map> annotations4 = new HashMap<>(); + SequenceI seq4 = new Sequence("Seq4", "ASD---ASD---AS-", 37, 44); + List annotationsList4 = new ArrayList<>(); + annotationsList4.add(new AlignmentAnnotation("jnetpred", "jnetpred", new Annotation[]{})); + annotations4.put(seq4, annotationsList4); // Annotation present from JPred for seq4 + + + return new Object[][]{ + {annotations1, true}, // Annotations present secondary structure present + {annotations2, false}, // No annotations related to any of the secondary structure present + {annotations3, false}, // Empty annotation map + {annotations4, true}, // Annotations present from JPred secondary structure present + }; + } +// +// @Test(dataProvider = "SSSourceFromAnnotationDescription") +// public void testGetSSSourceFromAnnotationDescription(Map> annotations, String expectedSSSource) { +// String actualSSSource = AlignmentUtils.getSSSourceFromAnnotationDescription(annotations); +// Assert.assertEquals(actualSSSource, expectedSSSource); +// } + + @DataProvider(name = "SSSourceFromAnnotationDescription") + public static Object[][] provideSSSourceFromAnnotationDescription() { + Map> annotations1 = new HashMap<>(); + SequenceI seq1 = new Sequence("Seq1", "ASD---ASD---ASD", 37, 45); + List annotationsList1 = new ArrayList<>(); + annotationsList1.add(new AlignmentAnnotation("jnetpred", "JPred Output", new Annotation[]{})); + annotations1.put(seq1, annotationsList1); // Annotation present from JPred for seq1 + + Map> annotations2 = new HashMap<>(); + SequenceI seq2 = new Sequence("Seq2", "ASD---ASD------", 37, 42); + List annotationsList2 = new ArrayList<>(); + annotationsList2.add(new AlignmentAnnotation("Secondary Structure", + "Secondary Structure for af-q43517-f1A", new Annotation[]{})); + annotations2.put(seq2, annotationsList2); // Annotation present secondary structure from Alphafold for seq2 + + Map> annotations3 = new HashMap<>(); + // Empty annotation map + + Map> annotations4 = new HashMap<>(); + SequenceI seq4 = new Sequence("Seq4", "ASD---ASD---AS-", 37, 44); + List annotationsList4 = new ArrayList<>(); + annotationsList4.add(new AlignmentAnnotation("Secondary Structure", + "Secondary Structure for 4zhpA", new Annotation[]{})); + annotations4.put(seq4, annotationsList4); // Annotation present secondary structure from pdb for seq4 + + Map> annotations5 = new HashMap<>(); + SequenceI seq5 = new Sequence("Seq5", "ASD---ASD---AS-", 37, 44); + List annotationsList5 = new ArrayList<>(); + annotationsList5.add(new AlignmentAnnotation("Secondary Structure", + "Secondary Structure for p09911_54-147__3a7wzn.1.p3502557454997462030P", + new Annotation[]{})); + annotations5.put(seq5, annotationsList5); // Annotation present secondary structure from Swiss model for seq5 + + + //JPred Output - JPred + //Secondary Structure for af-q43517-f1A - Alphafold + //Secondary Structure for 4zhpA - Experimental + //Secondary Structure for p09911_54-147__3a7wzn.1.p3502557454997462030P - Swiss Model + + return new Object[][]{ + {annotations1, "JPred"}, + {annotations2, "Alphafold"}, + {annotations3, null}, + {annotations4, "PDB"}, + {annotations5, "Swiss Model"} + }; + } + }