From: gmungoc Date: Mon, 20 Feb 2017 16:07:45 +0000 (+0000) Subject: JAL-2403 ScoreModelI now DistanceModelI, ScoreMatrix delegate of X-Git-Tag: Release_2_10_2~3^2~105^2~2^2~100 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=fcb39fa3bc47777bf4e0eb209f765dd254dc3cb9;p=jalview.git JAL-2403 ScoreModelI now DistanceModelI, ScoreMatrix delegate of PairwiseDistanceModel --- diff --git a/resources/scoreModel/dna.scm b/resources/scoreModel/dna.scm index b1e0621..4a196fb 100644 --- a/resources/scoreModel/dna.scm +++ b/resources/scoreModel/dna.scm @@ -18,7 +18,7 @@ ACGTUIXRYN - # Comment line with symbols is provided as a guide # Values may be integer or floating point, delimited by tab, space, comma or combinations # -# A C G T U I X R Y N - +# A C G T U I X R Y N - # 10 -8 -8 -8 -8 1 1 1 -8 1 1 1 -8 10 -8 -8 -8 1 1 -8 1 1 1 1 @@ -33,4 +33,4 @@ ACGTUIXRYN - 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 # -# A C G T U I X R Y N - +# A C G T U I X R Y N - diff --git a/src/jalview/analysis/NJTree.java b/src/jalview/analysis/NJTree.java index 542f15e..7140867 100644 --- a/src/jalview/analysis/NJTree.java +++ b/src/jalview/analysis/NJTree.java @@ -21,7 +21,7 @@ package jalview.analysis; import jalview.analysis.scoremodels.ScoreModels; -import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.DistanceModelI; import jalview.datamodel.AlignmentView; import jalview.datamodel.BinaryNode; import jalview.datamodel.CigarArray; @@ -224,7 +224,7 @@ public class NJTree * DOCUMENT ME! */ public NJTree(SequenceI[] sequence, AlignmentView seqData, String type, - String pwtype, ScoreModelI sm, int start, int end) + String pwtype, DistanceModelI sm, int start, int end) { this.sequence = sequence; this.node = new Vector(); @@ -736,7 +736,7 @@ public class NJTree * * @return similarity matrix used to compute tree */ - public float[][] findDistances(ScoreModelI _pwmatrix) + public float[][] findDistances(DistanceModelI _pwmatrix) { float[][] dist = new float[noseqs][noseqs]; diff --git a/src/jalview/analysis/PCA.java b/src/jalview/analysis/PCA.java index 87ec922..ae83400 100755 --- a/src/jalview/analysis/PCA.java +++ b/src/jalview/analysis/PCA.java @@ -20,6 +20,7 @@ */ package jalview.analysis; +import jalview.analysis.scoremodels.PairwiseDistanceModel; import jalview.analysis.scoremodels.ScoreMatrix; import jalview.analysis.scoremodels.ScoreModels; import jalview.datamodel.BinarySequence; @@ -94,14 +95,15 @@ public class PCA implements Runnable String sm = s_m; if (sm != null) { - smtrx = (ScoreMatrix) ScoreModels.getInstance().forName(sm); + smtrx = (ScoreMatrix) ((PairwiseDistanceModel) ScoreModels + .getInstance() + .forName(sm)).getScoreModel(); } if (smtrx == null) { // either we were given a non-existent score matrix or a scoremodel that // isn't based on a pairwise symbol score matrix - smtrx = (ScoreMatrix) ScoreModels.getInstance().forName( - sm = (nucleotides ? "DNA" : "BLOSUM62")); + smtrx = ScoreModels.getInstance().getDefaultModel(!nucleotides); } details.append("PCA calculation using " + sm + " sequence similarity matrix\n========\n\n"); diff --git a/src/jalview/analysis/scoremodels/FeatureScoreModel.java b/src/jalview/analysis/scoremodels/FeatureDistanceModel.java similarity index 97% rename from src/jalview/analysis/scoremodels/FeatureScoreModel.java rename to src/jalview/analysis/scoremodels/FeatureDistanceModel.java index 6fffcab..04a7b14 100644 --- a/src/jalview/analysis/scoremodels/FeatureScoreModel.java +++ b/src/jalview/analysis/scoremodels/FeatureDistanceModel.java @@ -20,7 +20,7 @@ */ package jalview.analysis.scoremodels; -import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.DistanceModelI; import jalview.api.analysis.ViewBasedAnalysisI; import jalview.datamodel.AlignmentView; import jalview.datamodel.SeqCigar; @@ -33,7 +33,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -public class FeatureScoreModel implements ScoreModelI, ViewBasedAnalysisI +public class FeatureDistanceModel implements DistanceModelI, ViewBasedAnalysisI { jalview.api.FeatureRenderer fr; diff --git a/src/jalview/analysis/scoremodels/PIDScoreModel.java b/src/jalview/analysis/scoremodels/PIDDistanceModel.java similarity index 92% rename from src/jalview/analysis/scoremodels/PIDScoreModel.java rename to src/jalview/analysis/scoremodels/PIDDistanceModel.java index e0e8634..f72b0fc 100644 --- a/src/jalview/analysis/scoremodels/PIDScoreModel.java +++ b/src/jalview/analysis/scoremodels/PIDDistanceModel.java @@ -20,18 +20,18 @@ */ package jalview.analysis.scoremodels; -import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.DistanceModelI; import jalview.datamodel.AlignmentView; import jalview.util.Comparison; -public class PIDScoreModel implements ScoreModelI +public class PIDDistanceModel implements DistanceModelI { @Override public float[][] findDistances(AlignmentView seqData) { String[] sequenceString = seqData - .getSequenceStrings(Comparison.GapChars.charAt(0)); + .getSequenceStrings(Comparison.GAP_SPACE); int noseqs = sequenceString.length; float[][] distance = new float[noseqs][noseqs]; for (int i = 0; i < (noseqs - 1); i++) diff --git a/src/jalview/analysis/scoremodels/PairwiseSeqScoreModel.java b/src/jalview/analysis/scoremodels/PairwiseDistanceModel.java similarity index 59% rename from src/jalview/analysis/scoremodels/PairwiseSeqScoreModel.java rename to src/jalview/analysis/scoremodels/PairwiseDistanceModel.java index f980d8e..cb9ad07 100644 --- a/src/jalview/analysis/scoremodels/PairwiseSeqScoreModel.java +++ b/src/jalview/analysis/scoremodels/PairwiseDistanceModel.java @@ -20,22 +20,41 @@ */ package jalview.analysis.scoremodels; -import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.DistanceModelI; import jalview.datamodel.AlignmentView; import jalview.util.Comparison; -public abstract class PairwiseSeqScoreModel implements ScoreModelI +public class PairwiseDistanceModel implements DistanceModelI { - abstract public float getPairwiseScore(char c, char d); + PairwiseScoreModelI scoreModel; + /** + * Constructor given something to provide pairwise scores for residues + * + * @param sm + */ + public PairwiseDistanceModel(PairwiseScoreModelI sm) + { + scoreModel = sm; + } + + /** + * Returns a matrix of [i][j] values representing distances between pairs of + * sequences + */ @Override public float[][] findDistances(AlignmentView seqData) { String[] sequenceString = seqData - .getSequenceStrings(Comparison.GapChars.charAt(0)); + .getSequenceStrings(Comparison.GAP_SPACE); int noseqs = sequenceString.length; float[][] distance = new float[noseqs][noseqs]; + /* + * calculate similarity scores for the upper half of the matrix + * as [i, j] = the sum of pairwise scores of corresponding + * positions of sequence[i] and sequence[j] + */ float maxscore = 0; int end = sequenceString[0].length(); for (int i = 0; i < (noseqs - 1); i++) @@ -48,7 +67,8 @@ public abstract class PairwiseSeqScoreModel implements ScoreModelI { try { - score += getPairwiseScore(sequenceString[i].charAt(k), + score += scoreModel.getPairwiseScore( + sequenceString[i].charAt(k), sequenceString[j].charAt(k)); } catch (Exception ex) { @@ -66,6 +86,12 @@ public abstract class PairwiseSeqScoreModel implements ScoreModelI } } + /* + * subtract similarity scores from the maximum value to + * convert to a distance measure; also populate the lower + * half of the result matrix with this value + */ + // FIXME this assumes the score matrix is symmetric - it may not be? for (int i = 0; i < (noseqs - 1); i++) { for (int j = i; j < noseqs; j++) @@ -77,5 +103,26 @@ public abstract class PairwiseSeqScoreModel implements ScoreModelI return distance; } - abstract public float[][] getMatrix(); + @Override + public String getName() + { + return scoreModel.getName(); + } + + @Override + public boolean isDNA() + { + return scoreModel.isDNA(); + } + + @Override + public boolean isProtein() + { + return scoreModel.isProtein(); + } + + public PairwiseScoreModelI getScoreModel() + { + return scoreModel; + } } diff --git a/src/jalview/analysis/scoremodels/PairwiseScoreModelI.java b/src/jalview/analysis/scoremodels/PairwiseScoreModelI.java new file mode 100644 index 0000000..8acedf0 --- /dev/null +++ b/src/jalview/analysis/scoremodels/PairwiseScoreModelI.java @@ -0,0 +1,42 @@ +package jalview.analysis.scoremodels; + +/** + * An interface that describes classes that can compute similarity (aka + * substitution) scores for pairs of residues + */ +public interface PairwiseScoreModelI +{ + /** + * Answers a similarity score between two sequence characters (for + * substitution of the first by the second). Typically the highest scores are + * for identity, and the lowest for substitution of a residue by one with very + * different properties. + * + * @param c + * @param d + * @return + */ + abstract public float getPairwiseScore(char c, char d); + + /** + * Returns a readable name for the model, suitable for display in menus + * + * @return + */ + String getName(); + + /** + * Answers true if the model is applicable to nucleotide data + * + * @return + */ + boolean isDNA(); + + /** + * Answers true if the model is applicable to peptide data + * + * @return + */ + boolean isProtein(); + +} diff --git a/src/jalview/analysis/scoremodels/SWScoreModel.java b/src/jalview/analysis/scoremodels/SWDistanceModel.java similarity index 91% rename from src/jalview/analysis/scoremodels/SWScoreModel.java rename to src/jalview/analysis/scoremodels/SWDistanceModel.java index d5d998e..f63ee13 100644 --- a/src/jalview/analysis/scoremodels/SWScoreModel.java +++ b/src/jalview/analysis/scoremodels/SWDistanceModel.java @@ -21,19 +21,19 @@ package jalview.analysis.scoremodels; import jalview.analysis.AlignSeq; -import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.DistanceModelI; import jalview.datamodel.AlignmentView; import jalview.datamodel.SequenceI; import jalview.util.Comparison; -public class SWScoreModel implements ScoreModelI +public class SWDistanceModel implements DistanceModelI { @Override public float[][] findDistances(AlignmentView seqData) { SequenceI[] sequenceString = seqData.getVisibleAlignment( - Comparison.GapChars.charAt(0)).getSequencesArray(); + Comparison.GAP_SPACE).getSequencesArray(); int noseqs = sequenceString.length; float[][] distance = new float[noseqs][noseqs]; @@ -48,7 +48,7 @@ public class SWScoreModel implements ScoreModelI as.calcScoreMatrix(); as.traceAlignment(); as.printAlignment(System.out); - distance[i][j] = (float) as.maxscore; + distance[i][j] = as.maxscore; if (max < distance[i][j]) { @@ -87,6 +87,7 @@ public class SWScoreModel implements ScoreModelI return true; } + @Override public String toString() { return "Score between two sequences aligned with Smith Waterman with default Peptide/Nucleotide matrix"; diff --git a/src/jalview/analysis/scoremodels/ScoreMatrix.java b/src/jalview/analysis/scoremodels/ScoreMatrix.java index baa18e9..51d8276 100644 --- a/src/jalview/analysis/scoremodels/ScoreMatrix.java +++ b/src/jalview/analysis/scoremodels/ScoreMatrix.java @@ -22,7 +22,7 @@ package jalview.analysis.scoremodels; import java.util.Arrays; -public class ScoreMatrix extends PairwiseSeqScoreModel +public class ScoreMatrix implements PairwiseScoreModelI { public static final short UNMAPPED = (short) -1; @@ -141,25 +141,53 @@ public class ScoreMatrix extends PairwiseSeqScoreModel return peptide; } - @Override + /** + * Returns the score matrix as used in getPairwiseScore. If using this matrix + * directly, callers must also call getMatrixIndex in + * order to get the matrix index for each character (symbol). + * + * @return + * @see #getMatrixIndex(char) + */ public float[][] getMatrix() { return matrix; } /** + * Answers the matrix index for a given character, or -1 if unmapped in the + * matrix. Use this method only if using getMatrix in order to + * compute scores directly (without symbol lookup) for efficiency. + * + * @param c + * @return + * @see #getMatrix() + */ + public int getMatrixIndex(char c) + { + if (c < symbolIndex.length) + { + return symbolIndex[c]; + } + else + { + return UNMAPPED; + } + } + + /** * Returns the pairwise score for substituting c with d, or zero if c or d is * an unscored or unexpected character */ @Override public float getPairwiseScore(char c, char d) { - if (c > MAX_ASCII) + if (c >= symbolIndex.length) { System.err.println(String.format(BAD_ASCII_ERROR, c)); return 0; } - if (d > MAX_ASCII) + if (d >= symbolIndex.length) { System.err.println(String.format(BAD_ASCII_ERROR, d)); return 0; diff --git a/src/jalview/analysis/scoremodels/ScoreModels.java b/src/jalview/analysis/scoremodels/ScoreModels.java index 2419997..043e6fb 100644 --- a/src/jalview/analysis/scoremodels/ScoreModels.java +++ b/src/jalview/analysis/scoremodels/ScoreModels.java @@ -1,6 +1,6 @@ package jalview.analysis.scoremodels; -import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.DistanceModelI; import jalview.io.DataSourceType; import jalview.io.FileParse; import jalview.io.ScoreMatrixFile; @@ -18,9 +18,11 @@ public class ScoreModels private final ScoreMatrix PAM250; + private final ScoreMatrix DNA; + private static ScoreModels instance = new ScoreModels(); - private Map models; + private Map models; public static ScoreModels getInstance() { @@ -44,13 +46,15 @@ public class ScoreModels /* * using LinkedHashMap keeps models ordered as added */ - models = new LinkedHashMap(); + models = new LinkedHashMap(); BLOSUM62 = loadScoreMatrix("scoreModel/blosum62.scm"); PAM250 = loadScoreMatrix("scoreModel/pam250.scm"); - loadScoreMatrix("scoreModel/dna.scm"); loadScoreMatrix("scoreModel/seqspace.scm"); - registerScoreModel(new FeatureScoreModel()); - registerScoreModel(new PIDScoreModel()); + // drop seqspace.scm for IdentityScoreModel once JAL-2379 merged in? + // registerScoreModel(new IdentityScoreModel()); + DNA = loadScoreMatrix("scoreModel/dna.scm"); + registerScoreModel(new FeatureDistanceModel()); + registerScoreModel(new PIDDistanceModel()); } /** @@ -80,24 +84,34 @@ public class ScoreModels } /** + * Registers a pairwise score model + * + * @param sm + */ + public void registerScoreModel(PairwiseScoreModelI sm) + { + registerScoreModel(new PairwiseDistanceModel(sm)); + } + + /** * Answers an iterable set of the registered score models. Currently these are * returned in the order in which they were registered. * * @return */ - public Iterable getModels() + public Iterable getModels() { return models.values(); } - public ScoreModelI forName(String s) + public DistanceModelI forName(String s) { return models.get(s); } - public void registerScoreModel(ScoreModelI sm) + public void registerScoreModel(DistanceModelI sm) { - ScoreModelI sm2 = models.get(sm.getName()); + DistanceModelI sm2 = models.get(sm.getName()); if (sm2 != null) { System.err.println("Warning: replacing score model " + sm2.getName()); @@ -112,10 +126,9 @@ public class ScoreModels * @param forPeptide * @return */ - public PairwiseSeqScoreModel getDefaultModel(boolean forPeptide) + public ScoreMatrix getDefaultModel(boolean forPeptide) { - return (PairwiseSeqScoreModel) (forPeptide ? forName("BLOSUM62") - : forName("DNA")); + return forPeptide ? BLOSUM62 : DNA; } public ScoreMatrix getBlosum62() diff --git a/src/jalview/api/analysis/ScoreModelI.java b/src/jalview/api/analysis/DistanceModelI.java similarity index 89% rename from src/jalview/api/analysis/ScoreModelI.java rename to src/jalview/api/analysis/DistanceModelI.java index 332bba5..3ceeed2 100644 --- a/src/jalview/api/analysis/ScoreModelI.java +++ b/src/jalview/api/analysis/DistanceModelI.java @@ -22,7 +22,11 @@ package jalview.api.analysis; import jalview.datamodel.AlignmentView; -public interface ScoreModelI +/** + * An interface that describes classes that can compute distances between pairs + * of sequences in an alignment + */ +public interface DistanceModelI { float[][] findDistances(AlignmentView seqData); diff --git a/src/jalview/appletgui/TreePanel.java b/src/jalview/appletgui/TreePanel.java index d3e6213..9ac6773 100644 --- a/src/jalview/appletgui/TreePanel.java +++ b/src/jalview/appletgui/TreePanel.java @@ -22,7 +22,7 @@ package jalview.appletgui; import jalview.analysis.NJTree; import jalview.analysis.scoremodels.ScoreModels; -import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.DistanceModelI; import jalview.api.analysis.ViewBasedAnalysisI; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentView; @@ -237,7 +237,7 @@ public class TreePanel extends EmbmenuFrame implements ActionListener, seqs = av.getSelectionGroup().getSequencesInOrder( av.getAlignment()); } - ScoreModelI sm = ScoreModels.getInstance().forName(pwtype); + DistanceModelI sm = ScoreModels.getInstance().forName(pwtype); if (sm instanceof ViewBasedAnalysisI) { try diff --git a/src/jalview/datamodel/BinarySequence.java b/src/jalview/datamodel/BinarySequence.java index 90b8be7..da41c44 100755 --- a/src/jalview/datamodel/BinarySequence.java +++ b/src/jalview/datamodel/BinarySequence.java @@ -116,20 +116,20 @@ public class BinarySequence extends Sequence /** * ancode using substitution matrix given in matrix * - * @param matrix + * @param smtrx */ - public void matrixEncode(final ScoreMatrix matrix) + public void matrixEncode(final ScoreMatrix smtrx) throws InvalidSequenceTypeException { - if (isNa != matrix.isDNA()) + if (isNa != smtrx.isDNA()) { throw new InvalidSequenceTypeException("matrix " - + matrix.getClass().getCanonicalName() + + smtrx.getClass().getCanonicalName() + " is not a valid matrix for " + (isNa ? "nucleotide" : "protein") + "sequences"); } - matrixEncode(matrix.isDNA() ? ResidueProperties.nucleotideIndex - : ResidueProperties.aaIndex, matrix.getMatrix()); + matrixEncode(smtrx.isDNA() ? ResidueProperties.nucleotideIndex + : ResidueProperties.aaIndex, smtrx.getMatrix()); } private void matrixEncode(final int[] aaIndex, final float[][] matrix) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 1162c53..5f0e5d3 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -35,7 +35,7 @@ import jalview.api.AlignmentViewPanel; import jalview.api.FeatureSettingsControllerI; import jalview.api.SplitContainerI; import jalview.api.ViewStyleI; -import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.DistanceModelI; import jalview.bin.Cache; import jalview.bin.Jalview; import jalview.commands.CommandI; @@ -5638,7 +5638,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, ColourMenuHelper.setColourSelected(colourMenu, schemeName); } - public void newTreePanel(String treeType, ScoreModelI sm) + public void newTreePanel(String treeType, DistanceModelI sm) { String scoreModelName = sm.getName(); final String ttl = TreePanel.getPanelTitle(treeType, scoreModelName); diff --git a/src/jalview/gui/PCAPanel.java b/src/jalview/gui/PCAPanel.java index f96d464..d053468 100644 --- a/src/jalview/gui/PCAPanel.java +++ b/src/jalview/gui/PCAPanel.java @@ -20,9 +20,9 @@ */ package jalview.gui; -import jalview.analysis.scoremodels.ScoreMatrix; +import jalview.analysis.scoremodels.PairwiseDistanceModel; import jalview.analysis.scoremodels.ScoreModels; -import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.DistanceModelI; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentView; @@ -157,9 +157,9 @@ public class PCAPanel extends GPCAPanel implements Runnable, protected void scoreMatrix_menuSelected() { scoreMatrixMenu.removeAll(); - for (ScoreModelI sm : ScoreModels.getInstance().getModels()) + for (DistanceModelI sm : ScoreModels.getInstance().getModels()) { - if (sm instanceof ScoreMatrix) + if (sm instanceof PairwiseDistanceModel) { final String name = sm.getName(); // create an entry for this score matrix for use in PCA @@ -167,8 +167,8 @@ public class PCAPanel extends GPCAPanel implements Runnable, jm.setText(MessageManager.getStringOrReturn("label.score_model_", name)); jm.setSelected(pcaModel.getScore_matrix().equals(name)); - if ((!pcaModel.isNucleotide() && !sm.isDNA()) - || (pcaModel.isNucleotide() && sm.isDNA())) + if ((pcaModel.isNucleotide() && sm.isDNA()) + || (!pcaModel.isNucleotide() && sm.isProtein())) { jm.addActionListener(new ActionListener() { diff --git a/src/jalview/gui/TreeChooser.java b/src/jalview/gui/TreeChooser.java index 8e2bff0..55e6650 100644 --- a/src/jalview/gui/TreeChooser.java +++ b/src/jalview/gui/TreeChooser.java @@ -22,7 +22,7 @@ package jalview.gui; import jalview.analysis.NJTree; import jalview.analysis.scoremodels.ScoreModels; -import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.DistanceModelI; import jalview.util.MessageManager; import java.awt.Color; @@ -86,7 +86,7 @@ public class TreeChooser extends JPanel matrixNames = new JComboBox(); ScoreModels scoreModels = ScoreModels.getInstance(); - for (ScoreModelI sm : scoreModels.getModels()) + for (DistanceModelI sm : scoreModels.getModels()) { boolean nucleotide = af.getViewport().getAlignment().isNucleotide(); if (sm.isDNA() && nucleotide || sm.isProtein() && !nucleotide) @@ -151,7 +151,7 @@ public class TreeChooser extends JPanel frame.setClosed(true); String treeType = neighbourJoining.isSelected() ? NJTree.NEIGHBOUR_JOINING : NJTree.AVERAGE_DISTANCE; - ScoreModelI sm = ScoreModels.getInstance().forName( + DistanceModelI sm = ScoreModels.getInstance().forName( matrixNames.getSelectedItem().toString()); af.newTreePanel(treeType, sm); } catch (Exception ex) diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java index 7df1f71..13e2360 100755 --- a/src/jalview/gui/TreePanel.java +++ b/src/jalview/gui/TreePanel.java @@ -23,7 +23,7 @@ package jalview.gui; import jalview.analysis.AlignmentSorter; import jalview.analysis.NJTree; import jalview.analysis.scoremodels.ScoreModels; -import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.DistanceModelI; import jalview.api.analysis.ViewBasedAnalysisI; import jalview.bin.Cache; import jalview.commands.CommandI; @@ -300,7 +300,7 @@ public class TreePanel extends GTreePanel seqs = av.getSelectionGroup().getSequencesInOrder( av.getAlignment()); } - ScoreModelI sm = ScoreModels.getInstance().forName(pwtype); + DistanceModelI sm = ScoreModels.getInstance().forName(pwtype); if (sm instanceof ViewBasedAnalysisI) { try diff --git a/src/jalview/schemes/Blosum62ColourScheme.java b/src/jalview/schemes/Blosum62ColourScheme.java index 58e12b7..8ac8731 100755 --- a/src/jalview/schemes/Blosum62ColourScheme.java +++ b/src/jalview/schemes/Blosum62ColourScheme.java @@ -20,7 +20,7 @@ */ package jalview.schemes; -import jalview.analysis.scoremodels.PairwiseSeqScoreModel; +import jalview.analysis.scoremodels.PairwiseScoreModelI; import jalview.analysis.scoremodels.ScoreModels; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.SequenceCollectionI; @@ -55,7 +55,7 @@ public class Blosum62ColourScheme extends ResidueColourScheme public Color findColour(char res, int j, SequenceI seq, String consensusResidue, float pid) { - PairwiseSeqScoreModel sm = ScoreModels.getInstance().getBlosum62(); + PairwiseScoreModelI sm = ScoreModels.getInstance().getBlosum62(); /* * compare as upper case; note consensusResidue is @@ -84,7 +84,6 @@ public class Blosum62ColourScheme extends ResidueColourScheme for (char consensus : consensusResidue.toCharArray()) { score += sm.getPairwiseScore(consensus, res); - // score += ResidueProperties.getBLOSUM62(consensus, res); } if (score > 0) diff --git a/src/jalview/ws/sifts/SiftsClient.java b/src/jalview/ws/sifts/SiftsClient.java index a066915..df5aee9 100644 --- a/src/jalview/ws/sifts/SiftsClient.java +++ b/src/jalview/ws/sifts/SiftsClient.java @@ -21,7 +21,7 @@ package jalview.ws.sifts; import jalview.analysis.AlignSeq; -import jalview.analysis.scoremodels.PairwiseSeqScoreModel; +import jalview.analysis.scoremodels.ScoreMatrix; import jalview.analysis.scoremodels.ScoreModels; import jalview.api.DBRefEntryI; import jalview.api.SiftsClientI; @@ -988,7 +988,7 @@ public class SiftsClient implements SiftsClientI output.append(String.valueOf(pdbEnd)); output.append(NEWLINE).append(NEWLINE); - PairwiseSeqScoreModel pam250 = ScoreModels.getInstance().getPam250(); + ScoreMatrix pam250 = ScoreModels.getInstance().getPam250(); int matchedSeqCount = 0; for (int j = 0; j < nochunks; j++) { diff --git a/test/jalview/analysis/scoremodels/FeatureScoreModelTest.java b/test/jalview/analysis/scoremodels/FeatureDistanceModelTest.java similarity index 97% rename from test/jalview/analysis/scoremodels/FeatureScoreModelTest.java rename to test/jalview/analysis/scoremodels/FeatureDistanceModelTest.java index 14254f7..8b84829 100644 --- a/test/jalview/analysis/scoremodels/FeatureScoreModelTest.java +++ b/test/jalview/analysis/scoremodels/FeatureDistanceModelTest.java @@ -36,7 +36,7 @@ import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -public class FeatureScoreModelTest +public class FeatureDistanceModelTest { @BeforeClass(alwaysRun = true) @@ -106,7 +106,7 @@ public class FeatureScoreModelTest public void testFeatureScoreModel() throws Exception { AlignFrame alf = getTestAlignmentFrame(); - FeatureScoreModel fsm = new FeatureScoreModel(); + FeatureDistanceModel fsm = new FeatureDistanceModel(); Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView() .getAlignPanel())); alf.selectAllSequenceMenuItem_actionPerformed(null); @@ -125,7 +125,7 @@ public class FeatureScoreModelTest AlignFrame alf = getTestAlignmentFrame(); // hiding first two columns shouldn't affect the tree alf.getViewport().hideColumns(0, 1); - FeatureScoreModel fsm = new FeatureScoreModel(); + FeatureDistanceModel fsm = new FeatureDistanceModel(); Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView() .getAlignPanel())); alf.selectAllSequenceMenuItem_actionPerformed(null); @@ -144,7 +144,7 @@ public class FeatureScoreModelTest // hide columns and check tree changes alf.getViewport().hideColumns(3, 4); alf.getViewport().hideColumns(0, 1); - FeatureScoreModel fsm = new FeatureScoreModel(); + FeatureDistanceModel fsm = new FeatureDistanceModel(); Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView() .getAlignPanel())); alf.selectAllSequenceMenuItem_actionPerformed(null); @@ -240,7 +240,7 @@ public class FeatureScoreModelTest alf.setShowSeqFeatures(true); alf.getFeatureRenderer().findAllFeatures(true); - FeatureScoreModel fsm = new FeatureScoreModel(); + FeatureDistanceModel fsm = new FeatureDistanceModel(); Assert.assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView() .getAlignPanel())); alf.selectAllSequenceMenuItem_actionPerformed(null); diff --git a/test/jalview/analysis/scoremodels/ScoreMatrixTest.java b/test/jalview/analysis/scoremodels/ScoreMatrixTest.java index cbc834d..fcc0bc3 100644 --- a/test/jalview/analysis/scoremodels/ScoreMatrixTest.java +++ b/test/jalview/analysis/scoremodels/ScoreMatrixTest.java @@ -56,4 +56,23 @@ public class ScoreMatrixTest } } } + + @Test(groups = "Functional") + public void testGetMatrixIndex() + { + ScoreMatrix sm = ScoreModels.getInstance().getBlosum62(); + assertEquals(sm.getMatrixIndex('A'), 0); + assertEquals(sm.getMatrixIndex('R'), 1); + assertEquals(sm.getMatrixIndex('r'), 1); + assertEquals(sm.getMatrixIndex('N'), 2); + assertEquals(sm.getMatrixIndex('D'), 3); + assertEquals(sm.getMatrixIndex('X'), 22); + assertEquals(sm.getMatrixIndex('x'), 22); + assertEquals(sm.getMatrixIndex(' '), 23); + assertEquals(sm.getMatrixIndex('*'), 24); + assertEquals(sm.getMatrixIndex('.'), -1); + assertEquals(sm.getMatrixIndex('-'), -1); + assertEquals(sm.getMatrixIndex('?'), -1); + assertEquals(sm.getMatrixIndex((char) 128), -1); + } } diff --git a/test/jalview/analysis/scoremodels/ScoreModelsTest.java b/test/jalview/analysis/scoremodels/ScoreModelsTest.java index 2ebbe5c..c5c8673 100644 --- a/test/jalview/analysis/scoremodels/ScoreModelsTest.java +++ b/test/jalview/analysis/scoremodels/ScoreModelsTest.java @@ -4,7 +4,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; -import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.DistanceModelI; import java.util.Iterator; @@ -19,40 +19,45 @@ public class ScoreModelsTest @Test public void testConstructor() { - Iterator models = ScoreModels.getInstance().getModels() + Iterator models = ScoreModels.getInstance().getModels() .iterator(); assertTrue(models.hasNext()); /* * models are served in order of addition */ - ScoreModelI sm = models.next(); - assertTrue(sm instanceof ScoreMatrix); + DistanceModelI sm = models.next(); + assertTrue(sm instanceof PairwiseDistanceModel); assertEquals(sm.getName(), "BLOSUM62"); - assertEquals(((ScoreMatrix) sm).getPairwiseScore('I', 'R'), -3f); + assertEquals(((PairwiseDistanceModel) sm).getScoreModel() + .getPairwiseScore('I', 'R'), -3f); sm = models.next(); - assertTrue(sm instanceof ScoreMatrix); + assertTrue(sm instanceof PairwiseDistanceModel); assertEquals(sm.getName(), "PAM250"); - assertEquals(((ScoreMatrix) sm).getPairwiseScore('R', 'C'), -4f); + assertEquals(((PairwiseDistanceModel) sm).getScoreModel() + .getPairwiseScore('R', 'C'), -4f); sm = models.next(); - assertTrue(sm instanceof ScoreMatrix); + assertTrue(sm instanceof PairwiseDistanceModel); assertEquals(sm.getName(), "Identity (SeqSpace)"); - assertEquals(((ScoreMatrix) sm).getPairwiseScore('R', 'C'), 0f); - assertEquals(((ScoreMatrix) sm).getPairwiseScore('R', 'r'), 1f); + assertEquals(((PairwiseDistanceModel) sm).getScoreModel() + .getPairwiseScore('R', 'C'), 0f); + assertEquals(((PairwiseDistanceModel) sm).getScoreModel() + .getPairwiseScore('R', 'r'), 1f); sm = models.next(); - assertTrue(sm instanceof ScoreMatrix); + assertTrue(sm instanceof PairwiseDistanceModel); assertEquals(sm.getName(), "DNA"); - assertEquals(((ScoreMatrix) sm).getPairwiseScore('c', 'x'), 1f); + assertEquals(((PairwiseDistanceModel) sm).getScoreModel() + .getPairwiseScore('c', 'x'), 1f); sm = models.next(); - assertFalse(sm instanceof ScoreMatrix); + assertFalse(sm instanceof PairwiseDistanceModel); assertEquals(sm.getName(), "Sequence Feature Similarity"); sm = models.next(); - assertFalse(sm instanceof ScoreMatrix); + assertFalse(sm instanceof PairwiseDistanceModel); assertEquals(sm.getName(), "PID"); } } diff --git a/test/jalview/schemes/ScoreMatrixPrinter.java b/test/jalview/schemes/ScoreMatrixPrinter.java index b58b56f..aed4086 100644 --- a/test/jalview/schemes/ScoreMatrixPrinter.java +++ b/test/jalview/schemes/ScoreMatrixPrinter.java @@ -22,7 +22,7 @@ package jalview.schemes; import jalview.analysis.scoremodels.ScoreMatrix; import jalview.analysis.scoremodels.ScoreModels; -import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.DistanceModelI; import jalview.gui.JvOptionPane; import org.testng.annotations.BeforeClass; @@ -41,7 +41,7 @@ public class ScoreMatrixPrinter @Test(groups = { "Functional" }) public void printAllMatrices() { - for (ScoreModelI sm : ScoreModels.getInstance().getModels()) + for (DistanceModelI sm : ScoreModels.getInstance().getModels()) { System.out.println("Matrix " + sm.getName()); System.out.println(sm.toString()); @@ -51,7 +51,7 @@ public class ScoreMatrixPrinter @Test(groups = { "Functional" }) public void printHTMLMatrices() { - for (ScoreModelI sm : ScoreModels.getInstance().getModels()) + for (DistanceModelI sm : ScoreModels.getInstance().getModels()) { if (sm instanceof ScoreMatrix) {