From: gmungoc Date: Wed, 12 Apr 2017 13:41:45 +0000 (+0100) Subject: JAL-2403 public static methods to convert distance/similarity matrices X-Git-Tag: Release_2_10_2~3^2~105^2~2^2~21 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=a581eb571426fb19c6b3421eebaedd90c63bb630;p=jalview.git JAL-2403 public static methods to convert distance/similarity matrices --- diff --git a/src/jalview/analysis/scoremodels/DistanceScoreModel.java b/src/jalview/analysis/scoremodels/DistanceScoreModel.java index 14c9667..0dd7617 100644 --- a/src/jalview/analysis/scoremodels/DistanceScoreModel.java +++ b/src/jalview/analysis/scoremodels/DistanceScoreModel.java @@ -15,14 +15,26 @@ public abstract class DistanceScoreModel implements ScoreModelI public MatrixI findSimilarities(AlignmentView seqData, SimilarityParamsI options) { - MatrixI result = findDistances(seqData, options); + MatrixI distances = findDistances(seqData, options); - /* - * reverse the range of score values so that - * max becomes min and vice versa - */ - result.reverseRange(false); + MatrixI similarities = distanceToSimilarity(distances); - return result; + return similarities; + } + + /** + * Converts distance scores to similarity scores, by reversing the range of + * score values so that max becomes min and vice versa. The input matrix is + * not modified. + * + * @param distances + */ + public static MatrixI distanceToSimilarity(MatrixI distances) + { + MatrixI similarities = distances.copy(); + + similarities.reverseRange(false); + + return similarities; } } diff --git a/src/jalview/analysis/scoremodels/SimilarityScoreModel.java b/src/jalview/analysis/scoremodels/SimilarityScoreModel.java index d41e0ba..dae1f62 100644 --- a/src/jalview/analysis/scoremodels/SimilarityScoreModel.java +++ b/src/jalview/analysis/scoremodels/SimilarityScoreModel.java @@ -17,14 +17,27 @@ public abstract class SimilarityScoreModel implements ScoreModelI public MatrixI findDistances(AlignmentView seqData, SimilarityParamsI options) { - MatrixI result = findSimilarities(seqData, options); + MatrixI similarities = findSimilarities(seqData, options); - /* - * reverse the range of the scores mapping the maximum to zero - */ - result.reverseRange(true); + MatrixI distances = similarityToDistance(similarities); - return result; + return distances; + } + + /** + * Converts a matrix of similarity scores to distance scores, by reversing the + * range of the scores, mapping the maximum to zero. The input matrix is not + * modified. + * + * @param similarities + */ + public static MatrixI similarityToDistance(MatrixI similarities) + { + MatrixI distances = similarities.copy(); + + distances.reverseRange(true); + + return distances; } }