X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2Fscoremodels%2FScoreModels.java;h=f1990c07800ab856895f62b6182f430338f961e5;hb=c6e8e8ccd10f21698226ae37196cd9680e6804a0;hp=4fa639686dd69e5530f70efb9f0eabc28776f801;hpb=1750b2f1dcdb6e7de41d0ef7beda88dc3400afba;p=jalview.git diff --git a/src/jalview/analysis/scoremodels/ScoreModels.java b/src/jalview/analysis/scoremodels/ScoreModels.java index 4fa6396..f1990c0 100644 --- a/src/jalview/analysis/scoremodels/ScoreModels.java +++ b/src/jalview/analysis/scoremodels/ScoreModels.java @@ -1,8 +1,10 @@ package jalview.analysis.scoremodels; import jalview.api.analysis.ScoreModelI; -import jalview.schemes.ResidueProperties; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; import java.util.Map; import java.util.TreeMap; @@ -37,18 +39,65 @@ public class ScoreModels * using TreeMap keeps models ordered alphabetically by name */ models = new TreeMap(String.CASE_INSENSITIVE_ORDER); - registerScoreModel(new ScoreMatrix("BLOSUM62", - ResidueProperties.BLOSUM62, 0)); - registerScoreModel(new ScoreMatrix("PAM250", ResidueProperties.PAM250, - 0)); - registerScoreModel(new ScoreMatrix("DNA", ResidueProperties.DNA, 1)); + loadScoreMatrix("/scoreModel/blosum62.scm"); + loadScoreMatrix("/scoreModel/pam250.scm"); + loadScoreMatrix("/scoreModel/dna.scm"); registerScoreModel(new FeatureScoreModel()); registerScoreModel(new PIDScoreModel()); } - public Iterable getModelNames() + /** + * Try to load a score matrix from the given resource file, and if successful, + * register it. Answers true if successful, else false. Any errors are + * reported on syserr but not thrown. + * + * @param string + */ + boolean loadScoreMatrix(String resourcePath) + { + URL url = this.getClass().getResource(resourcePath); + if (url == null) + { + System.err.println("Failed to locate " + resourcePath); + return false; + } + boolean success = false; + InputStream is = null; + try + { + is = url.openStream(); + ScoreMatrix sm = ScoreMatrix.parse(is); + if (sm != null) + { + registerScoreModel(sm); + success = true; + } + } catch (IOException e) + { + } finally + { + if (is != null) + { + try + { + is.close(); + } catch (IOException e) + { + } + } + } + return success; + } + + /** + * Answers an iterable set of the registered score models. Currently these are + * ordered by name (not case sensitive). + * + * @return + */ + public Iterable getModels() { - return models.keySet(); + return models.values(); } public ScoreModelI forName(String s)