JAL-2416 better encapsulated 'constants' for BLOSUM62, PAM250
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Sat, 18 Feb 2017 08:21:41 +0000 (08:21 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Sat, 18 Feb 2017 08:21:41 +0000 (08:21 +0000)
src/jalview/analysis/AlignSeq.java
src/jalview/analysis/Conservation.java
src/jalview/analysis/scoremodels/ScoreModels.java
src/jalview/schemes/Blosum62ColourScheme.java
src/jalview/ws/sifts/SiftsClient.java

index 61ff012..ed4e3bc 100755 (executable)
@@ -118,8 +118,7 @@ public class AlignSeq
 
   int gapExtend = 20;
 
-  float[][] lookup = ((ScoreMatrix) ScoreModels.getInstance().forName(
-          ScoreModels.BLOSUM62)).getMatrix();
+  float[][] lookup = ScoreModels.getInstance().getBlosum62().getMatrix();
 
   // ResidueProperties.getBLOSUM62();
 
@@ -604,8 +603,7 @@ public class AlignSeq
             .append(String.valueOf(s2str.length())).append(")")
             .append(NEWLINE).append(NEWLINE);
 
-    PairwiseSeqScoreModel pam250 = (PairwiseSeqScoreModel) ScoreModels
-            .getInstance().forName(ScoreModels.PAM250);
+    PairwiseSeqScoreModel pam250 = ScoreModels.getInstance().getPam250();
 
     for (int j = 0; j < nochunks; j++)
     {
index 436be5b..79fa3d6 100755 (executable)
@@ -20,7 +20,6 @@
  */
 package jalview.analysis;
 
-import jalview.analysis.scoremodels.PairwiseSeqScoreModel;
 import jalview.analysis.scoremodels.ScoreModels;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Annotation;
@@ -604,8 +603,8 @@ public class Conservation
     quality = new Vector<Double>();
 
     double max = -10000;
-    float[][] BLOSUM62 = ((PairwiseSeqScoreModel) ScoreModels.getInstance()
-            .forName(ScoreModels.BLOSUM62)).getMatrix();
+    float[][] BLOSUM62 = ScoreModels.getInstance().getBlosum62()
+            .getMatrix();
 
     // Loop over columns // JBPNote Profiling info
     // long ts = System.currentTimeMillis();
index 07840fc..2419997 100644 (file)
@@ -14,17 +14,12 @@ import java.util.Map;
  */
 public class ScoreModels
 {
-  /*
-   * constants for built-in score model names
-   * NB! these have to match names in loaded score matrix files
-   */
-  public static final String BLOSUM62 = "BLOSUM62";
-
-  public static final String PAM250 = "PAM250";
+  private final ScoreMatrix BLOSUM62;
 
-  public static final String DNA = "DNA";
+  private final ScoreMatrix PAM250;
 
   private static ScoreModels instance = new ScoreModels();
+
   private Map<String, ScoreModelI> models;
 
   public static ScoreModels getInstance()
@@ -50,21 +45,22 @@ public class ScoreModels
      * using LinkedHashMap keeps models ordered as added
      */
     models = new LinkedHashMap<String, ScoreModelI>();
-    loadScoreMatrix("scoreModel/blosum62.scm");
-    loadScoreMatrix("scoreModel/pam250.scm");
-    loadScoreMatrix("scoreModel/seqspace.scm");
+    BLOSUM62 = loadScoreMatrix("scoreModel/blosum62.scm");
+    PAM250 = loadScoreMatrix("scoreModel/pam250.scm");
     loadScoreMatrix("scoreModel/dna.scm");
+    loadScoreMatrix("scoreModel/seqspace.scm");
     registerScoreModel(new FeatureScoreModel());
     registerScoreModel(new PIDScoreModel());
   }
 
   /**
-   * Try to load a score matrix from the given resource file, and if successful,
-   * register it. Answers true if successful, else false.
+   * Tries to load a score matrix from the given resource file, and if
+   * successful, registers it.
    * 
    * @param string
+   * @return
    */
-  boolean loadScoreMatrix(String resourcePath)
+  ScoreMatrix loadScoreMatrix(String resourcePath)
   {
     try
     {
@@ -74,13 +70,13 @@ public class ScoreModels
       FileParse fp = new FileParse(resourcePath, DataSourceType.CLASSLOADER);
       ScoreMatrix sm = new ScoreMatrixFile(fp).parseMatrix();
       registerScoreModel(sm);
-      return true;
+      return sm;
     } catch (IOException e)
     {
       System.err.println("Error reading " + resourcePath + ": "
               + e.getMessage());
     }
-    return false;
+    return null;
   }
 
   /**
@@ -121,4 +117,14 @@ public class ScoreModels
     return (PairwiseSeqScoreModel) (forPeptide ? forName("BLOSUM62")
             : forName("DNA"));
   }
+
+  public ScoreMatrix getBlosum62()
+  {
+    return BLOSUM62;
+  }
+
+  public ScoreMatrix getPam250()
+  {
+    return PAM250;
+  }
 }
index a88f74f..58e12b7 100755 (executable)
@@ -55,8 +55,7 @@ public class Blosum62ColourScheme extends ResidueColourScheme
   public Color findColour(char res, int j, SequenceI seq,
           String consensusResidue, float pid)
   {
-    PairwiseSeqScoreModel sm = (PairwiseSeqScoreModel) ScoreModels
-            .getInstance().forName(ScoreModels.BLOSUM62);
+    PairwiseSeqScoreModel sm = ScoreModels.getInstance().getBlosum62();
 
     /*
      * compare as upper case; note consensusResidue is 
index 6d961c0..a066915 100644 (file)
@@ -988,8 +988,7 @@ public class SiftsClient implements SiftsClientI
     output.append(String.valueOf(pdbEnd));
     output.append(NEWLINE).append(NEWLINE);
 
-    PairwiseSeqScoreModel pam250 = (PairwiseSeqScoreModel) ScoreModels
-            .getInstance().forName(ScoreModels.PAM250);
+    PairwiseSeqScoreModel pam250 = ScoreModels.getInstance().getPam250();
     int matchedSeqCount = 0;
     for (int j = 0; j < nochunks; j++)
     {