From: gmungoc Date: Sat, 18 Feb 2017 08:21:41 +0000 (+0000) Subject: JAL-2416 better encapsulated 'constants' for BLOSUM62, PAM250 X-Git-Tag: Release_2_10_2~3^2~105^2~2^2~104 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=67428050d76de7946d96d43ba16ee02d439026bd;p=jalview.git JAL-2416 better encapsulated 'constants' for BLOSUM62, PAM250 --- diff --git a/src/jalview/analysis/AlignSeq.java b/src/jalview/analysis/AlignSeq.java index 61ff012..ed4e3bc 100755 --- a/src/jalview/analysis/AlignSeq.java +++ b/src/jalview/analysis/AlignSeq.java @@ -118,8 +118,7 @@ public class AlignSeq int gapExtend = 20; - float[][] lookup = ((ScoreMatrix) ScoreModels.getInstance().forName( - ScoreModels.BLOSUM62)).getMatrix(); + float[][] lookup = ScoreModels.getInstance().getBlosum62().getMatrix(); // ResidueProperties.getBLOSUM62(); @@ -604,8 +603,7 @@ public class AlignSeq .append(String.valueOf(s2str.length())).append(")") .append(NEWLINE).append(NEWLINE); - PairwiseSeqScoreModel pam250 = (PairwiseSeqScoreModel) ScoreModels - .getInstance().forName(ScoreModels.PAM250); + PairwiseSeqScoreModel pam250 = ScoreModels.getInstance().getPam250(); for (int j = 0; j < nochunks; j++) { diff --git a/src/jalview/analysis/Conservation.java b/src/jalview/analysis/Conservation.java index 436be5b..79fa3d6 100755 --- a/src/jalview/analysis/Conservation.java +++ b/src/jalview/analysis/Conservation.java @@ -20,7 +20,6 @@ */ package jalview.analysis; -import jalview.analysis.scoremodels.PairwiseSeqScoreModel; import jalview.analysis.scoremodels.ScoreModels; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; @@ -604,8 +603,8 @@ public class Conservation quality = new Vector(); double max = -10000; - float[][] BLOSUM62 = ((PairwiseSeqScoreModel) ScoreModels.getInstance() - .forName(ScoreModels.BLOSUM62)).getMatrix(); + float[][] BLOSUM62 = ScoreModels.getInstance().getBlosum62() + .getMatrix(); // Loop over columns // JBPNote Profiling info // long ts = System.currentTimeMillis(); diff --git a/src/jalview/analysis/scoremodels/ScoreModels.java b/src/jalview/analysis/scoremodels/ScoreModels.java index 07840fc..2419997 100644 --- a/src/jalview/analysis/scoremodels/ScoreModels.java +++ b/src/jalview/analysis/scoremodels/ScoreModels.java @@ -14,17 +14,12 @@ import java.util.Map; */ public class ScoreModels { - /* - * constants for built-in score model names - * NB! these have to match names in loaded score matrix files - */ - public static final String BLOSUM62 = "BLOSUM62"; - - public static final String PAM250 = "PAM250"; + private final ScoreMatrix BLOSUM62; - public static final String DNA = "DNA"; + private final ScoreMatrix PAM250; private static ScoreModels instance = new ScoreModels(); + private Map models; public static ScoreModels getInstance() @@ -50,21 +45,22 @@ public class ScoreModels * using LinkedHashMap keeps models ordered as added */ models = new LinkedHashMap(); - loadScoreMatrix("scoreModel/blosum62.scm"); - loadScoreMatrix("scoreModel/pam250.scm"); - loadScoreMatrix("scoreModel/seqspace.scm"); + BLOSUM62 = loadScoreMatrix("scoreModel/blosum62.scm"); + PAM250 = loadScoreMatrix("scoreModel/pam250.scm"); loadScoreMatrix("scoreModel/dna.scm"); + loadScoreMatrix("scoreModel/seqspace.scm"); registerScoreModel(new FeatureScoreModel()); registerScoreModel(new PIDScoreModel()); } /** - * Try to load a score matrix from the given resource file, and if successful, - * register it. Answers true if successful, else false. + * Tries to load a score matrix from the given resource file, and if + * successful, registers it. * * @param string + * @return */ - boolean loadScoreMatrix(String resourcePath) + ScoreMatrix loadScoreMatrix(String resourcePath) { try { @@ -74,13 +70,13 @@ public class ScoreModels FileParse fp = new FileParse(resourcePath, DataSourceType.CLASSLOADER); ScoreMatrix sm = new ScoreMatrixFile(fp).parseMatrix(); registerScoreModel(sm); - return true; + return sm; } catch (IOException e) { System.err.println("Error reading " + resourcePath + ": " + e.getMessage()); } - return false; + return null; } /** @@ -121,4 +117,14 @@ public class ScoreModels return (PairwiseSeqScoreModel) (forPeptide ? forName("BLOSUM62") : forName("DNA")); } + + public ScoreMatrix getBlosum62() + { + return BLOSUM62; + } + + public ScoreMatrix getPam250() + { + return PAM250; + } } diff --git a/src/jalview/schemes/Blosum62ColourScheme.java b/src/jalview/schemes/Blosum62ColourScheme.java index a88f74f..58e12b7 100755 --- a/src/jalview/schemes/Blosum62ColourScheme.java +++ b/src/jalview/schemes/Blosum62ColourScheme.java @@ -55,8 +55,7 @@ public class Blosum62ColourScheme extends ResidueColourScheme public Color findColour(char res, int j, SequenceI seq, String consensusResidue, float pid) { - PairwiseSeqScoreModel sm = (PairwiseSeqScoreModel) ScoreModels - .getInstance().forName(ScoreModels.BLOSUM62); + PairwiseSeqScoreModel sm = ScoreModels.getInstance().getBlosum62(); /* * compare as upper case; note consensusResidue is diff --git a/src/jalview/ws/sifts/SiftsClient.java b/src/jalview/ws/sifts/SiftsClient.java index 6d961c0..a066915 100644 --- a/src/jalview/ws/sifts/SiftsClient.java +++ b/src/jalview/ws/sifts/SiftsClient.java @@ -988,8 +988,7 @@ public class SiftsClient implements SiftsClientI output.append(String.valueOf(pdbEnd)); output.append(NEWLINE).append(NEWLINE); - PairwiseSeqScoreModel pam250 = (PairwiseSeqScoreModel) ScoreModels - .getInstance().forName(ScoreModels.PAM250); + PairwiseSeqScoreModel pam250 = ScoreModels.getInstance().getPam250(); int matchedSeqCount = 0; for (int j = 0; j < nochunks; j++) {