2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.schemes;
23 import jalview.analysis.scoremodels.PairwiseSeqScoreModel;
24 import jalview.api.analysis.ScoreModelI;
26 public class ScoreMatrix extends PairwiseSeqScoreModel implements
32 public String getName()
38 * reference to integer score matrix
43 * 0 for Protein Score matrix. 1 for dna score matrix
50 * Unique, human readable name for the matrix
52 * Pairwise scores indexed according to appropriate symbol alphabet
54 * 0 for Protein, 1 for NA
56 ScoreMatrix(String name, int[][] matrix, int type)
64 public boolean isDNA()
70 public boolean isProtein()
76 public int[][] getMatrix()
85 * @return score for substituting first char in A1 with first char in A2
87 public int getPairwiseScore(String A1, String A2)
89 return getPairwiseScore(A1.charAt(0), A2.charAt(0));
92 public int getPairwiseScore(char c, char d)
98 int a = (type == 0) ? ResidueProperties.aaIndex[c]
99 : ResidueProperties.nucleotideIndex[c];
100 int b = (type == 0) ? ResidueProperties.aaIndex[d]
101 : ResidueProperties.nucleotideIndex[d];
104 } catch (Exception e)
106 // System.out.println("Unknown residue in " + A1 + " " + A2);
113 * pretty print the matrix
115 public String toString()
117 return outputMatrix(false);
120 public String outputMatrix(boolean html)
122 StringBuffer sb = new StringBuffer();
123 int[] symbols = (type == 0) ? ResidueProperties.aaIndex
124 : ResidueProperties.nucleotideIndex;
125 int symMax = (type == 0) ? ResidueProperties.maxProteinIndex
126 : ResidueProperties.maxNucleotideIndex;
127 boolean header = true;
130 sb.append("<table border=\"1\">");
132 for (char sym = 'A'; sym <= 'Z'; sym++)
134 if (symbols[sym] >= 0 && symbols[sym] < symMax)
138 sb.append(html ? "<tr><td></td>" : "");
139 for (char sym2 = 'A'; sym2 <= 'Z'; sym2++)
141 if (symbols[sym2] >= 0 && symbols[sym2] < symMax)
143 sb.append((html ? "<td> " : "\t") + sym2
144 + (html ? " </td>" : ""));
148 sb.append(html ? "</tr>\n" : "\n");
154 sb.append((html ? "<td>" : "") + sym + (html ? "</td>" : ""));
155 for (char sym2 = 'A'; sym2 <= 'Z'; sym2++)
157 if (symbols[sym2] >= 0 && symbols[sym2] < symMax)
159 sb.append((html ? "<td>" : "\t")
160 + matrix[symbols[sym]][symbols[sym2]]
161 + (html ? "</td>" : ""));
164 sb.append(html ? "</tr>\n" : "\n");
169 sb.append("</table>");
171 return sb.toString();