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 public class ScoreMatrix
26 * reference to integer score matrix
31 * 0 for Protein Score matrix. 1 for dna score matrix
35 ScoreMatrix(String name, int[][] matrix, int type)
41 public boolean isDNA()
46 public boolean isProtein()
51 public int[][] getMatrix()
60 * @return score for substituting first char in A1 with first char in A2
62 public int getPairwiseScore(String A1, String A2)
64 return getPairwiseScore(A1.charAt(0), A2.charAt(0));
67 public int getPairwiseScore(char c, char d)
73 int a = (type == 0) ? ResidueProperties.aaIndex[c]
74 : ResidueProperties.nucleotideIndex[c];
75 int b = (type == 0) ? ResidueProperties.aaIndex[d]
76 : ResidueProperties.nucleotideIndex[d];
81 // System.out.println("Unknown residue in " + A1 + " " + A2);
88 * pretty print the matrix
90 public String toString()
92 return outputMatrix(false);
95 public String outputMatrix(boolean html)
97 StringBuffer sb = new StringBuffer();
98 int[] symbols = (type == 0) ? ResidueProperties.aaIndex
99 : ResidueProperties.nucleotideIndex;
100 int symMax = (type == 0) ? ResidueProperties.maxProteinIndex
101 : ResidueProperties.maxNucleotideIndex;
102 boolean header = true;
105 sb.append("<table>");
107 for (char sym = 'A'; sym <= 'Z'; sym++)
109 if (symbols[sym] >= 0 && symbols[sym] < symMax)
113 sb.append(html ? "<tr><td></td>" : "");
114 for (char sym2 = 'A'; sym2 <= 'Z'; sym2++)
116 if (symbols[sym2] >= 0 && symbols[sym2] < symMax)
118 sb.append((html ? "<td> " : "\t") + sym2
119 + (html ? " </td>" : ""));
123 sb.append(html ? "</tr>\n" : "\n");
129 sb.append((html ? "<td>" : "") + sym + (html ? "</td>" : ""));
130 for (char sym2 = 'A'; sym2 <= 'Z'; sym2++)
132 if (symbols[sym2] >= 0 && symbols[sym2] < symMax)
134 sb.append((html ? "<td>" : "\t")
135 + matrix[symbols[sym]][symbols[sym2]]
136 + (html ? "</td>" : ""));
139 sb.append(html ? "</tr>\n" : "\n");
144 sb.append("</table>");
146 return sb.toString();