Merge branch 'features/JAL-1541_BioJsMSA' into develop
[jalview.git] / test / jalview / analysis / AlignmentAnnotationUtilsTest.java
index 1da1939..c34bb68 100644 (file)
@@ -3,10 +3,6 @@ package jalview.analysis;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import jalview.datamodel.AlignmentAnnotation;
-import jalview.datamodel.AlignmentI;
-import jalview.datamodel.SequenceI;
-import jalview.io.AppletFormatAdapter;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -19,6 +15,12 @@ import java.util.Map;
 import org.junit.Before;
 import org.junit.Test;
 
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Annotation;
+import jalview.datamodel.SequenceI;
+import jalview.io.AppletFormatAdapter;
+
 public class AlignmentAnnotationUtilsTest
 {
   // 4 sequences x 13 positions
@@ -36,7 +38,7 @@ public class AlignmentAnnotationUtilsTest
           "TIETHKEEELTA-" + EOL;
   // @formatter:on
 
-  private static final int SEQ_ANN_COUNT = 10;
+  private static final int SEQ_ANN_COUNT = 12;
 
   private AlignmentI alignment;
 
@@ -111,6 +113,11 @@ public class AlignmentAnnotationUtilsTest
     return result;
   }
 
+  /**
+   * Load the test alignment and generate annotations on it
+   * 
+   * @throws IOException
+   */
   @Before
   public void setUp() throws IOException
   {
@@ -120,7 +127,13 @@ public class AlignmentAnnotationUtilsTest
     AlignmentAnnotation[] anns = new AlignmentAnnotation[SEQ_ANN_COUNT];
     for (int i = 0; i < anns.length; i++)
     {
-      anns[i] = new AlignmentAnnotation("Label" + i, null, 0d);
+      /*
+       * Use the constructor for a positional annotation (with an Annotation
+       * array)
+       */
+      anns[i] = new AlignmentAnnotation("Label" + i, "Desc " + i,
+              new Annotation[]
+              {});
       anns[i].setCalcId("CalcId" + i);
       anns[i].visible = true;
       alignment.addAnnotation(anns[i]);
@@ -212,6 +225,7 @@ public class AlignmentAnnotationUtilsTest
   @Test
   public void testGetShownHiddenTypes_withGraphGroups()
   {
+    final int GROUP_3 = 3;
     final int GROUP_4 = 4;
     final int GROUP_5 = 5;
     final int GROUP_6 = 6;
@@ -222,10 +236,10 @@ public class AlignmentAnnotationUtilsTest
     SequenceI[] seqs = alignment.getSequencesArray();
   
     /*
-     * Configure annotation properties for test
+     * Annotations for selection group and graph group
+     * 
+     * Hidden annotations Label2, Label3, in (hidden) group 5
      */
-    // annotations for selection group and graph group
-    // hidden annotations Label2, Label3, in (hidden) group 5
     anns[2].sequenceRef = seqs[3];
     anns[2].visible = false;
     anns[2].graph = AlignmentAnnotation.LINE_GRAPH;
@@ -236,6 +250,19 @@ public class AlignmentAnnotationUtilsTest
     anns[3].graphGroup = GROUP_5;
     // need to ensure annotations have the same calcId as well
     anns[3].setCalcId("CalcId2");
+    // annotations for a different hidden group generating the same group label
+    anns[10].sequenceRef = seqs[0];
+    anns[10].visible = false;
+    anns[10].graph = AlignmentAnnotation.LINE_GRAPH;
+    anns[10].graphGroup = GROUP_3;
+    anns[10].label = "Label3";
+    anns[10].setCalcId("CalcId2");
+    anns[11].sequenceRef = seqs[3];
+    anns[11].visible = false;
+    anns[11].graph = AlignmentAnnotation.LINE_GRAPH;
+    anns[11].graphGroup = GROUP_3;
+    anns[11].label = "Label2";
+    anns[11].setCalcId("CalcId2");
   
     // annotations Label1 (hidden), Label5 (visible) in group 6 (visible)
     anns[1].sequenceRef = seqs[3];
@@ -248,9 +275,29 @@ public class AlignmentAnnotationUtilsTest
     anns[5].graph = AlignmentAnnotation.LINE_GRAPH;
     anns[5].graphGroup = GROUP_6;
     anns[5].setCalcId("CalcId1");
+    /*
+     * Annotations 0 and 4 are visible, for a different CalcId and graph group.
+     * They produce the same label as annotations 1 and 5, which should not be
+     * duplicated in the results. This case corresponds to (e.g.) many
+     * occurrences of an IUPred Short/Long annotation group, one per sequence.
+     */
+    anns[4].sequenceRef = seqs[0];
+    anns[4].visible = false;
+    anns[4].graph = AlignmentAnnotation.LINE_GRAPH;
+    anns[4].graphGroup = GROUP_4;
+    anns[4].label = "Label1";
+    anns[4].setCalcId("CalcId1");
+    anns[0].sequenceRef = seqs[0];
+    anns[0].visible = true;
+    anns[0].graph = AlignmentAnnotation.LINE_GRAPH;
+    anns[0].graphGroup = GROUP_4;
+    anns[0].label = "Label5";
+    anns[0].setCalcId("CalcId1");
   
-    // annotations outwith selection group - should be ignored
-    // hidden grouped annotations
+    /*
+     * Annotations outwith selection group - should be ignored.
+     */
+    // Hidden grouped annotations
     anns[6].sequenceRef = seqs[2];
     anns[6].visible = false;
     anns[6].graph = AlignmentAnnotation.LINE_GRAPH;
@@ -259,6 +306,7 @@ public class AlignmentAnnotationUtilsTest
     anns[8].visible = false;
     anns[8].graph = AlignmentAnnotation.LINE_GRAPH;
     anns[8].graphGroup = GROUP_4;
+
     // visible grouped annotations Label7, Label9
     anns[7].sequenceRef = seqs[2];
     anns[7].visible = true;
@@ -269,6 +317,11 @@ public class AlignmentAnnotationUtilsTest
     anns[9].graph = AlignmentAnnotation.LINE_GRAPH;
     anns[9].graphGroup = GROUP_4;
   
+    /*
+     * Generate annotations[] arrays to match aligned columns
+     */
+    // adjustForAlignment(anns);
+
     List<SequenceI> selected = selectSequences(0, 3);
     AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
             AlignmentAnnotationUtils.asList(anns),
@@ -276,13 +329,16 @@ public class AlignmentAnnotationUtilsTest
   
     consoleDebug(shownTypes, hiddenTypes);
   
-    // CalcId1 / Label1, Label5 (only) should be 'shown', as a compound type
+    // CalcId1 / Label1, Label5 (only) should be 'shown', once, as a compound
+    // type
+    assertEquals(1, shownTypes.size());
     assertEquals(1, shownTypes.get("CalcId1").size());
     assertEquals(2, shownTypes.get("CalcId1").get(0).size());
     assertEquals("Label1", shownTypes.get("CalcId1").get(0).get(0));
     assertEquals("Label5", shownTypes.get("CalcId1").get(0).get(1));
   
     // CalcId2 / Label2, Label3 (only) should be 'hidden'
+    assertEquals(1, hiddenTypes.size());
     assertEquals(1, hiddenTypes.get("CalcId2").size());
     assertEquals(2, hiddenTypes.get("CalcId2").get(0).size());
     assertEquals("Label2", hiddenTypes.get("CalcId2").get(0).get(0));