Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / jalview / schemes / ScoreMatrix.js
1 Clazz.declarePackage ("jalview.schemes");
2 Clazz.load (["jalview.analysis.scoremodels.PairwiseSeqScoreModel", "jalview.api.analysis.ScoreModelI"], "jalview.schemes.ScoreMatrix", ["jalview.schemes.ResidueProperties", "java.lang.StringBuffer"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.name = null;
5 this.matrix = null;
6 this.type = 0;
7 Clazz.instantialize (this, arguments);
8 }, jalview.schemes, "ScoreMatrix", jalview.analysis.scoremodels.PairwiseSeqScoreModel, jalview.api.analysis.ScoreModelI);
9 Clazz.overrideMethod (c$, "getName", 
10 function () {
11 return this.name;
12 });
13 Clazz.makeConstructor (c$, 
14 function (name, matrix, type) {
15 Clazz.superConstructor (this, jalview.schemes.ScoreMatrix, []);
16 this.matrix = matrix;
17 this.type = type;
18 this.name = name;
19 }, "~S,~A,~N");
20 Clazz.overrideMethod (c$, "isDNA", 
21 function () {
22 return this.type == 1;
23 });
24 Clazz.overrideMethod (c$, "isProtein", 
25 function () {
26 return this.type == 0;
27 });
28 Clazz.overrideMethod (c$, "getMatrix", 
29 function () {
30 return this.matrix;
31 });
32 Clazz.defineMethod (c$, "getPairwiseScore", 
33 function (A1, A2) {
34 return this.getPairwiseScore (A1.charAt (0), A2.charAt (0));
35 }, "~S,~S");
36 Clazz.defineMethod (c$, "getPairwiseScore", 
37 function (c, d) {
38 var pog = 0;
39 try {
40 var a = (this.type == 0) ? jalview.schemes.ResidueProperties.aaIndex[c.charCodeAt (0)] : jalview.schemes.ResidueProperties.nucleotideIndex[c.charCodeAt (0)];
41 var b = (this.type == 0) ? jalview.schemes.ResidueProperties.aaIndex[d.charCodeAt (0)] : jalview.schemes.ResidueProperties.nucleotideIndex[d.charCodeAt (0)];
42 pog = this.matrix[a][b];
43 } catch (e) {
44 if (Clazz.exceptionOf (e, Exception)) {
45 } else {
46 throw e;
47 }
48 }
49 return pog;
50 }, "~S,~S");
51 Clazz.overrideMethod (c$, "toString", 
52 function () {
53 return this.outputMatrix (false);
54 });
55 Clazz.defineMethod (c$, "outputMatrix", 
56 function (html) {
57 var sb =  new StringBuffer ();
58 var symbols = (this.type == 0) ? jalview.schemes.ResidueProperties.aaIndex : jalview.schemes.ResidueProperties.nucleotideIndex;
59 var symMax = (this.type == 0) ? 23 : 10;
60 var header = true;
61 if (html) {
62 sb.append ("<table border=\"1\">");
63 }for (var sym = 'A'; sym <= 'Z'; sym = String.fromCharCode (sym.charCodeAt (0) + 1)) {
64 if (symbols[sym.charCodeAt (0)] >= 0 && symbols[sym.charCodeAt (0)] < symMax) {
65 if (header) {
66 sb.append (html ? "<tr><td></td>" : "");
67 for (var sym2 = 'A'; sym2 <= 'Z'; sym2 = String.fromCharCode (sym2.charCodeAt (0) + 1)) {
68 if (symbols[sym2.charCodeAt (0)] >= 0 && symbols[sym2.charCodeAt (0)] < symMax) {
69 sb.append ((html ? "<td>&nbsp;" : "\t") + sym2 + (html ? "&nbsp;</td>" : ""));
70 }}
71 header = false;
72 sb.append (html ? "</tr>\n" : "\n");
73 }if (html) {
74 sb.append ("<tr>");
75 }sb.append ((html ? "<td>" : "") + sym + (html ? "</td>" : ""));
76 for (var sym2 = 'A'; sym2 <= 'Z'; sym2 = String.fromCharCode (sym2.charCodeAt (0) + 1)) {
77 if (symbols[sym2.charCodeAt (0)] >= 0 && symbols[sym2.charCodeAt (0)] < symMax) {
78 sb.append ((html ? "<td>" : "\t") + this.matrix[symbols[sym.charCodeAt (0)]][symbols[sym2.charCodeAt (0)]] + (html ? "</td>" : ""));
79 }}
80 sb.append (html ? "</tr>\n" : "\n");
81 }}
82 if (html) {
83 sb.append ("</table>");
84 }return sb.toString ();
85 }, "~B");
86 });