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
18 * constants for built-in score model names
19 * NB! these have to match names in loaded score matrix files
21 public static final String BLOSUM62 = "BLOSUM62";
23 public static final String PAM250 = "PAM250";
25 public static final String DNA = "DNA";
27 private static ScoreModels instance = new ScoreModels();
28 private Map<String, ScoreModelI> models;
30 public static ScoreModels getInstance()
36 * Private constructor to enforce use of singleton. Registers Jalview's
37 * "built-in" score models:
41 * <li>SeqSpace (identity matrix)</li>
43 * <li>Sequence Feature Similarity</li>
44 * <li>Percentage Identity</li>
50 * using LinkedHashMap keeps models ordered as added
52 models = new LinkedHashMap<String, ScoreModelI>();
53 loadScoreMatrix("scoreModel/blosum62.scm");
54 loadScoreMatrix("scoreModel/pam250.scm");
55 loadScoreMatrix("scoreModel/seqspace.scm");
56 loadScoreMatrix("scoreModel/dna.scm");
57 registerScoreModel(new FeatureScoreModel());
58 registerScoreModel(new PIDScoreModel());
62 * Try to load a score matrix from the given resource file, and if successful,
63 * register it. Answers true if successful, else false.
67 boolean loadScoreMatrix(String resourcePath)
72 * delegate parsing to ScoreMatrixFile
74 FileParse fp = new FileParse(resourcePath, DataSourceType.CLASSLOADER);
75 ScoreMatrix sm = new ScoreMatrixFile(fp).parseMatrix();
76 registerScoreModel(sm);
78 } catch (IOException e)
80 System.err.println("Error reading " + resourcePath + ": "
87 * Answers an iterable set of the registered score models. Currently these are
88 * returned in the order in which they were registered.
92 public Iterable<ScoreModelI> getModels()
94 return models.values();
97 public ScoreModelI forName(String s)
102 public void registerScoreModel(ScoreModelI sm)
104 ScoreModelI sm2 = models.get(sm.getName());
107 System.err.println("Warning: replacing score model " + sm2.getName());
109 models.put(sm.getName(), sm);
113 * Returns the default peptide or nucleotide score model, currently BLOSUM62
119 public PairwiseSeqScoreModel getDefaultModel(boolean forPeptide)
121 return (PairwiseSeqScoreModel) (forPeptide ? forName("BLOSUM62")