sort by length
authorjprocter <Jim Procter>
Fri, 19 Dec 2008 15:33:08 +0000 (15:33 +0000)
committerjprocter <Jim Procter>
Fri, 19 Dec 2008 15:33:08 +0000 (15:33 +0000)
src/jalview/analysis/AlignmentSorter.java

index ab1e62d..9353aab 100755 (executable)
@@ -64,6 +64,8 @@ public class AlignmentSorter
    */
   private static String lastSortByFeatureScore;
 
+  private static boolean sortLengthAscending;
+
   /**
    * Sort by Percentage Identity w.r.t. s
    * 
@@ -202,6 +204,38 @@ public class AlignmentSorter
 
     sortIdAscending = !sortIdAscending;
   }
+  /**
+   * Sorts by sequence length
+   * 
+   * @param align
+   *                The alignment object to sort
+   */
+  public static void sortByLength(AlignmentI align)
+  {
+    int nSeq = align.getHeight();
+
+    float[] length = new float[nSeq];
+    SequenceI[] seqs = new SequenceI[nSeq];
+    
+    for (int i = 0; i < nSeq; i++)
+    {
+      seqs[i] = align.getSequenceAt(i);
+      length[i] = (float) (seqs[i].getEnd()-seqs[i].getStart());
+    }
+
+    QuickSort.sort(length, seqs);
+
+    if (sortLengthAscending)
+    {
+      setReverseOrder(align, seqs);
+    }
+    else
+    {
+      setOrder(align, seqs);
+    }
+
+    sortLengthAscending = !sortLengthAscending;
+  }
 
   /**
    * Sorts the alignment by size of group. <br>