JAL-2403 ScoreModelI now DistanceModelI, ScoreMatrix delegate of
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 20 Feb 2017 16:07:45 +0000 (16:07 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 20 Feb 2017 16:07:45 +0000 (16:07 +0000)
PairwiseDistanceModel

23 files changed:
resources/scoreModel/dna.scm
src/jalview/analysis/NJTree.java
src/jalview/analysis/PCA.java
src/jalview/analysis/scoremodels/FeatureDistanceModel.java [moved from src/jalview/analysis/scoremodels/FeatureScoreModel.java with 97% similarity]
src/jalview/analysis/scoremodels/PIDDistanceModel.java [moved from src/jalview/analysis/scoremodels/PIDScoreModel.java with 92% similarity]
src/jalview/analysis/scoremodels/PairwiseDistanceModel.java [moved from src/jalview/analysis/scoremodels/PairwiseSeqScoreModel.java with 59% similarity]
src/jalview/analysis/scoremodels/PairwiseScoreModelI.java [new file with mode: 0644]
src/jalview/analysis/scoremodels/SWDistanceModel.java [moved from src/jalview/analysis/scoremodels/SWScoreModel.java with 91% similarity]
src/jalview/analysis/scoremodels/ScoreMatrix.java
src/jalview/analysis/scoremodels/ScoreModels.java
src/jalview/api/analysis/DistanceModelI.java [moved from src/jalview/api/analysis/ScoreModelI.java with 89% similarity]
src/jalview/appletgui/TreePanel.java
src/jalview/datamodel/BinarySequence.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/PCAPanel.java
src/jalview/gui/TreeChooser.java
src/jalview/gui/TreePanel.java
src/jalview/schemes/Blosum62ColourScheme.java
src/jalview/ws/sifts/SiftsClient.java
test/jalview/analysis/scoremodels/FeatureDistanceModelTest.java [moved from test/jalview/analysis/scoremodels/FeatureScoreModelTest.java with 97% similarity]
test/jalview/analysis/scoremodels/ScoreMatrixTest.java
test/jalview/analysis/scoremodels/ScoreModelsTest.java
test/jalview/schemes/ScoreMatrixPrinter.java

index b1e0621..4a196fb 100644 (file)
@@ -18,7 +18,7 @@ ACGTUIXRYN -
 # Comment line with symbols is provided as a guide
 # Values may be integer or floating point, delimited by tab, space, comma or combinations
 #
-#      A       C       G       T       U       I       X       R       Y       N       -
+#      A       C       G       T       U       I       X       R       Y       N               -
 #
        10      -8      -8      -8      -8      1       1       1       -8      1       1       1 
        -8      10      -8      -8      -8      1       1       -8      1       1       1       1
@@ -33,4 +33,4 @@ ACGTUIXRYN -
        1       1       1       1       1       1       1       1       1       1       1       1
        1       1       1       1       1       1       1       1       1       1       1       1
 #
-#      A       C       G       T       U       I       X       R       Y       N       -
+#      A       C       G       T       U       I       X       R       Y       N               -
index 542f15e..7140867 100644 (file)
@@ -21,7 +21,7 @@
 package jalview.analysis;
 
 import jalview.analysis.scoremodels.ScoreModels;
-import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.DistanceModelI;
 import jalview.datamodel.AlignmentView;
 import jalview.datamodel.BinaryNode;
 import jalview.datamodel.CigarArray;
@@ -224,7 +224,7 @@ public class NJTree
    *          DOCUMENT ME!
    */
   public NJTree(SequenceI[] sequence, AlignmentView seqData, String type,
-          String pwtype, ScoreModelI sm, int start, int end)
+          String pwtype, DistanceModelI sm, int start, int end)
   {
     this.sequence = sequence;
     this.node = new Vector<SequenceNode>();
@@ -736,7 +736,7 @@ public class NJTree
    * 
    * @return similarity matrix used to compute tree
    */
-  public float[][] findDistances(ScoreModelI _pwmatrix)
+  public float[][] findDistances(DistanceModelI _pwmatrix)
   {
 
     float[][] dist = new float[noseqs][noseqs];
index 87ec922..ae83400 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.analysis;
 
+import jalview.analysis.scoremodels.PairwiseDistanceModel;
 import jalview.analysis.scoremodels.ScoreMatrix;
 import jalview.analysis.scoremodels.ScoreModels;
 import jalview.datamodel.BinarySequence;
@@ -94,14 +95,15 @@ public class PCA implements Runnable
     String sm = s_m;
     if (sm != null)
     {
-      smtrx = (ScoreMatrix) ScoreModels.getInstance().forName(sm);
+      smtrx = (ScoreMatrix) ((PairwiseDistanceModel) ScoreModels
+              .getInstance()
+              .forName(sm)).getScoreModel();
     }
     if (smtrx == null)
     {
       // either we were given a non-existent score matrix or a scoremodel that
       // isn't based on a pairwise symbol score matrix
-      smtrx = (ScoreMatrix) ScoreModels.getInstance().forName(
-              sm = (nucleotides ? "DNA" : "BLOSUM62"));
+      smtrx = ScoreModels.getInstance().getDefaultModel(!nucleotides);
     }
     details.append("PCA calculation using " + sm
             + " sequence similarity matrix\n========\n\n");
@@ -20,7 +20,7 @@
  */
 package jalview.analysis.scoremodels;
 
-import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.DistanceModelI;
 import jalview.api.analysis.ViewBasedAnalysisI;
 import jalview.datamodel.AlignmentView;
 import jalview.datamodel.SeqCigar;
@@ -33,7 +33,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-public class FeatureScoreModel implements ScoreModelI, ViewBasedAnalysisI
+public class FeatureDistanceModel implements DistanceModelI, ViewBasedAnalysisI
 {
   jalview.api.FeatureRenderer fr;
 
  */
 package jalview.analysis.scoremodels;
 
-import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.DistanceModelI;
 import jalview.datamodel.AlignmentView;
 import jalview.util.Comparison;
 
-public class PIDScoreModel implements ScoreModelI
+public class PIDDistanceModel implements DistanceModelI
 {
 
   @Override
   public float[][] findDistances(AlignmentView seqData)
   {
     String[] sequenceString = seqData
-            .getSequenceStrings(Comparison.GapChars.charAt(0));
+            .getSequenceStrings(Comparison.GAP_SPACE);
     int noseqs = sequenceString.length;
     float[][] distance = new float[noseqs][noseqs];
     for (int i = 0; i < (noseqs - 1); i++)
  */
 package jalview.analysis.scoremodels;
 
-import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.DistanceModelI;
 import jalview.datamodel.AlignmentView;
 import jalview.util.Comparison;
 
-public abstract class PairwiseSeqScoreModel implements ScoreModelI
+public class PairwiseDistanceModel implements DistanceModelI
 {
-  abstract public float getPairwiseScore(char c, char d);
+  PairwiseScoreModelI scoreModel;
 
+  /**
+   * Constructor given something to provide pairwise scores for residues
+   * 
+   * @param sm
+   */
+  public PairwiseDistanceModel(PairwiseScoreModelI sm)
+  {
+    scoreModel = sm;
+  }
+
+  /**
+   * Returns a matrix of [i][j] values representing distances between pairs of
+   * sequences
+   */
   @Override
   public float[][] findDistances(AlignmentView seqData)
   {
     String[] sequenceString = seqData
-            .getSequenceStrings(Comparison.GapChars.charAt(0));
+            .getSequenceStrings(Comparison.GAP_SPACE);
     int noseqs = sequenceString.length;
     float[][] distance = new float[noseqs][noseqs];
 
+    /*
+     * calculate similarity scores for the upper half of the matrix
+     * as [i, j] = the sum of pairwise scores of corresponding
+     * positions of sequence[i] and sequence[j]
+     */
     float maxscore = 0;
     int end = sequenceString[0].length();
     for (int i = 0; i < (noseqs - 1); i++)
@@ -48,7 +67,8 @@ public abstract class PairwiseSeqScoreModel implements ScoreModelI
         {
           try
           {
-            score += getPairwiseScore(sequenceString[i].charAt(k),
+            score += scoreModel.getPairwiseScore(
+                    sequenceString[i].charAt(k),
                     sequenceString[j].charAt(k));
           } catch (Exception ex)
           {
@@ -66,6 +86,12 @@ public abstract class PairwiseSeqScoreModel implements ScoreModelI
       }
     }
 
+    /*
+     * subtract similarity scores from the maximum value to
+     * convert to a distance measure; also populate the lower
+     * half of the result matrix with this value 
+     */
+    // FIXME this assumes the score matrix is symmetric - it may not be?
     for (int i = 0; i < (noseqs - 1); i++)
     {
       for (int j = i; j < noseqs; j++)
@@ -77,5 +103,26 @@ public abstract class PairwiseSeqScoreModel implements ScoreModelI
     return distance;
   }
 
-  abstract public float[][] getMatrix();
+  @Override
+  public String getName()
+  {
+    return scoreModel.getName();
+  }
+
+  @Override
+  public boolean isDNA()
+  {
+    return scoreModel.isDNA();
+  }
+
+  @Override
+  public boolean isProtein()
+  {
+    return scoreModel.isProtein();
+  }
+
+  public PairwiseScoreModelI getScoreModel()
+  {
+    return scoreModel;
+  }
 }
diff --git a/src/jalview/analysis/scoremodels/PairwiseScoreModelI.java b/src/jalview/analysis/scoremodels/PairwiseScoreModelI.java
new file mode 100644 (file)
index 0000000..8acedf0
--- /dev/null
@@ -0,0 +1,42 @@
+package jalview.analysis.scoremodels;
+
+/**
+ * An interface that describes classes that can compute similarity (aka
+ * substitution) scores for pairs of residues
+ */
+public interface PairwiseScoreModelI
+{
+  /**
+   * Answers a similarity score between two sequence characters (for
+   * substitution of the first by the second). Typically the highest scores are
+   * for identity, and the lowest for substitution of a residue by one with very
+   * different properties.
+   * 
+   * @param c
+   * @param d
+   * @return
+   */
+  abstract public float getPairwiseScore(char c, char d);
+
+  /**
+   * Returns a readable name for the model, suitable for display in menus
+   * 
+   * @return
+   */
+  String getName();
+
+  /**
+   * Answers true if the model is applicable to nucleotide data
+   * 
+   * @return
+   */
+  boolean isDNA();
+
+  /**
+   * Answers true if the model is applicable to peptide data
+   * 
+   * @return
+   */
+  boolean isProtein();
+
+}
 package jalview.analysis.scoremodels;
 
 import jalview.analysis.AlignSeq;
-import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.DistanceModelI;
 import jalview.datamodel.AlignmentView;
 import jalview.datamodel.SequenceI;
 import jalview.util.Comparison;
 
-public class SWScoreModel implements ScoreModelI
+public class SWDistanceModel implements DistanceModelI
 {
 
   @Override
   public float[][] findDistances(AlignmentView seqData)
   {
     SequenceI[] sequenceString = seqData.getVisibleAlignment(
-            Comparison.GapChars.charAt(0)).getSequencesArray();
+            Comparison.GAP_SPACE).getSequencesArray();
     int noseqs = sequenceString.length;
     float[][] distance = new float[noseqs][noseqs];
 
@@ -48,7 +48,7 @@ public class SWScoreModel implements ScoreModelI
         as.calcScoreMatrix();
         as.traceAlignment();
         as.printAlignment(System.out);
-        distance[i][j] = (float) as.maxscore;
+        distance[i][j] = as.maxscore;
 
         if (max < distance[i][j])
         {
@@ -87,6 +87,7 @@ public class SWScoreModel implements ScoreModelI
     return true;
   }
 
+  @Override
   public String toString()
   {
     return "Score between two sequences aligned with Smith Waterman with default Peptide/Nucleotide matrix";
index baa18e9..51d8276 100644 (file)
@@ -22,7 +22,7 @@ package jalview.analysis.scoremodels;
 
 import java.util.Arrays;
 
-public class ScoreMatrix extends PairwiseSeqScoreModel
+public class ScoreMatrix implements PairwiseScoreModelI
 {
   public static final short UNMAPPED = (short) -1;
 
@@ -141,25 +141,53 @@ public class ScoreMatrix extends PairwiseSeqScoreModel
     return peptide;
   }
 
-  @Override
+  /**
+   * Returns the score matrix as used in getPairwiseScore. If using this matrix
+   * directly, callers <em>must</em> also call <code>getMatrixIndex</code> in
+   * order to get the matrix index for each character (symbol).
+   * 
+   * @return
+   * @see #getMatrixIndex(char)
+   */
   public float[][] getMatrix()
   {
     return matrix;
   }
 
   /**
+   * Answers the matrix index for a given character, or -1 if unmapped in the
+   * matrix. Use this method only if using <code>getMatrix</code> in order to
+   * compute scores directly (without symbol lookup) for efficiency.
+   * 
+   * @param c
+   * @return
+   * @see #getMatrix()
+   */
+  public int getMatrixIndex(char c)
+  {
+    if (c < symbolIndex.length)
+    {
+      return symbolIndex[c];
+    }
+    else
+    {
+      return UNMAPPED;
+    }
+  }
+
+  /**
    * Returns the pairwise score for substituting c with d, or zero if c or d is
    * an unscored or unexpected character
    */
   @Override
   public float getPairwiseScore(char c, char d)
   {
-    if (c > MAX_ASCII)
+    if (c >= symbolIndex.length)
     {
       System.err.println(String.format(BAD_ASCII_ERROR, c));
       return 0;
     }
-    if (d > MAX_ASCII)
+    if (d >= symbolIndex.length)
     {
       System.err.println(String.format(BAD_ASCII_ERROR, d));
       return 0;
index 2419997..043e6fb 100644 (file)
@@ -1,6 +1,6 @@
 package jalview.analysis.scoremodels;
 
-import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.DistanceModelI;
 import jalview.io.DataSourceType;
 import jalview.io.FileParse;
 import jalview.io.ScoreMatrixFile;
@@ -18,9 +18,11 @@ public class ScoreModels
 
   private final ScoreMatrix PAM250;
 
+  private final ScoreMatrix DNA;
+
   private static ScoreModels instance = new ScoreModels();
 
-  private Map<String, ScoreModelI> models;
+  private Map<String, DistanceModelI> models;
 
   public static ScoreModels getInstance()
   {
@@ -44,13 +46,15 @@ public class ScoreModels
     /*
      * using LinkedHashMap keeps models ordered as added
      */
-    models = new LinkedHashMap<String, ScoreModelI>();
+    models = new LinkedHashMap<String, DistanceModelI>();
     BLOSUM62 = loadScoreMatrix("scoreModel/blosum62.scm");
     PAM250 = loadScoreMatrix("scoreModel/pam250.scm");
-    loadScoreMatrix("scoreModel/dna.scm");
     loadScoreMatrix("scoreModel/seqspace.scm");
-    registerScoreModel(new FeatureScoreModel());
-    registerScoreModel(new PIDScoreModel());
+    // drop seqspace.scm for IdentityScoreModel once JAL-2379 merged in?
+    // registerScoreModel(new IdentityScoreModel());
+    DNA = loadScoreMatrix("scoreModel/dna.scm");
+    registerScoreModel(new FeatureDistanceModel());
+    registerScoreModel(new PIDDistanceModel());
   }
 
   /**
@@ -80,24 +84,34 @@ public class ScoreModels
   }
 
   /**
+   * Registers a pairwise score model
+   * 
+   * @param sm
+   */
+  public void registerScoreModel(PairwiseScoreModelI sm)
+  {
+    registerScoreModel(new PairwiseDistanceModel(sm));
+  }
+
+  /**
    * Answers an iterable set of the registered score models. Currently these are
    * returned in the order in which they were registered.
    * 
    * @return
    */
-  public Iterable<ScoreModelI> getModels()
+  public Iterable<DistanceModelI> getModels()
   {
     return models.values();
   }
 
-  public ScoreModelI forName(String s)
+  public DistanceModelI forName(String s)
   {
     return models.get(s);
   }
 
-  public void registerScoreModel(ScoreModelI sm)
+  public void registerScoreModel(DistanceModelI sm)
   {
-    ScoreModelI sm2 = models.get(sm.getName());
+    DistanceModelI sm2 = models.get(sm.getName());
     if (sm2 != null)
     {
       System.err.println("Warning: replacing score model " + sm2.getName());
@@ -112,10 +126,9 @@ public class ScoreModels
    * @param forPeptide
    * @return
    */
-  public PairwiseSeqScoreModel getDefaultModel(boolean forPeptide)
+  public ScoreMatrix getDefaultModel(boolean forPeptide)
   {
-    return (PairwiseSeqScoreModel) (forPeptide ? forName("BLOSUM62")
-            : forName("DNA"));
+    return forPeptide ? BLOSUM62 : DNA;
   }
 
   public ScoreMatrix getBlosum62()
similarity index 89%
rename from src/jalview/api/analysis/ScoreModelI.java
rename to src/jalview/api/analysis/DistanceModelI.java
index 332bba5..3ceeed2 100644 (file)
@@ -22,7 +22,11 @@ package jalview.api.analysis;
 
 import jalview.datamodel.AlignmentView;
 
-public interface ScoreModelI
+/**
+ * An interface that describes classes that can compute distances between pairs
+ * of sequences in an alignment
+ */
+public interface DistanceModelI
 {
 
   float[][] findDistances(AlignmentView seqData);
index d3e6213..9ac6773 100644 (file)
@@ -22,7 +22,7 @@ package jalview.appletgui;
 
 import jalview.analysis.NJTree;
 import jalview.analysis.scoremodels.ScoreModels;
-import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.DistanceModelI;
 import jalview.api.analysis.ViewBasedAnalysisI;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentView;
@@ -237,7 +237,7 @@ public class TreePanel extends EmbmenuFrame implements ActionListener,
           seqs = av.getSelectionGroup().getSequencesInOrder(
                   av.getAlignment());
         }
-        ScoreModelI sm = ScoreModels.getInstance().forName(pwtype);
+        DistanceModelI sm = ScoreModels.getInstance().forName(pwtype);
         if (sm instanceof ViewBasedAnalysisI)
         {
           try
index 90b8be7..da41c44 100755 (executable)
@@ -116,20 +116,20 @@ public class BinarySequence extends Sequence
   /**
    * ancode using substitution matrix given in matrix
    * 
-   * @param matrix
+   * @param smtrx
    */
-  public void matrixEncode(final ScoreMatrix matrix)
+  public void matrixEncode(final ScoreMatrix smtrx)
           throws InvalidSequenceTypeException
   {
-    if (isNa != matrix.isDNA())
+    if (isNa != smtrx.isDNA())
     {
       throw new InvalidSequenceTypeException("matrix "
-              + matrix.getClass().getCanonicalName()
+              + smtrx.getClass().getCanonicalName()
               + " is not a valid matrix for "
               + (isNa ? "nucleotide" : "protein") + "sequences");
     }
-    matrixEncode(matrix.isDNA() ? ResidueProperties.nucleotideIndex
-            : ResidueProperties.aaIndex, matrix.getMatrix());
+    matrixEncode(smtrx.isDNA() ? ResidueProperties.nucleotideIndex
+            : ResidueProperties.aaIndex, smtrx.getMatrix());
   }
 
   private void matrixEncode(final int[] aaIndex, final float[][] matrix)
index 1162c53..5f0e5d3 100644 (file)
@@ -35,7 +35,7 @@ import jalview.api.AlignmentViewPanel;
 import jalview.api.FeatureSettingsControllerI;
 import jalview.api.SplitContainerI;
 import jalview.api.ViewStyleI;
-import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.DistanceModelI;
 import jalview.bin.Cache;
 import jalview.bin.Jalview;
 import jalview.commands.CommandI;
@@ -5638,7 +5638,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     ColourMenuHelper.setColourSelected(colourMenu, schemeName);
   }
 
-  public void newTreePanel(String treeType, ScoreModelI sm)
+  public void newTreePanel(String treeType, DistanceModelI sm)
   {
     String scoreModelName = sm.getName();
     final String ttl = TreePanel.getPanelTitle(treeType, scoreModelName);
index f96d464..d053468 100644 (file)
@@ -20,9 +20,9 @@
  */
 package jalview.gui;
 
-import jalview.analysis.scoremodels.ScoreMatrix;
+import jalview.analysis.scoremodels.PairwiseDistanceModel;
 import jalview.analysis.scoremodels.ScoreModels;
-import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.DistanceModelI;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AlignmentView;
@@ -157,9 +157,9 @@ public class PCAPanel extends GPCAPanel implements Runnable,
   protected void scoreMatrix_menuSelected()
   {
     scoreMatrixMenu.removeAll();
-    for (ScoreModelI sm : ScoreModels.getInstance().getModels())
+    for (DistanceModelI sm : ScoreModels.getInstance().getModels())
     {
-      if (sm instanceof ScoreMatrix)
+      if (sm instanceof PairwiseDistanceModel)
       {
         final String name = sm.getName();
         // create an entry for this score matrix for use in PCA
@@ -167,8 +167,8 @@ public class PCAPanel extends GPCAPanel implements Runnable,
         jm.setText(MessageManager.getStringOrReturn("label.score_model_",
                 name));
         jm.setSelected(pcaModel.getScore_matrix().equals(name));
-        if ((!pcaModel.isNucleotide() && !sm.isDNA())
-                || (pcaModel.isNucleotide() && sm.isDNA()))
+        if ((pcaModel.isNucleotide() && sm.isDNA())
+                || (!pcaModel.isNucleotide() && sm.isProtein()))
         {
           jm.addActionListener(new ActionListener()
           {
index 8e2bff0..55e6650 100644 (file)
@@ -22,7 +22,7 @@ package jalview.gui;
 
 import jalview.analysis.NJTree;
 import jalview.analysis.scoremodels.ScoreModels;
-import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.DistanceModelI;
 import jalview.util.MessageManager;
 
 import java.awt.Color;
@@ -86,7 +86,7 @@ public class TreeChooser extends JPanel
 
     matrixNames = new JComboBox<String>();
     ScoreModels scoreModels = ScoreModels.getInstance();
-    for (ScoreModelI sm : scoreModels.getModels())
+    for (DistanceModelI sm : scoreModels.getModels())
     {
       boolean nucleotide = af.getViewport().getAlignment().isNucleotide();
       if (sm.isDNA() && nucleotide || sm.isProtein() && !nucleotide)
@@ -151,7 +151,7 @@ public class TreeChooser extends JPanel
       frame.setClosed(true);
       String treeType = neighbourJoining.isSelected() ? NJTree.NEIGHBOUR_JOINING
               : NJTree.AVERAGE_DISTANCE;
-      ScoreModelI sm = ScoreModels.getInstance().forName(
+      DistanceModelI sm = ScoreModels.getInstance().forName(
               matrixNames.getSelectedItem().toString());
       af.newTreePanel(treeType, sm);
     } catch (Exception ex)
index 7df1f71..13e2360 100755 (executable)
@@ -23,7 +23,7 @@ package jalview.gui;
 import jalview.analysis.AlignmentSorter;
 import jalview.analysis.NJTree;
 import jalview.analysis.scoremodels.ScoreModels;
-import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.DistanceModelI;
 import jalview.api.analysis.ViewBasedAnalysisI;
 import jalview.bin.Cache;
 import jalview.commands.CommandI;
@@ -300,7 +300,7 @@ public class TreePanel extends GTreePanel
           seqs = av.getSelectionGroup().getSequencesInOrder(
                   av.getAlignment());
         }
-        ScoreModelI sm = ScoreModels.getInstance().forName(pwtype);
+        DistanceModelI sm = ScoreModels.getInstance().forName(pwtype);
         if (sm instanceof ViewBasedAnalysisI)
         {
           try
index 58e12b7..8ac8731 100755 (executable)
@@ -20,7 +20,7 @@
  */
 package jalview.schemes;
 
-import jalview.analysis.scoremodels.PairwiseSeqScoreModel;
+import jalview.analysis.scoremodels.PairwiseScoreModelI;
 import jalview.analysis.scoremodels.ScoreModels;
 import jalview.datamodel.AnnotatedCollectionI;
 import jalview.datamodel.SequenceCollectionI;
@@ -55,7 +55,7 @@ public class Blosum62ColourScheme extends ResidueColourScheme
   public Color findColour(char res, int j, SequenceI seq,
           String consensusResidue, float pid)
   {
-    PairwiseSeqScoreModel sm = ScoreModels.getInstance().getBlosum62();
+    PairwiseScoreModelI sm = ScoreModels.getInstance().getBlosum62();
 
     /*
      * compare as upper case; note consensusResidue is 
@@ -84,7 +84,6 @@ public class Blosum62ColourScheme extends ResidueColourScheme
       for (char consensus : consensusResidue.toCharArray())
       {
         score += sm.getPairwiseScore(consensus, res);
-        // score += ResidueProperties.getBLOSUM62(consensus, res);
       }
 
       if (score > 0)
index a066915..df5aee9 100644 (file)
@@ -21,7 +21,7 @@
 package jalview.ws.sifts;
 
 import jalview.analysis.AlignSeq;
-import jalview.analysis.scoremodels.PairwiseSeqScoreModel;
+import jalview.analysis.scoremodels.ScoreMatrix;
 import jalview.analysis.scoremodels.ScoreModels;
 import jalview.api.DBRefEntryI;
 import jalview.api.SiftsClientI;
@@ -988,7 +988,7 @@ public class SiftsClient implements SiftsClientI
     output.append(String.valueOf(pdbEnd));
     output.append(NEWLINE).append(NEWLINE);
 
-    PairwiseSeqScoreModel pam250 = ScoreModels.getInstance().getPam250();
+    ScoreMatrix pam250 = ScoreModels.getInstance().getPam250();
     int matchedSeqCount = 0;
     for (int j = 0; j < nochunks; j++)
     {
@@ -36,7 +36,7 @@ import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-public class FeatureScoreModelTest
+public class FeatureDistanceModelTest
 {
 
   @BeforeClass(alwaysRun = true)
@@ -106,7 +106,7 @@ public class FeatureScoreModelTest
   public void testFeatureScoreModel() throws Exception
   {
     AlignFrame alf = getTestAlignmentFrame();
-    FeatureScoreModel fsm = new FeatureScoreModel();
+    FeatureDistanceModel fsm = new FeatureDistanceModel();
     Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
             .getAlignPanel()));
     alf.selectAllSequenceMenuItem_actionPerformed(null);
@@ -125,7 +125,7 @@ public class FeatureScoreModelTest
     AlignFrame alf = getTestAlignmentFrame();
     // hiding first two columns shouldn't affect the tree
     alf.getViewport().hideColumns(0, 1);
-    FeatureScoreModel fsm = new FeatureScoreModel();
+    FeatureDistanceModel fsm = new FeatureDistanceModel();
     Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
             .getAlignPanel()));
     alf.selectAllSequenceMenuItem_actionPerformed(null);
@@ -144,7 +144,7 @@ public class FeatureScoreModelTest
     // hide columns and check tree changes
     alf.getViewport().hideColumns(3, 4);
     alf.getViewport().hideColumns(0, 1);
-    FeatureScoreModel fsm = new FeatureScoreModel();
+    FeatureDistanceModel fsm = new FeatureDistanceModel();
     Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
             .getAlignPanel()));
     alf.selectAllSequenceMenuItem_actionPerformed(null);
@@ -240,7 +240,7 @@ public class FeatureScoreModelTest
     alf.setShowSeqFeatures(true);
     alf.getFeatureRenderer().findAllFeatures(true);
 
-    FeatureScoreModel fsm = new FeatureScoreModel();
+    FeatureDistanceModel fsm = new FeatureDistanceModel();
     Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
             .getAlignPanel()));
     alf.selectAllSequenceMenuItem_actionPerformed(null);
index cbc834d..fcc0bc3 100644 (file)
@@ -56,4 +56,23 @@ public class ScoreMatrixTest
       }
     }
   }
+
+  @Test(groups = "Functional")
+  public void testGetMatrixIndex()
+  {
+    ScoreMatrix sm = ScoreModels.getInstance().getBlosum62();
+    assertEquals(sm.getMatrixIndex('A'), 0);
+    assertEquals(sm.getMatrixIndex('R'), 1);
+    assertEquals(sm.getMatrixIndex('r'), 1);
+    assertEquals(sm.getMatrixIndex('N'), 2);
+    assertEquals(sm.getMatrixIndex('D'), 3);
+    assertEquals(sm.getMatrixIndex('X'), 22);
+    assertEquals(sm.getMatrixIndex('x'), 22);
+    assertEquals(sm.getMatrixIndex(' '), 23);
+    assertEquals(sm.getMatrixIndex('*'), 24);
+    assertEquals(sm.getMatrixIndex('.'), -1);
+    assertEquals(sm.getMatrixIndex('-'), -1);
+    assertEquals(sm.getMatrixIndex('?'), -1);
+    assertEquals(sm.getMatrixIndex((char) 128), -1);
+  }
 }
index 2ebbe5c..c5c8673 100644 (file)
@@ -4,7 +4,7 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
 
-import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.DistanceModelI;
 
 import java.util.Iterator;
 
@@ -19,40 +19,45 @@ public class ScoreModelsTest
   @Test
   public void testConstructor()
   {
-    Iterator<ScoreModelI> models = ScoreModels.getInstance().getModels()
+    Iterator<DistanceModelI> models = ScoreModels.getInstance().getModels()
             .iterator();
     assertTrue(models.hasNext());
 
     /*
      * models are served in order of addition
      */
-    ScoreModelI sm = models.next();
-    assertTrue(sm instanceof ScoreMatrix);
+    DistanceModelI sm = models.next();
+    assertTrue(sm instanceof PairwiseDistanceModel);
     assertEquals(sm.getName(), "BLOSUM62");
-    assertEquals(((ScoreMatrix) sm).getPairwiseScore('I', 'R'), -3f);
+    assertEquals(((PairwiseDistanceModel) sm).getScoreModel()
+            .getPairwiseScore('I', 'R'), -3f);
 
     sm = models.next();
-    assertTrue(sm instanceof ScoreMatrix);
+    assertTrue(sm instanceof PairwiseDistanceModel);
     assertEquals(sm.getName(), "PAM250");
-    assertEquals(((ScoreMatrix) sm).getPairwiseScore('R', 'C'), -4f);
+    assertEquals(((PairwiseDistanceModel) sm).getScoreModel()
+            .getPairwiseScore('R', 'C'), -4f);
 
     sm = models.next();
-    assertTrue(sm instanceof ScoreMatrix);
+    assertTrue(sm instanceof PairwiseDistanceModel);
     assertEquals(sm.getName(), "Identity (SeqSpace)");
-    assertEquals(((ScoreMatrix) sm).getPairwiseScore('R', 'C'), 0f);
-    assertEquals(((ScoreMatrix) sm).getPairwiseScore('R', 'r'), 1f);
+    assertEquals(((PairwiseDistanceModel) sm).getScoreModel()
+            .getPairwiseScore('R', 'C'), 0f);
+    assertEquals(((PairwiseDistanceModel) sm).getScoreModel()
+            .getPairwiseScore('R', 'r'), 1f);
 
     sm = models.next();
-    assertTrue(sm instanceof ScoreMatrix);
+    assertTrue(sm instanceof PairwiseDistanceModel);
     assertEquals(sm.getName(), "DNA");
-    assertEquals(((ScoreMatrix) sm).getPairwiseScore('c', 'x'), 1f);
+    assertEquals(((PairwiseDistanceModel) sm).getScoreModel()
+            .getPairwiseScore('c', 'x'), 1f);
 
     sm = models.next();
-    assertFalse(sm instanceof ScoreMatrix);
+    assertFalse(sm instanceof PairwiseDistanceModel);
     assertEquals(sm.getName(), "Sequence Feature Similarity");
 
     sm = models.next();
-    assertFalse(sm instanceof ScoreMatrix);
+    assertFalse(sm instanceof PairwiseDistanceModel);
     assertEquals(sm.getName(), "PID");
   }
 }
index b58b56f..aed4086 100644 (file)
@@ -22,7 +22,7 @@ package jalview.schemes;
 
 import jalview.analysis.scoremodels.ScoreMatrix;
 import jalview.analysis.scoremodels.ScoreModels;
-import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.DistanceModelI;
 import jalview.gui.JvOptionPane;
 
 import org.testng.annotations.BeforeClass;
@@ -41,7 +41,7 @@ public class ScoreMatrixPrinter
   @Test(groups = { "Functional" })
   public void printAllMatrices()
   {
-    for (ScoreModelI sm : ScoreModels.getInstance().getModels())
+    for (DistanceModelI sm : ScoreModels.getInstance().getModels())
     {
       System.out.println("Matrix " + sm.getName());
       System.out.println(sm.toString());
@@ -51,7 +51,7 @@ public class ScoreMatrixPrinter
   @Test(groups = { "Functional" })
   public void printHTMLMatrices()
   {
-    for (ScoreModelI sm : ScoreModels.getInstance().getModels())
+    for (DistanceModelI sm : ScoreModels.getInstance().getModels())
     {
       if (sm instanceof ScoreMatrix)
       {