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;
9 import java.util.LinkedHashMap;
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:
32 * <li>SeqSpace (identity matrix)</li>
34 * <li>Sequence Feature Similarity</li>
35 * <li>Percentage Identity</li>
41 * using LinkedHashMap keeps models ordered as added
43 models = new LinkedHashMap<String, ScoreModelI>();
44 loadScoreMatrix("scoreModel/blosum62.scm");
45 loadScoreMatrix("scoreModel/pam250.scm");
46 loadScoreMatrix("scoreModel/seqspace.scm");
47 loadScoreMatrix("scoreModel/dna.scm");
48 registerScoreModel(new FeatureScoreModel());
49 registerScoreModel(new PIDScoreModel());
53 * Try to load a score matrix from the given resource file, and if successful,
54 * register it. Answers true if successful, else false.
58 boolean loadScoreMatrix(String resourcePath)
63 * delegate parsing to ScoreMatrixFile
65 FileParse fp = new FileParse(resourcePath, DataSourceType.CLASSLOADER);
66 ScoreMatrix sm = new ScoreMatrixFile(fp).parseMatrix();
67 registerScoreModel(sm);
69 } catch (IOException e)
71 System.err.println("Error reading " + resourcePath + ": "
78 * Answers an iterable set of the registered score models. Currently these are
79 * returned in the order in which they were registered.
83 public Iterable<ScoreModelI> getModels()
85 return models.values();
88 public ScoreModelI forName(String s)
93 public void registerScoreModel(ScoreModelI sm)
95 ScoreModelI sm2 = models.get(sm.getName());
98 System.err.println("Warning: replacing score model " + sm2.getName());
100 models.put(sm.getName(), sm);