1 package jalview.analysis.scoremodels;
3 import jalview.api.AlignmentViewPanel;
4 import jalview.api.analysis.ScoreModelI;
5 import jalview.io.DataSourceType;
6 import jalview.io.FileParse;
7 import jalview.io.ScoreMatrixFile;
9 import java.io.IOException;
10 import java.util.LinkedHashMap;
14 * A class that can register and serve instances of ScoreModelI
16 public class ScoreModels
18 private final ScoreMatrix BLOSUM62;
20 private final ScoreMatrix PAM250;
22 private final ScoreMatrix DNA;
24 private static ScoreModels instance = new ScoreModels();
26 private Map<String, ScoreModelI> models;
28 public static ScoreModels getInstance()
34 * Private constructor to enforce use of singleton. Registers Jalview's
35 * "built-in" score models:
41 * <li>Sequence Feature Similarity</li>
47 * using LinkedHashMap keeps models ordered as added
49 models = new LinkedHashMap<String, ScoreModelI>();
50 BLOSUM62 = loadScoreMatrix("scoreModel/blosum62.scm");
51 PAM250 = loadScoreMatrix("scoreModel/pam250.scm");
52 registerScoreModel(new PIDModel());
53 DNA = loadScoreMatrix("scoreModel/dna.scm");
54 registerScoreModel(new FeatureDistanceModel());
58 * Tries to load a score matrix from the given resource file, and if
59 * successful, registers it.
64 ScoreMatrix loadScoreMatrix(String resourcePath)
69 * delegate parsing to ScoreMatrixFile
71 FileParse fp = new FileParse(resourcePath, DataSourceType.CLASSLOADER);
72 ScoreMatrix sm = new ScoreMatrixFile(fp).parseMatrix();
73 registerScoreModel(sm);
75 } catch (IOException e)
77 System.err.println("Error reading " + resourcePath + ": "
84 * Answers an iterable set of the registered score models. Currently these are
85 * returned in the order in which they were registered.
89 public Iterable<ScoreModelI> getModels()
91 return models.values();
95 * Returns an instance of a score model for the given name. If the model is of
96 * 'view dependent' type (e.g. feature similarity), instantiates a new
97 * instance configured for the given view. Otherwise returns a cached instance
104 public ScoreModelI getScoreModel(String name, AlignmentViewPanel avp)
106 ScoreModelI model = models.get(name);
107 return model == null ? null : model.getInstance(avp);
110 public void registerScoreModel(ScoreModelI sm)
112 ScoreModelI sm2 = models.get(sm.getName());
115 System.err.println("Warning: replacing score model " + sm2.getName());
117 models.put(sm.getName(), sm);
121 * Returns the default peptide or nucleotide score model, currently BLOSUM62
127 public ScoreMatrix getDefaultModel(boolean forPeptide)
129 return forPeptide ? BLOSUM62 : DNA;
132 public ScoreMatrix getBlosum62()
137 public ScoreMatrix getPam250()