JAL-3081 sort annotations by order read from project after reloading
[jalview.git] / test / jalview / analysis / AnnotationSorterTest.java
index de57b1b..fa8af3d 100644 (file)
@@ -33,6 +33,8 @@ import jalview.datamodel.SequenceI;
 import jalview.gui.AlignViewport;
 import jalview.gui.JvOptionPane;
 
+import java.util.Arrays;
+import java.util.List;
 import java.util.Random;
 
 import org.testng.annotations.BeforeClass;
@@ -138,6 +140,7 @@ public class AnnotationSorterTest
     av.setShowAutocalculatedAbove(false);
     AnnotationSorter testee = new AnnotationSorter(av);
     testee.sort(SequenceAnnotationOrder.SEQUENCE_AND_LABEL, false);
+    anns = al.getAlignmentAnnotation();
     assertEquals("label5", anns[0].label); // for sequence 0
     assertEquals("label0", anns[1].label); // for sequence 1
     assertEquals("iron", anns[2].label); // sequence 3 /iron
@@ -169,6 +172,7 @@ public class AnnotationSorterTest
     av.setShowAutocalculatedAbove(true);
     AnnotationSorter testee = new AnnotationSorter(av);
     testee.sort(SequenceAnnotationOrder.SEQUENCE_AND_LABEL, false);
+    anns = al.getAlignmentAnnotation();
     assertEquals("Quality", anns[0].label); // autocalc annotations
     assertEquals("Consensus", anns[1].label); // retain ordering
     assertEquals("label5", anns[2].label); // for sequence 0
@@ -209,6 +213,7 @@ public class AnnotationSorterTest
     av.setShowAutocalculatedAbove(false);
     AnnotationSorter testee = new AnnotationSorter(av);
     testee.sort(SequenceAnnotationOrder.LABEL_AND_SEQUENCE, false);
+    anns = al.getAlignmentAnnotation();
     assertEquals("IRON", anns[0].label); // IRON / sequence 0
     assertEquals("iron", anns[1].label); // iron / sequence 3
     assertEquals("label0", anns[2].label); // label0 / sequence 1
@@ -240,6 +245,7 @@ public class AnnotationSorterTest
     av.setShowAutocalculatedAbove(true);
     AnnotationSorter testee = new AnnotationSorter(av);
     testee.sort(SequenceAnnotationOrder.LABEL_AND_SEQUENCE, false);
+    anns = al.getAlignmentAnnotation();
     assertEquals("Quality", anns[0].label); // autocalc annotations
     assertEquals("Consensus", anns[1].label); // retain ordering
     assertEquals("IRON", anns[2].label); // IRON / sequence 0
@@ -272,6 +278,7 @@ public class AnnotationSorterTest
     av.setShowAutocalculatedAbove(true);
     AnnotationSorter testee = new AnnotationSorter(av);
     testee.sort(SequenceAnnotationOrder.NONE, false);
+    anns = al.getAlignmentAnnotation();
     assertEquals("Quality", anns[0].label); // autocalc annotations
     assertEquals("Consensus", anns[1].label); // retain ordering
     assertEquals("label0", anns[2].label);
@@ -468,6 +475,7 @@ public class AnnotationSorterTest
     av.setShowAutocalculatedAbove(true);
     AnnotationSorter testee = new AnnotationSorter(av);
     testee.sort(SequenceAnnotationOrder.CUSTOM, false);
+    anns = al.getAlignmentAnnotation();
     assertEquals("label0", anns[0].label); // all unchanged
     assertEquals("structure", anns[1].label);
     assertEquals("iron", anns[2].label);
@@ -502,6 +510,7 @@ public class AnnotationSorterTest
     av.setShowAutocalculatedAbove(true);
     AnnotationSorter testee = new AnnotationSorter(av);
     testee.sort(SequenceAnnotationOrder.LABEL_AND_SEQUENCE, true);
+    anns = al.getAlignmentAnnotation();
     assertEquals("Quality", anns[0].label); // moved to top
     assertEquals("Consensus", anns[1].label); // moved to top
     assertEquals("label0", anns[2].label); // the rest unchanged
@@ -524,4 +533,42 @@ public class AnnotationSorterTest
     assertEquals("Quality", anns[5].label); // moved to bottom
     assertEquals("Consensus", anns[6].label); // moved to bottom
   }
+
+  /**
+   * Test sorting by annotation order
+   */
+  @Test(groups = { "Functional" })
+  public void testSortByAnnotation()
+  {
+    AlignmentI al = av.getAlignment();
+    AlignmentAnnotation[] anns = al.getAlignmentAnnotation();
+  
+    // @formatter:off
+    anns[0].sequenceRef = al.getSequenceAt(1); anns[0].label = "label0";
+    anns[1].sequenceRef = al.getSequenceAt(3); anns[1].label = "structure";
+    anns[2].sequenceRef = al.getSequenceAt(3); anns[2].label = "iron";
+    anns[3].autoCalculated = true;             anns[3].label = "Quality";
+    anns[4].autoCalculated = true;             anns[4].label = "Consensus";
+    anns[5].sequenceRef = al.getSequenceAt(0); anns[5].label = "label5";
+    anns[6].sequenceRef = al.getSequenceAt(3); anns[6].label = "IRP";
+    // @formatter:on
+  
+    av.setShowAutocalculatedAbove(false);
+    AnnotationSorter testee = new AnnotationSorter(av);
+    List<AlignmentAnnotation> reorder = Arrays.asList(anns[2], anns[6],
+            anns[3], anns[0], anns[5], anns[1], anns[4]);
+    testee.sort(reorder);
+
+    /*
+     * should now be ordered as specified by the list
+     */
+    anns = al.getAlignmentAnnotation();
+    assertEquals("iron", anns[0].label);
+    assertEquals("IRP", anns[1].label);
+    assertEquals("Quality", anns[2].label);
+    assertEquals("label0", anns[3].label);
+    assertEquals("label5", anns[4].label);
+    assertEquals("structure", anns[5].label);
+    assertEquals("Consensus", anns[6].label);
+  }
 }