1 Clazz.declarePackage ("jalview.analysis");
2 Clazz.load (null, "jalview.analysis.Conservation", ["jalview.datamodel.Annotation", "$.Sequence", "jalview.schemes.ResidueProperties", "jalview.util.Comparison", "java.awt.Color", "java.lang.Character", "$.Double", "$.StringBuffer", "java.util.Hashtable", "$.Vector"], function () {
3 c$ = Clazz.decorateAsClass (function () {
9 this.seqNumsChanged = false;
11 this.canonicaliseAa = true;
13 this.qualityRange = null;
15 this.consSequence = null;
20 this.consSymbs = null;
21 Clazz.instantialize (this, arguments);
22 }, jalview.analysis, "Conservation");
23 Clazz.prepareFields (c$, function () {
24 this.qualityRange = new Array (2);
26 Clazz.makeConstructor (c$,
27 function (name, propHash, threshold, sequences, start, end) {
29 this.propHash = propHash;
30 this.threshold = threshold;
33 this.maxLength = end - start + 1;
35 var sSize = sequences.size ();
36 var sarray = new Array (sSize);
37 this.sequences = sarray;
39 for (s = 0; s < sSize; s++) {
40 sarray[s] = sequences.get (s);
41 if (sarray[s].getLength () > this.maxLength) {
42 this.maxLength = sarray[s].getLength ();
45 if (Clazz.exceptionOf (ex, ArrayIndexOutOfBoundsException)) {
46 this.sequences = new Array (0);
52 }, "~S,java.util.Hashtable,~N,java.util.List,~N,~N");
53 Clazz.defineMethod (c$, "calcSeqNum",
57 var sSize = this.sequences.length;
58 if ((i > -1) && (i < sSize)) {
59 sq = this.sequences[i].getSequenceAsString ();
60 if (this.seqNums.size () <= i) {
61 this.seqNums.addElement ( Clazz.newIntArray (sq.length + 1, 0));
62 }if (sq.hashCode () != (this.seqNums.elementAt (i))[0]) {
65 this.seqNumsChanged = true;
67 if (this.maxLength < len) {
69 }sqnum = Clazz.newIntArray (len + 1, 0);
70 sqnum[0] = sq.hashCode ();
71 for (j = 1; j <= len; j++) {
72 sqnum[j] = jalview.schemes.ResidueProperties.aaIndex[sq.charCodeAt (j - 1)];
74 this.seqNums.setElementAt (sqnum, i);
76 System.out.println ("SEQUENCE HAS BEEN DELETED!!!");
78 System.err.println ("ERROR: calcSeqNum called with out of range sequence index for Alignment\n");
80 Clazz.defineMethod (c$, "calculate",
86 var jSize = this.sequences.length;
92 this.total = new Array (this.maxLength);
93 for (var i = this.start; i <= this.end; i++) {
94 values = Clazz.newIntArray (255, 0);
95 for (j = 0; j < jSize; j++) {
96 if (this.sequences[j].getLength () > i) {
97 c = this.sequences[j].getCharAt (i);
98 if (this.canonicaliseAa) {
99 c = String.fromCharCode (jalview.schemes.ResidueProperties.aaIndex[this.sequences[j].getCharAt (i).charCodeAt (0)]);
100 if (c.charCodeAt (0) > 20) {
103 c = jalview.schemes.ResidueProperties.aa[c.charCodeAt (0)].charAt (0);
105 if (c == '.' || c == ' ') {
107 }if (!this.canonicaliseAa && 'a' <= c && c <= 'z') {
108 c = String.fromCharCode (c.charCodeAt (0) - (32));
109 }}values[c.charCodeAt (0)]++;
111 values['-'.charCodeAt (0)]++;
113 thresh = Clazz.doubleToInt ((this.threshold * (jSize)) / 100);
114 resultHash = new java.util.Hashtable ();
115 for (var v = '-'; v < 'Z'; v = String.fromCharCode (v.charCodeAt (0) + 1)) {
116 if (values[v.charCodeAt (0)] > thresh) {
117 res = String.valueOf (v);
118 enumeration2 = this.propHash.keys ();
119 while (enumeration2.hasMoreElements ()) {
120 type = enumeration2.nextElement ();
121 ht = this.propHash.get (type);
122 if (!resultHash.containsKey (type)) {
123 if (ht.containsKey (res)) {
124 resultHash.put (type, ht.get (res));
126 resultHash.put (type, ht.get ("-"));
127 }} else if ((resultHash.get (type)).equals (ht.get (res)) == false) {
128 resultHash.put (type, new Integer (-1));
131 if (this.total.length > 0) {
132 this.total[i - this.start] = resultHash;
135 Clazz.defineMethod (c$, "countConsNGaps",
140 var r = Clazz.newIntArray (2, 0);
143 var iSize = this.sequences.length;
145 for (i = 0; i < iSize; i++) {
146 if (j >= this.sequences[i].getLength ()) {
149 }c = this.sequences[i].getCharAt (j);
150 if (jalview.util.Comparison.isGap ((c))) {
160 r[0] = (nres == cons) ? 1 : 0;
164 Clazz.defineMethod (c$, "verdict",
165 function (consflag, percentageGaps) {
166 var consString = new StringBuffer ();
175 for (var i = 0; i < this.start; i++) {
176 consString.append ('-');
178 this.consSymbs = new Array (this.end - this.start + 1);
179 for (var i = this.start; i <= this.end; i++) {
180 gapcons = this.countConsNGaps (i);
181 totGaps = gapcons[1];
182 pgaps = (totGaps * 100) / this.sequences.length;
183 this.consSymbs[i - this.start] = String.instantialize ();
184 if (percentageGaps > pgaps) {
185 resultHash = this.total[i - this.start];
187 enumeration = resultHash.keys ();
188 while (enumeration.hasMoreElements ()) {
189 type = enumeration.nextElement ();
190 result = resultHash.get (type);
192 if (result.intValue () == 1) {
193 this.consSymbs[i - this.start] = type + " " + this.consSymbs[i - this.start];
196 if (result.intValue () != -1) {
198 if (result.intValue () == 0) {
199 this.consSymbs[i - this.start] = this.consSymbs[i - this.start] + " !" + type;
201 this.consSymbs[i - this.start] = type + " " + this.consSymbs[i - this.start];
205 consString.append ("" + count);
207 consString.append ((gapcons[0] == 1) ? "*" : "+");
209 consString.append ('-');
211 this.consSequence = new jalview.datamodel.Sequence (this.name, consString.toString (), this.start, this.end);
213 Clazz.defineMethod (c$, "getConsSequence",
215 return this.consSequence;
217 Clazz.defineMethod (c$, "findQuality",
219 this.findQuality (0, this.maxLength - 1);
221 Clazz.defineMethod (c$, "percentIdentity2",
223 this.seqNums = new java.util.Vector ();
225 var iSize = this.sequences.length;
226 for (i = 0; i < iSize; i++) {
229 if ((this.cons2 == null) || this.seqNumsChanged) {
230 this.cons2 = Clazz.newIntArray (this.maxLength, 24, 0);
231 for (var j = 0; j < 24; j++) {
232 for (i = 0; i < this.maxLength; i++) {
233 this.cons2[i][j] = 0;
238 while (j < this.sequences.length) {
239 sqnum = this.seqNums.elementAt (j);
240 for (i = 1; i < sqnum.length; i++) {
241 this.cons2[i - 1][sqnum[i]]++;
243 for (i = sqnum.length - 1; i < this.maxLength; i++) {
249 Clazz.defineMethod (c$, "findQuality",
250 function (start, end) {
251 this.quality = new java.util.Vector ();
253 var BLOSUM62 = jalview.schemes.ResidueProperties.getBLOSUM62 ();
254 this.percentIdentity2 ();
255 var size = this.seqNums.size ();
256 var lengths = Clazz.newIntArray (size, 0);
270 for (l = 0; l < size; l++) {
271 lengths[l] = (this.seqNums.elementAt (l)).length - 1;
273 for (j = start; j <= end; j++) {
275 x = Clazz.newDoubleArray (24, 0);
276 for (ii = 0; ii < 24; ii++) {
278 for (i2 = 0; i2 < 24; i2++) {
279 x[ii] += ((this.cons2[j][i2] * BLOSUM62[ii][i2]) + 4);
283 for (k = 0; k < size; k++) {
285 xx = Clazz.newDoubleArray (24, 0);
286 seqNum = (j < lengths[k]) ? (this.seqNums.elementAt (k))[j + 1] : 23;
287 for (i = 0; i < 23; i++) {
289 sr = BLOSUM62[i][seqNum] + 4;
291 tot += (xx[i] * xx[i]);
293 bigtot += Math.sqrt (tot);
297 }this.quality.addElement ( new Double (bigtot));
300 for (j = start; j <= end; j++) {
301 tmp = (this.quality.elementAt (j)).doubleValue ();
302 tmp = ((max - tmp) * (size - this.cons2[j][23])) / size;
303 this.quality.setElementAt ( new Double (tmp), j);
307 this.qualityRange[0] = new Double (0);
308 this.qualityRange[1] = new Double (newmax);
310 Clazz.defineMethod (c$, "completeAnnotations",
311 function (conservation, quality2, istart, alWidth) {
312 var sequence = this.getConsSequence ().getSequence ();
330 if (conservation.annotations != null && conservation.annotations.length < alWidth) {
331 conservation.annotations = new Array (alWidth);
332 }if (quality2 != null) {
333 quality2.graphMax = this.qualityRange[1].floatValue ();
334 if (quality2.annotations != null && quality2.annotations.length < alWidth) {
335 quality2.annotations = new Array (alWidth);
336 }qmin = this.qualityRange[0].floatValue ();
337 qmax = this.qualityRange[1].floatValue ();
338 }for (var i = 0; i < alWidth; i++) {
341 if (Character.isDigit (c)) {
342 value = c.charCodeAt (0) - 48;
343 } else if (c == '*') {
345 } else if (c == '+') {
347 }var vprop = value - min;
349 conservation.annotations[i] = new jalview.datamodel.Annotation (String.valueOf (c), this.consSymbs[i - this.start], ' ', value, new java.awt.Color (minR + (maxR * vprop), minG + (maxG * vprop), minB + (maxB * vprop)));
350 if (quality2 != null) {
351 value = (this.quality.elementAt (i)).floatValue ();
352 vprop = value - qmin;
354 quality2.annotations[i] = new jalview.datamodel.Annotation (" ", String.valueOf (value), ' ', value, new java.awt.Color (minR + (maxR * vprop), minG + (maxG * vprop), minB + (maxB * vprop)));
356 }, "jalview.datamodel.AlignmentAnnotation,jalview.datamodel.AlignmentAnnotation,~N,~N");
357 c$.calculateConservation = Clazz.defineMethod (c$, "calculateConservation",
358 function (name, consHash, threshold, seqs, start, end, posOrNeg, consPercGaps, calcQuality) {
359 var cons = new jalview.analysis.Conservation (name, consHash, threshold, seqs, start, end);
360 return jalview.analysis.Conservation.calculateConservation (cons, posOrNeg, consPercGaps, calcQuality);
361 }, "~S,java.util.Hashtable,~N,java.util.List,~N,~N,~B,~N,~B");
362 c$.calculateConservation = Clazz.defineMethod (c$, "calculateConservation",
363 function (cons, b, consPercGaps, calcQuality) {
365 cons.verdict (b, consPercGaps);
369 }, "jalview.analysis.Conservation,~B,~N,~B");