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