JAL-4386 remove magic string in registerScoreModel...
authorJim Procter <jprocter@dundee.ac.uk>
Tue, 3 Sep 2024 14:08:47 +0000 (15:08 +0100)
committerJim Procter <jprocter@dundee.ac.uk>
Tue, 3 Sep 2024 14:08:47 +0000 (15:08 +0100)
src/jalview/analysis/scoremodels/ScoreModels.java

index 490ec00..84db2e3 100644 (file)
@@ -80,25 +80,26 @@ public class ScoreModels
      * using LinkedHashMap keeps models ordered as added
      */
     models = new LinkedHashMap<>();
-    BLOSUM62 = loadScoreMatrix("scoreModel/blosum62.scm");
-    PAM250 = loadScoreMatrix("scoreModel/pam250.scm");
-    DNA = loadScoreMatrix("scoreModel/dna.scm");
+    BLOSUM62 = loadScoreMatrix("scoreModel/blosum62.scm",true);
+    PAM250 = loadScoreMatrix("scoreModel/pam250.scm",true);
+    DNA = loadScoreMatrix("scoreModel/dna.scm",true);
     registerScoreModel(new PIDModel());
     registerScoreModel(new FeatureDistanceModel());
     SECONDARYSTRUCTURE = loadScoreMatrix(
-            "scoreModel/secondarystructure.scm");
+            "scoreModel/secondarystructure.scm",false);
     registerScoreModel(new SecondaryStructureDistanceModel());
 
   }
 
   /**
    * Tries to load a score matrix from the given resource file, and if
-   * successful, registers it.
+   * successful, optionally registers it.
    * 
-   * @param string
-   * @return
+   * @param resourcePath
+   * @param register (if true)
+   * @return loaded matrix
    */
-  ScoreMatrix loadScoreMatrix(String resourcePath)
+  ScoreMatrix loadScoreMatrix(String resourcePath, boolean register)
   {
     try
     {
@@ -108,7 +109,9 @@ public class ScoreModels
       FileParse fp = new FileParse(resourcePath,
               DataSourceType.CLASSLOADER);
       ScoreMatrix sm = new ScoreMatrixFile(fp).parseMatrix();
-      registerScoreModel(sm);
+      if (register) {
+        registerScoreModel(sm);
+      }
       return sm;
     } catch (IOException e)
     {
@@ -147,10 +150,6 @@ public class ScoreModels
 
   public void registerScoreModel(ScoreModelI sm)
   {
-    if (sm.getName().equals("SECONDARYSTRUCTURE"))
-    {
-      return;
-    }
     ScoreModelI sm2 = models.get(sm.getName());
     if (sm2 != null)
     {
@@ -190,6 +189,10 @@ public class ScoreModels
     return PAM250;
   }
 
+  /**
+   * get currently configured matrix for comparing secondary structure
+   * @return
+   */
   public ScoreMatrix getSecondaryStructureMatrix()
   {
     return SECONDARYSTRUCTURE;