Clover icon

Coverage Report

  1. Project Clover database Wed Jan 7 2026 02:49:01 GMT
  2. Package jalview.analysis.scoremodels

File ScoreModels.java

 

Coverage histogram

../../../img/srcFileCovDistChart9.png
12% of files have more coverage

Code metrics

8
31
12
1
203
98
17
0.55
2.58
12
1.42

Classes

Class Line # Actions
ScoreModels 38 31 17
0.8823529588.2%
 

Contributing tests

This file is covered by 226 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.analysis.scoremodels;
22   
23    import jalview.api.AlignmentViewPanel;
24    import jalview.api.analysis.ScoreModelI;
25    import jalview.bin.ApplicationSingletonProvider;
26    import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
27    import jalview.io.DataSourceType;
28    import jalview.io.FileParse;
29    import jalview.io.ScoreMatrixFile;
30   
31    import java.io.IOException;
32    import java.util.LinkedHashMap;
33    import java.util.Map;
34   
35    /**
36    * A class that can register and serve instances of ScoreModelI
37    */
 
38    public class ScoreModels implements ApplicationSingletonI
39    {
40    private final ScoreMatrix BLOSUM62;
41   
42    private final ScoreMatrix PAM250;
43   
44    private final ScoreMatrix DNA;
45   
46    private final ScoreMatrix FOLDSEEK3DI;
47   
48    private final ScoreMatrix SECONDARYSTRUCTURE;
49   
50    private Map<String, ScoreModelI> models;
51    /**
52    * Answers the singleton instance of this class, with lazy initialisation
53    * (built-in score models are loaded on the first call to this method)
54    *
55    * @return
56    */
 
57  21083 toggle public static ScoreModels getInstance()
58    {
59  21083 return ApplicationSingletonProvider.getInstance(ScoreModels.class);
60    }
61   
62    /**
63    * Private constructor to enforce use of singleton. Registers Jalview's
64    * "built-in" score models:
65    * <ul>
66    * <li>BLOSUM62</li>
67    * <li>PAM250</li>
68    * <li>PID</li>
69    * <li>DNA</li>
70    * <li>Sequence Feature Similarity</li> *
71    * <li>Secondary Structure Similarity</li>
72    * <li>FOLDSEEK_3di</li>
73    * </ul>
74    */
 
75  74 toggle private ScoreModels()
76    {
77    /*
78    * using LinkedHashMap keeps models ordered as added
79    */
80  74 models = new LinkedHashMap<>();
81  74 BLOSUM62 = loadScoreMatrix("scoreModel/blosum62.scm",true);
82  74 PAM250 = loadScoreMatrix("scoreModel/pam250.scm",true);
83  74 DNA = loadScoreMatrix("scoreModel/dna.scm",true);
84  74 FOLDSEEK3DI = loadScoreMatrix("scoreModel/foldseek_mat3di.scm",true);
85  74 registerScoreModel(new PIDModel());
86  74 registerScoreModel(new FeatureDistanceModel());
87  74 SECONDARYSTRUCTURE = loadScoreMatrix(
88    "scoreModel/secondarystructure.scm",false);
89  74 registerScoreModel(new SecondaryStructureDistanceModel());
90    }
91   
92    /**
93    * Tries to load a score matrix from the given resource file, and if
94    * successful, optionally registers it.
95    *
96    * @param resourcePath
97    * @param register (if true)
98    * @return loaded matrix
99    */
 
100  370 toggle ScoreMatrix loadScoreMatrix(String resourcePath, boolean register)
101    {
102  370 try
103    {
104    /*
105    * delegate parsing to ScoreMatrixFile
106    */
107  370 FileParse fp = new FileParse(resourcePath,
108    DataSourceType.CLASSLOADER);
109  370 ScoreMatrix sm = new ScoreMatrixFile(fp).parseMatrix();
110  370 if (register) {
111  296 registerScoreModel(sm);
112    }
113  370 return sm;
114    } catch (IOException e)
115    {
116  0 jalview.bin.Console.errPrintln(
117    "Error reading " + resourcePath + ": " + e.getMessage());
118    }
119  0 return null;
120    }
121   
122    /**
123    * Answers an iterable set of the registered score models. Currently these are
124    * returned in the order in which they were registered.
125    *
126    * @return
127    */
 
128  17 toggle public Iterable<ScoreModelI> getModels()
129    {
130  17 return models.values();
131    }
132   
133    /**
134    * Returns an instance of a score model for the given name. If the model is of
135    * 'view dependent' type (e.g. feature similarity), instantiates a new
136    * instance configured for the given view. Otherwise returns a cached instance
137    * of the score model.
138    *
139    * @param name
140    * @param avp
141    * @return
142    */
 
143  18 toggle public ScoreModelI getScoreModel(String name, AlignmentViewPanel avp)
144    {
145  18 ScoreModelI model = models.get(name);
146  18 return model == null ? null : model.getInstance(avp);
147    }
148   
 
149  519 toggle public void registerScoreModel(ScoreModelI sm)
150    {
151  519 ScoreModelI sm2 = models.get(sm.getName());
152  519 if (sm2 != null)
153    {
154  0 jalview.bin.Console.errPrintln(
155    "Warning: replacing score model " + sm2.getName());
156    }
157  519 models.put(sm.getName(), sm);
158    }
159   
160    /**
161    * Resets to just the built-in score models
162    */
 
163  20 toggle public void reset()
164    {
165  20 ApplicationSingletonProvider.removeInstance(this.getClass());
166    }
167   
168    /**
169    * Returns the default peptide or nucleotide score model, currently BLOSUM62
170    * or DNA
171    *
172    * @param forPeptide
173    * @return
174    */
 
175  1153 toggle public ScoreMatrix getDefaultModel(boolean forPeptide)
176    {
177  1153 return forPeptide ? BLOSUM62 : DNA;
178    }
179   
 
180  19630 toggle public ScoreMatrix getBlosum62()
181    {
182  19630 return BLOSUM62;
183    }
184   
 
185  236 toggle public ScoreMatrix getPam250()
186    {
187  236 return PAM250;
188    }
189   
190    /**
191    * get currently configured matrix for comparing secondary structure
192    * @return
193    */
 
194  11 toggle public ScoreMatrix getSecondaryStructureMatrix()
195    {
196  11 return SECONDARYSTRUCTURE;
197    }
198   
 
199  0 toggle public ScoreMatrix getFOLDSEEK3DI()
200    {
201  0 return FOLDSEEK3DI;
202    }
203    }