1 package jalview.analysis.scoremodels;
3 import jalview.api.analysis.ScoreModelI;
5 import java.io.IOException;
6 import java.io.InputStream;
9 import java.util.TreeMap;
12 * A class that can register and serve instances of ScoreModelI
14 public class ScoreModels
16 private static ScoreModels instance = new ScoreModels();
18 private Map<String, ScoreModelI> models;
20 public static ScoreModels getInstance()
26 * Private constructor to enforce use of singleton. Registers Jalview's
27 * "built-in" score models:
32 * <li>Sequence Feature Similarity</li>
33 * <li>Percentage Identity</li>
39 * using TreeMap keeps models ordered alphabetically by name
41 models = new TreeMap<String, ScoreModelI>(String.CASE_INSENSITIVE_ORDER);
42 loadScoreMatrix("/scoreModel/blosum62.scm");
43 loadScoreMatrix("/scoreModel/pam250.scm");
44 loadScoreMatrix("/scoreModel/dna.scm");
45 registerScoreModel(new FeatureScoreModel());
46 registerScoreModel(new PIDScoreModel());
50 * Try to load a score matrix from the given resource file, and if successful,
51 * register it. Answers true if successful, else false. Any errors are
52 * reported on syserr but not thrown.
56 boolean loadScoreMatrix(String resourcePath)
58 URL url = this.getClass().getResource(resourcePath);
61 System.err.println("Failed to locate " + resourcePath);
64 boolean success = false;
65 InputStream is = null;
68 is = url.openStream();
69 ScoreMatrix sm = ScoreMatrix.parse(is);
72 registerScoreModel(sm);
75 } catch (IOException e)
84 } catch (IOException e)
93 * Answers an iterable set of the registered score models. Currently these are
94 * ordered by name (not case sensitive).
98 public Iterable<ScoreModelI> getModels()
100 return models.values();
103 public ScoreModelI forName(String s)
105 return models.get(s);
108 public void registerScoreModel(ScoreModelI sm)
110 ScoreModelI sm2 = models.get(sm.getName());
113 System.err.println("Warning: replacing score model " + sm2.getName());
115 models.put(sm.getName(), sm);