JAL-838 move two callers off Comparison.PID and deprecate it
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 24 Mar 2017 09:30:47 +0000 (09:30 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 24 Mar 2017 09:30:47 +0000 (09:30 +0000)
src/jalview/analysis/AlignSeq.java
src/jalview/analysis/AlignmentSorter.java
src/jalview/analysis/scoremodels/PIDModel.java
src/jalview/appletgui/AlignFrame.java
src/jalview/gui/AlignFrame.java
src/jalview/util/Comparison.java
test/jalview/util/ComparisonTest.java

index ceca6d6..1a6826d 100755 (executable)
  */
 package jalview.analysis;
 
+import jalview.analysis.scoremodels.PIDModel;
 import jalview.analysis.scoremodels.ScoreMatrix;
 import jalview.analysis.scoremodels.ScoreModels;
+import jalview.analysis.scoremodels.SimilarityParams;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Mapping;
@@ -1059,6 +1061,8 @@ public class AlignSeq
 
     // long start = System.currentTimeMillis();
 
+    SimilarityParams pidParams = new SimilarityParams(true, true, true,
+            true);
     float pid;
     String seqi, seqj;
     for (int i = 0; i < height; i++)
@@ -1099,7 +1103,7 @@ public class AlignSeq
             seqj = ug;
           }
         }
-        pid = Comparison.PID(seqi, seqj);
+        pid = (float) PIDModel.computePID(seqi, seqj, pidParams);
 
         // use real sequence length rather than string length
         if (lngth[j] < lngth[i])
index a3810da..6c46a3e 100755 (executable)
@@ -20,6 +20,8 @@
  */
 package jalview.analysis;
 
+import jalview.analysis.scoremodels.PIDModel;
+import jalview.analysis.scoremodels.SimilarityParams;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AlignmentOrder;
@@ -27,7 +29,6 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.SequenceNode;
-import jalview.util.Comparison;
 import jalview.util.MessageManager;
 import jalview.util.QuickSort;
 
@@ -87,46 +88,29 @@ public class AlignmentSorter
   private static boolean sortLengthAscending;
 
   /**
-   * Sort by Percentage Identity w.r.t. s
+   * Sorts sequences in the alignment by Percentage Identity with the given
+   * reference sequence, sorting the highest identity to the top
    * 
    * @param align
    *          AlignmentI
    * @param s
    *          SequenceI
-   * @param tosort
-   *          sequences from align that are to be sorted.
-   */
-  public static void sortByPID(AlignmentI align, SequenceI s,
-          SequenceI[] tosort)
-  {
-    sortByPID(align, s, tosort, 0, -1);
-  }
-
-  /**
-   * Sort by Percentage Identity w.r.t. s
-   * 
-   * @param align
-   *          AlignmentI
-   * @param s
-   *          SequenceI
-   * @param tosort
-   *          sequences from align that are to be sorted.
-   * @param start
-   *          start column (0 for beginning
    * @param end
    */
-  public static void sortByPID(AlignmentI align, SequenceI s,
-          SequenceI[] tosort, int start, int end)
+  public static void sortByPID(AlignmentI align, SequenceI s)
   {
     int nSeq = align.getHeight();
 
     float[] scores = new float[nSeq];
     SequenceI[] seqs = new SequenceI[nSeq];
+    String refSeq = s.getSequenceAsString();
 
+    SimilarityParams pidParams = new SimilarityParams(true, true, true,
+            true);
     for (int i = 0; i < nSeq; i++)
     {
-      scores[i] = Comparison.PID(align.getSequenceAt(i)
-              .getSequenceAsString(), s.getSequenceAsString());
+      scores[i] = (float) PIDModel.computePID(align.getSequenceAt(i)
+              .getSequenceAsString(), refSeq, pidParams);
       seqs[i] = align.getSequenceAt(i);
     }
 
index 86d52b5..9500df4 100644 (file)
@@ -103,7 +103,7 @@ public class PIDModel implements SimilarityScoreModelI,
    * @param options
    * @return
    */
-  protected static double computePID(String seq1, String seq2,
+  public static double computePID(String seq1, String seq2,
           SimilarityParamsI options)
   {
     int len1 = seq1.length();
index b6a2430..9d19ec8 100644 (file)
@@ -2722,7 +2722,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   {
     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
     AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
-            .getAlignment().getSequenceAt(0), null);
+            .getAlignment().getSequenceAt(0));
 
     addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
             viewport.getAlignment()));
index 27fc34c..a222995 100644 (file)
@@ -3447,7 +3447,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   {
     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
     AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
-            .getAlignment().getSequenceAt(0), null);
+            .getAlignment().getSequenceAt(0));
     addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
             viewport.getAlignment()));
     alignPanel.paintAlignment(true);
index 6c2fb4b..22e1ab7 100644 (file)
@@ -135,7 +135,9 @@ public class Comparison
    * @param s2
    *          SequenceI
    * @return float
+   * @deprecated use PIDModel.computePID()
    */
+  @Deprecated
   public final static float PID(String seq1, String seq2)
   {
     return PID(seq1, seq2, 0, seq1.length());
@@ -144,6 +146,10 @@ public class Comparison
   static final int caseShift = 'a' - 'A';
 
   // Another pid with region specification
+  /**
+   * @deprecated use PIDModel.computePID()
+   */
+  @Deprecated
   public final static float PID(String seq1, String seq2, int start, int end)
   {
     return PID(seq1, seq2, start, end, true, false);
@@ -165,7 +171,9 @@ public class Comparison
    * @param ungappedOnly
    *          - if true - only count PID over ungapped columns
    * @return
+   * @deprecated use PIDModel.computePID()
    */
+  @Deprecated
   public final static float PID(String seq1, String seq2, int start,
           int end, boolean wcGaps, boolean ungappedOnly)
   {
index ec1779b..6f6841d 100644 (file)
@@ -115,7 +115,7 @@ public class ComparisonTest
   @Test(groups = { "Functional" })
   public void testPID_includingGaps()
   {
-    String seq1 = "ABCDEF";
+    String seq1 = "ABCDEFG"; // extra length here is ignored
     String seq2 = "abcdef";
     assertEquals("identical", 100f, Comparison.PID(seq1, seq2), 0.001f);
 
@@ -165,7 +165,8 @@ public class ComparisonTest
   public void testPID_ungappedOnly()
   {
     // 5 identical, 2 gap-gap, 2 gap-residue, 1 mismatch
-    String seq1 = "a--b-cdefh";
+    // the extra length of seq1 is ignored
+    String seq1 = "a--b-cdefhr";
     String seq2 = "a---bcdefg";
     int length = seq1.length();