69a0922e37c55c2e3f32efe72109b574825ea9a1
[jalview.git] / src / jalview / schemes / ScoreMatrix.java
1 package jalview.schemes;\r
2 \r
3 public class ScoreMatrix\r
4 {\r
5   String name;\r
6   /**\r
7    * reference to integer score matrix\r
8    */\r
9   int[][] matrix;\r
10   /**\r
11    * 0 for Protein Score matrix. 1 for dna score matrix\r
12    */\r
13   int type;\r
14   ScoreMatrix(String name, int[][] matrix, int type)\r
15   {\r
16     this.matrix = matrix;\r
17     this.type = type;\r
18   }\r
19 \r
20   public boolean isDNA()\r
21   {\r
22     return type == 1;\r
23   }\r
24 \r
25   public boolean isProtein()\r
26   {\r
27     return type == 0;\r
28   }\r
29 \r
30   public int[][] getMatrix()\r
31   {\r
32     return matrix;\r
33   }\r
34 \r
35   /**\r
36    *\r
37    * @param A1\r
38    * @param A2\r
39    * @return score for substituting first char in A1 with first char in A2\r
40    */\r
41   public int getPairwiseScore(String A1, String A2)\r
42   {\r
43     return getPairwiseScore(A1.charAt(0), A2.charAt(0));\r
44   }\r
45 \r
46   public int getPairwiseScore(char c, char d)\r
47   {\r
48     int pog = 0;\r
49 \r
50     try\r
51     {\r
52       int a = (type == 0) ? ResidueProperties.aaIndex[c] :\r
53           ResidueProperties.nucleotideIndex[c];\r
54       int b = (type == 0) ? ResidueProperties.aaIndex[d] :\r
55           ResidueProperties.nucleotideIndex[d];\r
56 \r
57       pog = matrix[a][b];\r
58     }\r
59     catch (Exception e)\r
60     {\r
61       //System.out.println("Unknown residue in " + A1 + " " + A2);\r
62     }\r
63 \r
64     return pog;\r
65   }\r
66 \r
67 }\r