2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.schemes;
21 import jalview.analysis.scoremodels.PairwiseSeqScoreModel;
22 import jalview.api.analysis.ScoreModelI;
24 public class ScoreMatrix extends PairwiseSeqScoreModel implements ScoreModelI
29 public String getName()
35 * reference to integer score matrix
40 * 0 for Protein Score matrix. 1 for dna score matrix
45 * @param name Unique, human readable name for the matrix
46 * @param matrix Pairwise scores indexed according to appropriate symbol alphabet
47 * @param type 0 for Protein, 1 for NA
49 ScoreMatrix(String name, int[][] matrix, int type)
57 public boolean isDNA()
62 public boolean isProtein()
68 public int[][] getMatrix()
77 * @return score for substituting first char in A1 with first char in A2
79 public int getPairwiseScore(String A1, String A2)
81 return getPairwiseScore(A1.charAt(0), A2.charAt(0));
84 public int getPairwiseScore(char c, char d)
90 int a = (type == 0) ? ResidueProperties.aaIndex[c]
91 : ResidueProperties.nucleotideIndex[c];
92 int b = (type == 0) ? ResidueProperties.aaIndex[d]
93 : ResidueProperties.nucleotideIndex[d];
98 // System.out.println("Unknown residue in " + A1 + " " + A2);
105 * pretty print the matrix
107 public String toString()
109 return outputMatrix(false);
112 public String outputMatrix(boolean html)
114 StringBuffer sb = new StringBuffer();
115 int[] symbols = (type == 0) ? ResidueProperties.aaIndex
116 : ResidueProperties.nucleotideIndex;
117 int symMax = (type == 0) ? ResidueProperties.maxProteinIndex
118 : ResidueProperties.maxNucleotideIndex;
119 boolean header = true;
122 sb.append("<table>");
124 for (char sym = 'A'; sym <= 'Z'; sym++)
126 if (symbols[sym] >= 0 && symbols[sym] < symMax)
130 sb.append(html ? "<tr><td></td>" : "");
131 for (char sym2 = 'A'; sym2 <= 'Z'; sym2++)
133 if (symbols[sym2] >= 0 && symbols[sym2] < symMax)
135 sb.append((html ? "<td> " : "\t") + sym2
136 + (html ? " </td>" : ""));
140 sb.append(html ? "</tr>\n" : "\n");
146 sb.append((html ? "<td>" : "") + sym + (html ? "</td>" : ""));
147 for (char sym2 = 'A'; sym2 <= 'Z'; sym2++)
149 if (symbols[sym2] >= 0 && symbols[sym2] < symMax)
151 sb.append((html ? "<td>" : "\t")
152 + matrix[symbols[sym]][symbols[sym2]]
153 + (html ? "</td>" : ""));
156 sb.append(html ? "</tr>\n" : "\n");
161 sb.append("</table>");
163 return sb.toString();