static NJTree lastTree = null;\r
static boolean sortTreeAscending = true;\r
\r
- private AlignmentSorter() {\r
- try {\r
- jbInit();\r
- } catch (Exception ex) {\r
- ex.printStackTrace();\r
- }\r
- }\r
-\r
- public static void sortGroups(AlignmentI align) {\r
- Vector groups = align.getGroups();\r
- int nGroup = groups.size();\r
-\r
- float[] arr = new float[nGroup];\r
- Object[] s = new Object[nGroup];\r
-\r
- for (int i = 0; i < nGroup; i++) {\r
- arr[i] = ((SequenceGroup) groups.elementAt(i)).getSize();\r
- s[i] = groups.elementAt(i);\r
- }\r
-\r
- QuickSort.sort(arr, s);\r
-\r
- // align..setGroups(newg);\r
- }\r
-\r
/**\r
* Sort by Percentage Identity\r
*\r
}\r
\r
private static void setOrder(AlignmentI align, SequenceI[] seqs) {\r
+\r
// NOTE: DO NOT USE align.setSequenceAt() here - it will NOT work\r
Vector algn = align.getSequences();\r
-\r
- for (int i = 0, p = 0; i < seqs.length; i++)\r
- algn.setElementAt(seqs[i], p++);\r
+ for (int i = 0; i < seqs.length; i++)\r
+ {\r
+ algn.setElementAt(seqs[i], i);\r
+ }\r
}\r
\r
public static void sortByID(AlignmentI align) {\r
}\r
\r
public static void sortByGroup(AlignmentI align) {\r
- Vector groups = align.getGroups();\r
+ //MAINTAINS ORIGNAL SEQUENCE ORDER,\r
+ //ORDERS BY GROUP SIZE\r
+\r
+ Vector groups = new Vector();\r
\r
if (groups.hashCode() != lastGroupHash) {\r
sortGroupAscending = true;\r
sortGroupAscending = !sortGroupAscending;\r
}\r
\r
- Vector seqs = new Vector();\r
+ //SORTS GROUPS BY SIZE\r
+ //////////////////////\r
+ for(int i=0; i<align.getGroups().size(); i++)\r
+ {\r
+ SequenceGroup sg = (SequenceGroup) align.getGroups().elementAt(i);\r
+\r
+ for(int j=0; j<groups.size(); j++)\r
+ {\r
+ SequenceGroup sg2 = (SequenceGroup) groups.elementAt(j);\r
+ if(sg.getSize() > sg2.getSize())\r
+ {\r
+ groups.insertElementAt(sg, j);\r
+ break;\r
+ }\r
+ }\r
+\r
+ if (!groups.contains(sg))\r
+ {\r
+ groups.addElement(sg);\r
+ }\r
+ }\r
\r
- for (int i = 0; i < groups.size(); i++) {\r
+ //NOW ADD SEQUENCES MAINTAINING ALIGNMENT ORDER\r
+ ///////////////////////////////////////////////\r
+ Vector seqs = new Vector();\r
+ for (int i = 0; i < groups.size(); i++)\r
+ {\r
SequenceGroup sg = (SequenceGroup) groups.elementAt(i);\r
-\r
- for (int j = 0; j < sg.getSize(); j++) {\r
- seqs.addElement(sg.getSequenceAt(j));\r
+ SequenceI [] orderedseqs = sg.getSequencesInOrder(align);\r
+ for (int j = 0; j < orderedseqs.length; j++)\r
+ {\r
+ seqs.addElement(orderedseqs[j]);\r
}\r
}\r
\r
- // Deletions can happen so this check may fail\r
-\r
- /*\r
- if (seqs.size() != nSeq) {\r
- System.err.println("ERROR: tmp.size() != nseq in sortByGroups");\r
- if (seqs.size() < nSeq) {\r
- addStrays(align,seqs);\r
- }\r
- }\r
- */\r
if (sortGroupAscending) {\r
setOrder(align, seqs);\r
} else {\r
}\r
\r
private static SequenceI[] vectorToArray(Vector tmp) {\r
+\r
SequenceI[] seqs = new SequenceI[tmp.size()];\r
\r
for (int i = 0; i < tmp.size(); i++) {\r
private static SequenceI[] vectorSubsetToArray(Vector tmp, Vector mask) {\r
Vector seqs = new Vector();\r
int i;\r
- int m;\r
- int p;\r
- boolean[] tmask = new boolean[m = mask.size()];\r
+ boolean[] tmask = new boolean[mask.size()];\r
\r
- for (i = 0; i < m; i++)\r
+ for (i = 0; i < mask.size(); i++)\r
tmask[i] = true;\r
\r
for (i = 0; i < tmp.size(); i++) {\r
- Object sq;\r
\r
- if (mask.contains(sq = tmp.elementAt(i))) {\r
+ Object sq = tmp.elementAt(i);\r
+\r
+ if (mask.contains(sq) && tmask[mask.indexOf(sq)])\r
+ {\r
tmask[mask.indexOf(sq)] = false;\r
seqs.addElement(sq);\r
- m--;\r
}\r
}\r
\r
// Get an ordered vector of sequences which may also be present in align\r
Vector tmp = order.getOrder();\r
\r
- // if (tmp.size()<align.getHeight())\r
- // addStrays(align, tmp);\r
if (lastOrder == order) {\r
sortOrderAscending = !sortOrderAscending;\r
} else {\r
\r
jalview.util.QuickSort.sort(ids, alignment);\r
}\r
-\r
- private void jbInit() throws Exception {\r
- }\r
}\r