From b0f76adef2787dd14566525e66a4073278e75d67 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 24 Mar 2017 09:30:47 +0000 Subject: [PATCH] JAL-838 move two callers off Comparison.PID and deprecate it --- src/jalview/analysis/AlignSeq.java | 6 +++- src/jalview/analysis/AlignmentSorter.java | 36 +++++++----------------- src/jalview/analysis/scoremodels/PIDModel.java | 2 +- src/jalview/appletgui/AlignFrame.java | 2 +- src/jalview/gui/AlignFrame.java | 2 +- src/jalview/util/Comparison.java | 8 ++++++ test/jalview/util/ComparisonTest.java | 5 ++-- 7 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/jalview/analysis/AlignSeq.java b/src/jalview/analysis/AlignSeq.java index ceca6d6..1a6826d 100755 --- a/src/jalview/analysis/AlignSeq.java +++ b/src/jalview/analysis/AlignSeq.java @@ -20,8 +20,10 @@ */ 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]) diff --git a/src/jalview/analysis/AlignmentSorter.java b/src/jalview/analysis/AlignmentSorter.java index a3810da..6c46a3e 100755 --- a/src/jalview/analysis/AlignmentSorter.java +++ b/src/jalview/analysis/AlignmentSorter.java @@ -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); } diff --git a/src/jalview/analysis/scoremodels/PIDModel.java b/src/jalview/analysis/scoremodels/PIDModel.java index 86d52b5..9500df4 100644 --- a/src/jalview/analysis/scoremodels/PIDModel.java +++ b/src/jalview/analysis/scoremodels/PIDModel.java @@ -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(); diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index b6a2430..9d19ec8 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -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())); diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 27fc34c..a222995 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -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); diff --git a/src/jalview/util/Comparison.java b/src/jalview/util/Comparison.java index 6c2fb4b..22e1ab7 100644 --- a/src/jalview/util/Comparison.java +++ b/src/jalview/util/Comparison.java @@ -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) { diff --git a/test/jalview/util/ComparisonTest.java b/test/jalview/util/ComparisonTest.java index ec1779b..6f6841d 100644 --- a/test/jalview/util/ComparisonTest.java +++ b/test/jalview/util/ComparisonTest.java @@ -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(); -- 1.7.10.2