1 package jalview.analysis.scoremodels;
3 import jalview.api.analysis.ScoreModelI;
4 import jalview.io.DataSourceType;
5 import jalview.io.FileParse;
6 import jalview.io.ScoreMatrixFile;
8 import java.io.IOException;
10 import java.util.TreeMap;
13 * A class that can register and serve instances of ScoreModelI
15 public class ScoreModels
17 private static ScoreModels instance = new ScoreModels();
19 private Map<String, ScoreModelI> models;
21 public static ScoreModels getInstance()
27 * Private constructor to enforce use of singleton. Registers Jalview's
28 * "built-in" score models:
33 * <li>Sequence Feature Similarity</li>
34 * <li>Percentage Identity</li>
40 * using TreeMap keeps models ordered alphabetically by name
42 models = new TreeMap<String, ScoreModelI>(String.CASE_INSENSITIVE_ORDER);
43 loadScoreMatrix("scoreModel/blosum62.scm");
44 loadScoreMatrix("scoreModel/pam250.scm");
45 loadScoreMatrix("scoreModel/dna.scm");
46 registerScoreModel(new FeatureScoreModel());
47 registerScoreModel(new PIDScoreModel());
51 * Try to load a score matrix from the given resource file, and if successful,
52 * register it. Answers true if successful, else false.
56 boolean loadScoreMatrix(String resourcePath)
61 * delegate parsing to ScoreMatrixFile
63 FileParse fp = new FileParse(resourcePath, DataSourceType.CLASSLOADER);
64 ScoreMatrix sm = new ScoreMatrixFile(fp).parseMatrix();
65 registerScoreModel(sm);
67 } catch (IOException e)
69 System.err.println("Error reading " + resourcePath + ": "
76 * Answers an iterable set of the registered score models. Currently these are
77 * ordered by name (not case sensitive).
81 public Iterable<ScoreModelI> getModels()
83 return models.values();
86 public ScoreModelI forName(String s)
91 public void registerScoreModel(ScoreModelI sm)
93 ScoreModelI sm2 = models.get(sm.getName());
96 System.err.println("Warning: replacing score model " + sm2.getName());
98 models.put(sm.getName(), sm);