// private singleton
}
- private static AlignmentSorter getInstance()
+ public static AlignmentSorter getInstance()
{
return (AlignmentSorter) ApplicationSingletonProvider
.getInstance(AlignmentSorter.class);
}
QuickSort.sort(scores, seqs);
-
setReverseOrder(align, seqs);
}
/**
- * Reverse the order of the sort
- *
- * @param align
- * DOCUMENT ME!
- * @param seqs
- * DOCUMENT ME!
- */
- private static void setReverseOrder(AlignmentI align, SequenceI[] seqs)
- {
- int nSeq = seqs.length;
-
- int len = 0;
-
- if ((nSeq % 2) == 0)
- {
- len = nSeq / 2;
- }
- else
- {
- len = (nSeq + 1) / 2;
- }
-
- // NOTE: DO NOT USE align.setSequenceAt() here - it will NOT work
- List<SequenceI> asq = align.getSequences();
- synchronized (asq)
- {
- for (int i = 0; i < len; i++)
- {
- // SequenceI tmp = seqs[i];
- asq.set(i, seqs[nSeq - i - 1]);
- asq.set(nSeq - i - 1, seqs[i]);
- }
- }
- }
-
- /**
- * Sets the Alignment object with the given sequences
- *
- * @param align
- * Alignment object to be updated
- * @param tmp
- * sequences as a vector
- */
- private static void setOrder(AlignmentI align, List<SequenceI> tmp)
- {
- setOrder(align, vectorSubsetToArray(tmp, align.getSequences()));
- }
-
- /**
- * Sets the Alignment object with the given sequences
- *
- * @param align
- * DOCUMENT ME!
- * @param seqs
- * sequences as an array
- */
- public static void setOrder(AlignmentI align, SequenceI[] seqs)
- {
- // NOTE: DO NOT USE align.setSequenceAt() here - it will NOT work
- List<SequenceI> algn = align.getSequences();
- synchronized (algn)
- {
- List<SequenceI> tmp = new ArrayList<>();
-
- for (int i = 0; i < seqs.length; i++)
- {
- if (algn.contains(seqs[i]))
- {
- tmp.add(seqs[i]);
- }
- }
-
- algn.clear();
- // User may have hidden seqs, then clicked undo or redo
- for (int i = 0; i < tmp.size(); i++)
- {
- algn.add(tmp.get(i));
- }
- }
- }
-
- /**
* Sorts by ID. Numbers are sorted before letters.
*
* @param align
}
QuickSort.sort(ids, seqs);
-
AlignmentSorter as = getInstance();
- if (as.sortIdAscending)
- {
- setReverseOrder(align, seqs);
- }
- else
- {
- setOrder(align, seqs);
- }
-
as.sortIdAscending = !as.sortIdAscending;
+ sort(align, seqs, as.sortIdAscending);
}
/**
}
QuickSort.sort(length, seqs);
-
AlignmentSorter as = getInstance();
-
- if (as.sortLengthAscending)
- {
- setReverseOrder(align, seqs);
- }
- else
- {
- setOrder(align, seqs);
- }
-
as.sortLengthAscending = !as.sortLengthAscending;
+ sort(align, seqs, as.sortLengthAscending);
}
/**
// NOW ADD SEQUENCES MAINTAINING ALIGNMENT ORDER
// /////////////////////////////////////////////
- List<SequenceI> seqs = new ArrayList<>();
+ List<SequenceI> tmp = new ArrayList<>();
for (int i = 0; i < groups.size(); i++)
{
for (int j = 0; j < orderedseqs.length; j++)
{
- seqs.add(orderedseqs[j]);
+ tmp.add(orderedseqs[j]);
}
}
-
- if (as.sortGroupAscending)
- {
- setOrder(align, seqs);
- }
- else
- {
- setReverseOrder(align,
- vectorSubsetToArray(seqs, align.getSequences()));
- }
+ sort(align, tmp, as.sortGroupAscending);
}
/**
{
as.sortOrderAscending = true;
}
-
- if (as.sortOrderAscending)
- {
- setOrder(align, tmp);
- }
- else
- {
- setReverseOrder(align,
- vectorSubsetToArray(tmp, align.getSequences()));
- }
+ sort(align, tmp, as.sortOrderAscending);
}
/**
{
as.sortTreeAscending = !as.sortTreeAscending;
}
-
- if (as.sortTreeAscending)
- {
- setOrder(align, tmp);
- }
- else
- {
- setReverseOrder(align,
- vectorSubsetToArray(tmp, align.getSequences()));
- }
+ sort(align, tmp, as.sortTreeAscending);
}
/**
for (int i = 0; i < alignment.length; i++)
{
- ids[i] = (new Float(alignment[i].getName().substring(8)))
+ ids[i] = (Float.valueOf(alignment[i].getName().substring(8)))
.floatValue();
}
as.sortByFeatureCriteria = scoreCriteria;
}
+ private static void sort(AlignmentI align, List<SequenceI> tmp,
+ boolean ascending)
+ {
+ sort(align, vectorSubsetToArray(tmp, align.getSequences()), ascending);
+ }
+
+ private static void sort(AlignmentI align, SequenceI[] seqs,
+ boolean ascending)
+ {
+ if (ascending)
+ {
+ setOrder(align, seqs);
+ }
+ else
+ {
+ setReverseOrder(align, seqs);
+ }
+
+ }
+
+
+ /**
+ * Sets the Alignment object with the given sequences
+ *
+ * @param align
+ * DOCUMENT ME!
+ * @param seqs
+ * sequences as an array
+ */
+ public static void setOrder(AlignmentI align, SequenceI[] seqs)
+ {
+ // NOTE: DO NOT USE align.setSequenceAt() here - it will NOT work
+ List<SequenceI> algn = align.getSequences();
+ synchronized (algn)
+ {
+ List<SequenceI> tmp = new ArrayList<>();
+
+ for (int i = 0; i < seqs.length; i++)
+ {
+ if (algn.contains(seqs[i]))
+ {
+ tmp.add(seqs[i]);
+ }
+ }
+
+ algn.clear();
+ // User may have hidden seqs, then clicked undo or redo
+ for (int i = 0; i < tmp.size(); i++)
+ {
+ algn.add(tmp.get(i));
+ }
+ }
+ }
+
+ /**
+ * Reverse the order of the sort
+ *
+ * @param align
+ * DOCUMENT ME!
+ * @param seqs
+ * DOCUMENT ME!
+ */
+ private static void setReverseOrder(AlignmentI align, SequenceI[] seqs)
+ {
+ int nSeq = seqs.length;
+
+ int len = (nSeq + (nSeq % 2)) / 2;
+// int len = 0;
+//
+// if ((nSeq % 2) == 0)
+// {
+// len = nSeq / 2;
+// }
+// else
+// {
+// len = (nSeq + 1) / 2;
+// }
+
+ // NOTE: DO NOT USE align.setSequenceAt() here - it will NOT work
+ List<SequenceI> asq = align.getSequences();
+ synchronized (asq)
+ {
+ for (int i = 0; i < len; i++)
+ {
+ // SequenceI tmp = seqs[i];
+ asq.set(i, seqs[nSeq - i - 1]);
+ asq.set(nSeq - i - 1, seqs[i]);
+ }
+ }
+ }
+
+
}