Merge branch 'Jalview-JS/develop' into merge_js_develop
[jalview.git] / src / jalview / analysis / AlignmentSorter.java
index af7db0a..f2b2222 100755 (executable)
@@ -113,6 +113,10 @@ public class AlignmentSorter implements ApplicationSingletonI
 
   private boolean sortLengthAscending;
 
+  private static boolean sortEValueAscending;
+
+  private static boolean sortBitScoreAscending;
+
   /**
    * Sorts sequences in the alignment by Percentage Identity with the given
    * reference sequence, sorting the highest identity to the top
@@ -196,6 +200,90 @@ public class AlignmentSorter implements ApplicationSingletonI
   }
 
   /**
+   * Sorts by sequence evalue. Currently moves all sequences without an evalue to
+   * the top of the alignment.
+   * 
+   * @param align
+   *                The alignment object to sort
+   */
+  public static void sortByEValue(AlignmentI align)
+  {
+    int nSeq = align.getHeight();
+
+    double[] evalue = new double[nSeq];
+    SequenceI[] seqs = new SequenceI[nSeq];
+
+    for (int i = 0; i < nSeq; i++)
+    {
+      seqs[i] = align.getSequenceAt(i);
+      AlignmentAnnotation[] ann = seqs[i].getAnnotation("Search Scores");
+      if (ann != null)
+      {
+        evalue[i] = ann[0].getEValue();
+      }
+      else
+      {
+        evalue[i] = -1;
+      }
+    }
+
+    QuickSort.sort(evalue, seqs);
+
+    if (sortEValueAscending)
+    {
+      setReverseOrder(align, seqs);
+    }
+    else
+    {
+      setOrder(align, seqs);
+    }
+
+    sortEValueAscending = !sortEValueAscending;
+  }
+
+  /**
+   * Sorts by sequence bit score. Currently moves all sequences without a bit
+   * score to the top of the alignment
+   * 
+   * @param align
+   *                The alignment object to sort
+   */
+  public static void sortByBitScore(AlignmentI align)
+  {
+    int nSeq = align.getHeight();
+
+    double[] score = new double[nSeq];
+    SequenceI[] seqs = new SequenceI[nSeq];
+
+    for (int i = 0; i < nSeq; i++)
+    {
+      seqs[i] = align.getSequenceAt(i);
+      AlignmentAnnotation[] ann = seqs[i].getAnnotation("Search Scores");
+      if (ann != null)
+      {
+        score[i] = ann[0].getEValue();
+      }
+      else
+      {
+        score[i] = -1;
+      }
+    }
+
+    QuickSort.sort(score, seqs);
+
+    if (sortBitScoreAscending)
+    {
+      setReverseOrder(align, seqs);
+    }
+    else
+    {
+      setOrder(align, seqs);
+    }
+
+    sortBitScoreAscending = !sortBitScoreAscending;
+  }
+
+  /**
    * Sorts the alignment by size of group. <br>
    * Maintains the order of sequences in each group by order in given alignment
    * object.