From: gmungoc Date: Fri, 17 Feb 2017 16:28:44 +0000 (+0000) Subject: JAL-2416 scoreMatrices removed from ResidueProperties X-Git-Tag: Release_2_10_2~3^2~105^2~2^2~107 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=a45b4529c64901e9e4b53b6c74ee804370c91002 JAL-2416 scoreMatrices removed from ResidueProperties --- diff --git a/src/jalview/analysis/AlignSeq.java b/src/jalview/analysis/AlignSeq.java index fe04156..f623a96 100755 --- a/src/jalview/analysis/AlignSeq.java +++ b/src/jalview/analysis/AlignSeq.java @@ -21,6 +21,7 @@ package jalview.analysis; import jalview.analysis.scoremodels.ScoreMatrix; +import jalview.analysis.scoremodels.ScoreModels; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Mapping; @@ -423,11 +424,11 @@ public class AlignSeq if (type.equals(AlignSeq.PEP)) { - lookup = ResidueProperties.getDefaultPeptideMatrix(); + lookup = ScoreModels.getInstance().getDefaultModel(true).getMatrix(); } else if (type.equals(AlignSeq.DNA)) { - lookup = ResidueProperties.getDefaultDnaMatrix(); + lookup = ScoreModels.getInstance().getDefaultModel(false).getMatrix(); } } diff --git a/src/jalview/analysis/scoremodels/PIDScoreModel.java b/src/jalview/analysis/scoremodels/PIDScoreModel.java index 0f7a67a..e0e8634 100644 --- a/src/jalview/analysis/scoremodels/PIDScoreModel.java +++ b/src/jalview/analysis/scoremodels/PIDScoreModel.java @@ -72,4 +72,9 @@ public class PIDScoreModel implements ScoreModelI return true; } + @Override + public String toString() + { + return "Percentage identity of sequences"; + } } diff --git a/src/jalview/analysis/scoremodels/ScoreModels.java b/src/jalview/analysis/scoremodels/ScoreModels.java index 377fdef..07840fc 100644 --- a/src/jalview/analysis/scoremodels/ScoreModels.java +++ b/src/jalview/analysis/scoremodels/ScoreModels.java @@ -14,8 +14,17 @@ import java.util.Map; */ public class ScoreModels { - private static ScoreModels instance = new 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"; + public static final String DNA = "DNA"; + + private static ScoreModels instance = new ScoreModels(); private Map models; public static ScoreModels getInstance() @@ -99,4 +108,17 @@ public class ScoreModels } models.put(sm.getName(), sm); } + + /** + * Returns the default peptide or nucleotide score model, currently BLOSUM62 + * or DNA + * + * @param forPeptide + * @return + */ + public PairwiseSeqScoreModel getDefaultModel(boolean forPeptide) + { + return (PairwiseSeqScoreModel) (forPeptide ? forName("BLOSUM62") + : forName("DNA")); + } } diff --git a/src/jalview/appletgui/TreePanel.java b/src/jalview/appletgui/TreePanel.java index b4b8ec2..d3e6213 100644 --- a/src/jalview/appletgui/TreePanel.java +++ b/src/jalview/appletgui/TreePanel.java @@ -21,6 +21,7 @@ package jalview.appletgui; import jalview.analysis.NJTree; +import jalview.analysis.scoremodels.ScoreModels; import jalview.api.analysis.ScoreModelI; import jalview.api.analysis.ViewBasedAnalysisI; import jalview.datamodel.Alignment; @@ -28,7 +29,6 @@ import jalview.datamodel.AlignmentView; import jalview.datamodel.ColumnSelection; import jalview.datamodel.SequenceI; import jalview.io.NewickFile; -import jalview.schemes.ResidueProperties; import jalview.util.MessageManager; import java.awt.BorderLayout; @@ -69,6 +69,7 @@ public class TreePanel extends EmbmenuFrame implements ActionListener, return tree; } + @Override public void finalize() throws Throwable { ap = null; @@ -200,6 +201,7 @@ public class TreePanel extends EmbmenuFrame implements ActionListener, this.newtree = newtree; } + @Override public void run() { if (newtree != null) @@ -235,7 +237,7 @@ public class TreePanel extends EmbmenuFrame implements ActionListener, seqs = av.getSelectionGroup().getSequencesInOrder( av.getAlignment()); } - ScoreModelI sm = ResidueProperties.getScoreModel(pwtype); + ScoreModelI sm = ScoreModels.getInstance().forName(pwtype); if (sm instanceof ViewBasedAnalysisI) { try @@ -286,6 +288,7 @@ public class TreePanel extends EmbmenuFrame implements ActionListener, } } + @Override public void actionPerformed(ActionEvent evt) { if (evt.getSource() == newickOutput) @@ -302,6 +305,7 @@ public class TreePanel extends EmbmenuFrame implements ActionListener, } } + @Override public void itemStateChanged(ItemEvent evt) { if (evt.getSource() == fitToWindow) diff --git a/src/jalview/schemes/Blosum62ColourScheme.java b/src/jalview/schemes/Blosum62ColourScheme.java index c03c40b..a88f74f 100755 --- a/src/jalview/schemes/Blosum62ColourScheme.java +++ b/src/jalview/schemes/Blosum62ColourScheme.java @@ -20,6 +20,8 @@ */ package jalview.schemes; +import jalview.analysis.scoremodels.PairwiseSeqScoreModel; +import jalview.analysis.scoremodels.ScoreModels; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; @@ -53,6 +55,9 @@ 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); + /* * compare as upper case; note consensusResidue is * always computed as uppercase @@ -79,7 +84,8 @@ public class Blosum62ColourScheme extends ResidueColourScheme for (char consensus : consensusResidue.toCharArray()) { - score += ResidueProperties.getBLOSUM62(consensus, res); + score += sm.getPairwiseScore(consensus, res); + // score += ResidueProperties.getBLOSUM62(consensus, res); } if (score > 0) diff --git a/src/jalview/schemes/ResidueProperties.java b/src/jalview/schemes/ResidueProperties.java index b4b5452..0b1b7cc 100755 --- a/src/jalview/schemes/ResidueProperties.java +++ b/src/jalview/schemes/ResidueProperties.java @@ -20,11 +20,6 @@ */ package jalview.schemes; -import jalview.analysis.scoremodels.FeatureScoreModel; -import jalview.analysis.scoremodels.PIDScoreModel; -import jalview.analysis.scoremodels.ScoreMatrix; -import jalview.api.analysis.ScoreModelI; - import java.awt.Color; import java.util.ArrayList; import java.util.Arrays; @@ -37,8 +32,6 @@ import java.util.Vector; public class ResidueProperties { - public static Hashtable scoreMatrices = new Hashtable(); - // Stores residue codes/names and colours and other things public static final int[] aaIndex; // aaHash version 2.1.1 and below @@ -1246,16 +1239,6 @@ public class ResidueProperties propMatrixPos[i][i] = maxP; propMatrixEpos[i][i] = maxEP; } - // JAL-1512 comment out physicochemical score matrices for 2.8.1 release - // scoreMatrices.put("Conservation Pos", new - // ScoreMatrix("Conservation Pos",propMatrixPos,0)); - // scoreMatrices.put("Conservation Both", new - // ScoreMatrix("Conservation Both",propMatrixF,0)); - // scoreMatrices.put("Conservation EnhPos", new - // ScoreMatrix("Conservation EnhPos",propMatrixEpos,0)); - scoreMatrices.put("PID", new PIDScoreModel()); - scoreMatrices.put("Sequence Feature Similarity", - new FeatureScoreModel()); } private ResidueProperties() @@ -1282,11 +1265,6 @@ public class ResidueProperties return aa3Hash; } - public static float[][] getDNA() - { - return ResidueProperties.DNA; - } - public static float[][] getBLOSUM62() { return ResidueProperties.BLOSUM62; @@ -1297,24 +1275,6 @@ public class ResidueProperties return getPAM250(A1.charAt(0), A2.charAt(0)); } - public static float getBLOSUM62(char c1, char c2) - { - float pog = 0; - - try - { - int a = aaIndex[c1]; - int b = aaIndex[c2]; - - pog = ResidueProperties.BLOSUM62[a][b]; - } catch (Exception e) - { - // System.out.println("Unknown residue in " + A1 + " " + A2); - } - - return pog; - } - public static String codonTranslate(String lccodon) { String cdn = codonHash2.get(lccodon.toUpperCase()); @@ -1325,43 +1285,6 @@ public class ResidueProperties return cdn; } - public static float[][] getDefaultPeptideMatrix() - { - return ResidueProperties.getBLOSUM62(); - } - - public static float[][] getDefaultDnaMatrix() - { - return ResidueProperties.getDNA(); - } - - /** - * get a ScoreMatrix based on its string name - * - * @param pwtype - * @return matrix in scoreMatrices with key pwtype or null - */ - public static ScoreMatrix getScoreMatrix(String pwtype) - { - Object val = scoreMatrices.get(pwtype); - if (val != null && val instanceof ScoreMatrix) - { - return (ScoreMatrix) val; - } - return null; - } - - /** - * get a ScoreModel based on its string name - * - * @param pwtype - * @return scoremodel of type pwtype or null - */ - public static ScoreModelI getScoreModel(String pwtype) - { - return scoreMatrices.get(pwtype); - } - public static float getPAM250(char c, char d) { int a = aaIndex[c]; diff --git a/test/jalview/schemes/ScoreMatrixPrinter.java b/test/jalview/schemes/ScoreMatrixPrinter.java index 4e7755c..b58b56f 100644 --- a/test/jalview/schemes/ScoreMatrixPrinter.java +++ b/test/jalview/schemes/ScoreMatrixPrinter.java @@ -21,11 +21,10 @@ package jalview.schemes; import jalview.analysis.scoremodels.ScoreMatrix; +import jalview.analysis.scoremodels.ScoreModels; import jalview.api.analysis.ScoreModelI; import jalview.gui.JvOptionPane; -import java.util.Map; - import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -42,25 +41,22 @@ public class ScoreMatrixPrinter @Test(groups = { "Functional" }) public void printAllMatrices() { - for (Map.Entry sm : ResidueProperties.scoreMatrices - .entrySet()) + for (ScoreModelI sm : ScoreModels.getInstance().getModels()) { - System.out.println("Matrix " + sm.getKey()); - System.out.println(sm.getValue().toString()); + System.out.println("Matrix " + sm.getName()); + System.out.println(sm.toString()); } } @Test(groups = { "Functional" }) public void printHTMLMatrices() { - for (Map.Entry _sm : ResidueProperties.scoreMatrices - .entrySet()) + for (ScoreModelI sm : ScoreModels.getInstance().getModels()) { - if (_sm.getValue() instanceof ScoreMatrix) + if (sm instanceof ScoreMatrix) { - ScoreMatrix sm = (ScoreMatrix) _sm.getValue(); - System.out.println("Matrix " + _sm.getKey()); - System.out.println(sm.outputMatrix(true)); + System.out.println("Matrix " + sm.getName()); + System.out.println(((ScoreMatrix) sm).outputMatrix(true)); } } }