1 Clazz.declarePackage ("jalview.analysis");
2 Clazz.load (null, "jalview.analysis.StructureFrequency", ["jalview.datamodel.Annotation", "jalview.util.Format", "$.QuickSort", "java.lang.Float", "java.util.Hashtable", "javajs.util.AU"], function () {
3 c$ = Clazz.declareType (jalview.analysis, "StructureFrequency");
4 c$.findPair = Clazz.defineMethod (c$, "findPair",
5 function (pairs, indice) {
6 for (var i = 0; i < pairs.length; i++) {
7 if (pairs[i].getBegin () == indice) {
8 return pairs[i].getEnd ();
12 c$.calculate = Clazz.defineMethod (c$, "calculate",
13 function (sequences, start, end, result, profile, rnaStruc) {
16 var struc = rnaStruc.getRNAStruc ().toCharArray ();
17 var rna = rnaStruc._rnasecstr;
26 var jSize = sequences.length;
31 for (i = start; i < end; i++) {
32 residueHash = new java.util.Hashtable ();
34 values = Clazz.newIntArray (255, 0);
35 pairs = Clazz.newIntArray (255, 255, 0);
37 if (i < struc.length) {
41 }if (s == '.' || s == ' ') {
43 }if (s != '(' && s != '[') {
45 values['-'.charCodeAt (0)]++;
47 bpEnd = jalview.analysis.StructureFrequency.findPair (rna, i);
49 for (j = 0; j < jSize; j++) {
50 if (sequences[j] == null) {
51 System.err.println ("WARNING: Consensus skipping null sequence - possible race condition.");
53 }c = sequences[j].getCharAt (i);
54 if (c == '.' || c == ' ') {
57 values['-'.charCodeAt (0)]++;
59 }cEnd = sequences[j].getCharAt (bpEnd);
60 if (jalview.analysis.StructureFrequency.checkBpType (c, cEnd) == true) {
61 values['('.charCodeAt (0)]++;
64 }if (jalview.analysis.StructureFrequency.checkBpType (c, cEnd) == false) {
66 values['['.charCodeAt (0)]++;
68 }pairs[c.charCodeAt (0)][cEnd.charCodeAt (0)]++;
71 residueHash.put ("P", Clazz.newArray (-1, [values, Clazz.newIntArray (-1, [jSize, (jSize - values['-'.charCodeAt (0)])])]));
72 residueHash.put ("B", pairs);
73 }if (wooble == true) {
74 count = values['('.charCodeAt (0)];
75 }if (wooble == false) {
76 count = values['['.charCodeAt (0)];
77 }residueHash.put ("C", new Integer (count));
78 residueHash.put ("R", maxResidue);
79 percentage = (count * 100) / jSize;
80 residueHash.put ("G", new Float (percentage));
81 if (result[i] == null) {
82 result[i] = residueHash;
84 values[')'.charCodeAt (0)] = values['('.charCodeAt (0)];
85 values[']'.charCodeAt (0)] = values['['.charCodeAt (0)];
86 values['('.charCodeAt (0)] = 0;
87 values['['.charCodeAt (0)] = 0;
88 residueHash = new java.util.Hashtable ();
91 }if (wooble == false) {
94 residueHash.put ("P", Clazz.newArray (-1, [values, Clazz.newIntArray (-1, [jSize, (jSize - values['-'.charCodeAt (0)])])]));
95 residueHash.put ("B", pairs);
96 }residueHash.put ("C", new Integer (count));
97 residueHash.put ("R", maxResidue);
98 percentage = (count * 100) / jSize;
99 residueHash.put ("G", new Float (percentage));
100 result[bpEnd] = residueHash;
102 }, "~A,~N,~N,~A,~B,jalview.datamodel.AlignmentAnnotation");
103 c$.checkBpType = Clazz.defineMethod (c$, "checkBpType",
104 function (up, down) {
106 up = String.fromCharCode (up.charCodeAt (0) - 32);
108 down = String.fromCharCode (down.charCodeAt (0) - 32);
153 c$.completeConsensus = Clazz.defineMethod (c$, "completeConsensus",
154 function (consensus, hconsensus, iStart, width, ignoreGapsInConsensusCalculation, includeAllConsSymbols, nseq) {
157 if (consensus == null || consensus.annotations == null || consensus.annotations.length < width) {
159 }var fmtstr = "%3.1f";
166 fmtstr = "%" + (2 + precision) + "." + precision + "f";
167 }var fmt = new jalview.util.Format (fmtstr);
168 for (var i = iStart; i < width; i++) {
170 if (i >= hconsensus.length || ((hci = hconsensus[i]) == null)) {
171 consensus.annotations[i] = null;
175 if (ignoreGapsInConsensusCalculation) {
180 consensus.annotations[i] = null;
182 }value = fv.floatValue ();
183 var maxRes = hci.get ("R").toString ();
184 var mouseOver = hci.get ("R") + " ";
185 if (maxRes.length > 1) {
186 mouseOver = "[" + maxRes + "] ";
188 }var profile = hci.get ("P");
189 var pairs = hci.get ("B");
190 if (pairs != null && includeAllConsSymbols) {
192 var ca = javajs.util.AU.newInt2 (625);
193 var vl = Clazz.newFloatArray (625, 0);
195 for (var c = 65; c < 90; c++) {
196 for (var d = 65; d < 90; d++) {
197 ca[x] = Clazz.newIntArray (-1, [c, d]);
202 jalview.util.QuickSort.sortFloatObject (vl, ca);
204 var divisor = profile[1][ignoreGapsInConsensusCalculation ? 1 : 0];
205 for (var c = 624; c > 0; c--) {
207 tval = (vl[c] * 100 / divisor);
208 mouseOver += ((p == 0) ? "" : "; ") + String.fromCharCode (ca[c][0]) + String.fromCharCode (ca[c][1]) + " " + fmt.formDouble (tval) + "%";
212 mouseOver += (fmt.formDouble (value) + "%");
213 }consensus.annotations[i] = new jalview.datamodel.Annotation (maxRes, mouseOver, ' ', value);
215 }, "jalview.datamodel.AlignmentAnnotation,~A,~N,~N,~B,~B,~N");
216 c$.extractProfile = Clazz.defineMethod (c$, "extractProfile",
217 function (hconsensus, ignoreGapsInConsensusCalculation) {
218 var rtnval = Clazz.newIntArray (74, 0);
219 var profile = hconsensus.get ("P");
220 var pairs = hconsensus.get ("B");
221 if (profile == null) {
223 }var ca = javajs.util.AU.newInt2 (625);
224 var vl = Clazz.newFloatArray (625, 0);
226 for (var c = 65; c < 90; c++) {
227 for (var d = 65; d < 90; d++) {
228 ca[x] = Clazz.newIntArray (-1, [c, d]);
233 jalview.util.QuickSort.sortFloatObject (vl, ca);
237 var divisor = profile[1][ignoreGapsInConsensusCalculation ? 1 : 0];
238 for (var c = 624; c > 0; c--) {
240 rtnval[offset++] = ca[c][0];
241 rtnval[offset++] = ca[c][1];
242 rtnval[offset] = Clazz.floatToInt (vl[c] * 100 / divisor);
243 rtnval[1] += rtnval[offset++];
246 rtnval[0] = valuesCount;
247 var result = Clazz.newIntArray (rtnval.length + 1, 0);
249 System.arraycopy (rtnval, 0, result, 1, rtnval.length);
251 }, "java.util.Hashtable,~B");
252 Clazz.defineStatics (c$,
253 "STRUCTURE_PROFILE_LENGTH", 74,