+ * @param sortBy
+ * the sort order to apply
+ * @param autoCalcOnly
+ * if true, only autocalculated annotations are repositioned (to top
+ * or bottom), others are left in their current order
+ */
+ public void sort(SequenceAnnotationOrder sortBy, boolean autoCalcOnly)
+ {
+ if (sortBy == null || sortBy == SequenceAnnotationOrder.CUSTOM)
+ {
+ return;
+ }
+
+ this.autocalcOnly = autoCalcOnly;
+
+ /*
+ * cache 'alignment sequence positions' if required for sorting
+ */
+ if (sortBy == SequenceAnnotationOrder.SEQUENCE_AND_LABEL
+ || sortBy == SequenceAnnotationOrder.LABEL_AND_SEQUENCE)
+ {
+ saveSequenceIndices();
+ }
+
+ Comparator<? super AlignmentAnnotation> comparator = getComparator(
+ sortBy);
+
+ AlignmentAnnotation[] annotations = alignment.getAlignmentAnnotation();
+ synchronized (annotations)
+ {
+ Arrays.sort(annotations, comparator);
+ }
+ }
+
+ /**
+ * Calculates and saves in a temporary map the position of each annotation's
+ * associated sequence (if it has one) in the alignment. Faster to do this
+ * once than for every annotation comparison.