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