Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / jalview / analysis / Conservation.js
index e49ae2a..328032a 100644 (file)
-Clazz.declarePackage ("jalview.analysis");\r
-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", "JU.DebugJS"], function () {\r
-c$ = Clazz.decorateAsClass (function () {\r
-this.sequences = null;\r
-this.start = 0;\r
-this.end = 0;\r
-this.seqNums = null;\r
-this.maxLength = 0;\r
-this.seqNumsChanged = false;\r
-this.total = null;\r
-this.canonicaliseAa = true;\r
-this.quality = null;\r
-this.qualityRange = null;\r
-this.consString = "";\r
-this.consSequence = null;\r
-this.propHash = null;\r
-this.threshold = 0;\r
-this.name = "";\r
-this.cons2 = null;\r
-this.consSymbs = null;\r
-Clazz.instantialize (this, arguments);\r
-}, jalview.analysis, "Conservation");\r
-Clazz.prepareFields (c$, function () {\r
-this.qualityRange =  new Array (2);\r
-});\r
-Clazz.makeConstructor (c$, \r
-function (name, propHash, threshold, sequences, start, end) {\r
-this.name = name;\r
-this.propHash = propHash;\r
-this.threshold = threshold;\r
-this.start = start;\r
-this.end = end;\r
-this.maxLength = end - start + 1;\r
-var s;\r
-var sSize = sequences.size ();\r
-var sarray =  new Array (sSize);\r
-this.sequences = sarray;\r
-try {\r
-for (s = 0; s < sSize; s++) {\r
-sarray[s] = sequences.get (s);\r
-if (sarray[s].getLength () > this.maxLength) {\r
-this.maxLength = sarray[s].getLength ();\r
-}}\r
-} catch (ex) {\r
-if (Clazz.exceptionOf (ex, ArrayIndexOutOfBoundsException)) {\r
-this.sequences =  new Array (0);\r
-this.maxLength = 0;\r
-} else {\r
-throw ex;\r
-}\r
-}\r
-}, "~S,java.util.Hashtable,~N,java.util.List,~N,~N");\r
-Clazz.defineMethod (c$, "calcSeqNum", \r
- function (i) {\r
-var sq = null;\r
-var sqnum = null;\r
-var sSize = this.sequences.length;\r
-if ((i > -1) && (i < sSize)) {\r
-sq = this.sequences[i].getSequenceAsString ();\r
-if (this.seqNums.size () <= i) {\r
-this.seqNums.addElement ( Clazz.newIntArray (sq.length + 1, 0));\r
-}if (sq.hashCode () != (this.seqNums.elementAt (i))[0]) {\r
-var j;\r
-var len;\r
-this.seqNumsChanged = true;\r
-len = sq.length;\r
-if (this.maxLength < len) {\r
-this.maxLength = len;\r
-}sqnum =  Clazz.newIntArray (len + 1, 0);\r
-sqnum[0] = sq.hashCode ();\r
-for (j = 1; j <= len; j++) {\r
-sqnum[j] = jalview.schemes.ResidueProperties.aaIndex[sq.charCodeAt (j - 1)];\r
-}\r
-this.seqNums.setElementAt (sqnum, i);\r
-} else {\r
-System.out.println ("SEQUENCE HAS BEEN DELETED!!!");\r
-}} else {\r
-System.err.println ("ERROR: calcSeqNum called with out of range sequence index for Alignment\n");\r
-}}, "~N");\r
-Clazz.defineMethod (c$, "calculate", \r
-function () {\r
-var resultHash;\r
-var ht;\r
-var thresh;\r
-var j;\r
-var jSize = this.sequences.length;\r
-var values;\r
-var type;\r
-var res = null;\r
-var c;\r
-var enumeration2;\r
-this.total =  new Array (this.maxLength);\r
-for (var i = this.start; i <= this.end; i++) {\r
-values =  Clazz.newIntArray (255, 0);\r
-for (j = 0; j < jSize; j++) {\r
-if (this.sequences[j].getLength () > i) {\r
-c = this.sequences[j].getCharAt (i);\r
-if (this.canonicaliseAa) {\r
-c = String.fromCharCode (jalview.schemes.ResidueProperties.aaIndex[this.sequences[j].getCharAt (i).charCodeAt (0)]);\r
-if (c.charCodeAt (0) > 20) {\r
-c = '-';\r
-} else {\r
-c = jalview.schemes.ResidueProperties.aa[c.charCodeAt (0)].charAt (0);\r
-}} else {\r
-if (c == '.' || c == ' ') {\r
-c = '-';\r
-}if (!this.canonicaliseAa && 'a' <= c && c <= 'z') {\r
-c = String.fromCharCode (c.charCodeAt (0) - (32));\r
-}}values[c.charCodeAt (0)]++;\r
-} else {\r
-values['-'.charCodeAt (0)]++;\r
-}}\r
-thresh = Clazz.doubleToInt ((this.threshold * (jSize)) / 100);\r
-resultHash =  new java.util.Hashtable ();\r
-for (var v = '-'; v < 'Z'; v = String.fromCharCode (v.charCodeAt (0) + 1)) {\r
-if (values[v.charCodeAt (0)] > thresh) {\r
-res = String.valueOf (v);\r
-enumeration2 = this.propHash.keys ();\r
-while (enumeration2.hasMoreElements ()) {\r
-type = enumeration2.nextElement ();\r
-ht = this.propHash.get (type);\r
-if (!resultHash.containsKey (type)) {\r
-if (ht.containsKey (res)) {\r
-resultHash.put (type, ht.get (res));\r
-} else {\r
-resultHash.put (type, ht.get ("-"));\r
-}} else if ((resultHash.get (type)).equals (ht.get (res)) == false) {\r
-resultHash.put (type,  new Integer (-1));\r
-}}\r
-}}\r
-if (this.total.length > 0) {\r
-this.total[i - this.start] = resultHash;\r
-}}\r
-});\r
-Clazz.defineMethod (c$, "countConsNGaps", \r
-function (j) {\r
-var count = 0;\r
-var cons = 0;\r
-var nres = 0;\r
-var r =  Clazz.newIntArray (2, 0);\r
-var f = '$';\r
-var i;\r
-var iSize = this.sequences.length;\r
-var c;\r
-for (i = 0; i < iSize; i++) {\r
-if (j >= this.sequences[i].getLength ()) {\r
-count++;\r
-continue;\r
-}c = this.sequences[i].getCharAt (j);\r
-if (jalview.util.Comparison.isGap ((c))) {\r
-count++;\r
-} else {\r
-nres++;\r
-if (nres == 1) {\r
-f = c;\r
-cons++;\r
-} else if (f == c) {\r
-cons++;\r
-}}}\r
-r[0] = (nres == cons) ? 1 : 0;\r
-r[1] = count;\r
-return r;\r
-}, "~N");\r
-Clazz.defineMethod (c$, "verdict", \r
-function (consflag, percentageGaps) {\r
-var consString =  new StringBuffer ();\r
-var type;\r
-var result;\r
-var gapcons;\r
-var totGaps;\r
-var count;\r
-var pgaps;\r
-var resultHash;\r
-var enumeration;\r
-for (var i = 0; i < this.start; i++) {\r
-consString.append ('-');\r
-}\r
-this.consSymbs =  new Array (this.end - this.start + 1);\r
-for (var i = this.start; i <= this.end; i++) {\r
-gapcons = this.countConsNGaps (i);\r
-totGaps = gapcons[1];\r
-pgaps = (totGaps * 100) / this.sequences.length;\r
-this.consSymbs[i - this.start] =  String.instantialize ();\r
-if (percentageGaps > pgaps) {\r
-resultHash = this.total[i - this.start];\r
-count = 0;\r
-enumeration = resultHash.keys ();\r
-while (enumeration.hasMoreElements ()) {\r
-type = enumeration.nextElement ();\r
-result = resultHash.get (type);\r
-if (consflag) {\r
-if (result.intValue () == 1) {\r
-this.consSymbs[i - this.start] = type + " " + this.consSymbs[i - this.start];\r
-count++;\r
-}} else {\r
-if (result.intValue () != -1) {\r
-{\r
-if (result.intValue () == 0) {\r
-this.consSymbs[i - this.start] = this.consSymbs[i - this.start] + " !" + type;\r
-} else {\r
-this.consSymbs[i - this.start] = type + " " + this.consSymbs[i - this.start];\r
-}}count++;\r
-}}}\r
-if (count < 10) {\r
-consString.append ("" + count);\r
-} else {\r
-consString.append ((gapcons[0] == 1) ? "*" : "+");\r
-}} else {\r
-consString.append ('-');\r
-}}\r
-this.consSequence =  new jalview.datamodel.Sequence (this.name, consString.toString (), this.start, this.end);\r
-}, "~B,~N");\r
-Clazz.defineMethod (c$, "getConsSequence", \r
-function () {\r
-return this.consSequence;\r
-});\r
-Clazz.defineMethod (c$, "findQuality", \r
-function () {\r
-this.findQuality (0, this.maxLength - 1);\r
-});\r
-Clazz.defineMethod (c$, "percentIdentity2", \r
- function () {\r
-this.seqNums =  new java.util.Vector ();\r
-var i = 0;\r
-var iSize = this.sequences.length;\r
-for (i = 0; i < iSize; i++) {\r
-this.calcSeqNum (i);\r
-}\r
-if ((this.cons2 == null) || this.seqNumsChanged) {\r
-this.cons2 =  Clazz.newIntArray (this.maxLength, 24, 0);\r
-for (var j = 0; j < 24; j++) {\r
-for (i = 0; i < this.maxLength; i++) {\r
-this.cons2[i][j] = 0;\r
-}\r
-}\r
-var sqnum;\r
-var j = 0;\r
-while (j < this.sequences.length) {\r
-sqnum = this.seqNums.elementAt (j);\r
-for (i = 1; i < sqnum.length; i++) {\r
-this.cons2[i - 1][sqnum[i]]++;\r
-}\r
-for (i = sqnum.length - 1; i < this.maxLength; i++) {\r
-this.cons2[i][23]++;\r
-}\r
-j++;\r
-}\r
-}});\r
-Clazz.defineMethod (c$, "findQuality", \r
-function (start, end) {\r
-this.quality =  new java.util.Vector ();\r
-var max = -10000;\r
-var BLOSUM62 = jalview.schemes.ResidueProperties.getBLOSUM62 ();\r
-this.percentIdentity2 ();\r
-var size = this.seqNums.size ();\r
-var lengths =  Clazz.newIntArray (size, 0);\r
-var tot;\r
-var bigtot;\r
-var sr;\r
-var tmp;\r
-var x;\r
-var xx;\r
-var l;\r
-var j;\r
-var i;\r
-var ii;\r
-var i2;\r
-var k;\r
-var seqNum;\r
-for (l = 0; l < size; l++) {\r
-lengths[l] = (this.seqNums.elementAt (l)).length - 1;\r
-}\r
-for (j = start; j <= end; j++) {\r
-bigtot = 0;\r
-x =  Clazz.newDoubleArray (24, 0);\r
-for (ii = 0; ii < 24; ii++) {\r
-x[ii] = 0;\r
-for (i2 = 0; i2 < 24; i2++) {\r
-x[ii] += ((this.cons2[j][i2] * BLOSUM62[ii][i2]) + 4);\r
-}\r
-x[ii] /= size;\r
-}\r
-for (k = 0; k < size; k++) {\r
-tot = 0;\r
-xx =  Clazz.newDoubleArray (24, 0);\r
-seqNum = (j < lengths[k]) ? (this.seqNums.elementAt (k))[j + 1] : 23;\r
-for (i = 0; i < 23; i++) {\r
-sr = 0;\r
-sr = BLOSUM62[i][seqNum] + 4;\r
-xx[i] = x[i] - sr;\r
-tot += (xx[i] * xx[i]);\r
-}\r
-bigtot += Math.sqrt (tot);\r
-}\r
-if (max < bigtot) {\r
-max = bigtot;\r
-}this.quality.addElement ( new Double (bigtot));\r
-}\r
-var newmax = -10000;\r
-for (j = start; j <= end; j++) {\r
-tmp = (this.quality.elementAt (j)).doubleValue ();\r
-tmp = ((max - tmp) * (size - this.cons2[j][23])) / size;\r
-this.quality.setElementAt ( new Double (tmp), j);\r
-if (tmp > newmax) {\r
-newmax = tmp;\r
-}}\r
-this.qualityRange[0] =  new Double (0);\r
-this.qualityRange[1] =  new Double (newmax);\r
-}, "~N,~N");\r
-Clazz.defineMethod (c$, "completeAnnotations", \r
-function (conservation, quality2, istart, alWidth) {\r
-var sequence = this.getConsSequence ().getSequence ();\r
-var minR;\r
-var minG;\r
-var minB;\r
-var maxR;\r
-var maxG;\r
-var maxB;\r
-minR = 0.3;\r
-minG = 0.0;\r
-minB = 0;\r
-maxR = 1.0 - minR;\r
-maxG = 0.9 - minG;\r
-maxB = 0 - minB;\r
-var min = 0;\r
-var max = 11;\r
-var qmin = 0;\r
-var qmax = 0;\r
-var c;\r
-if (conservation.annotations != null && conservation.annotations.length < alWidth) {\r
-conservation.annotations =  new Array (alWidth);\r
-}if (quality2 != null) {\r
-quality2.graphMax = this.qualityRange[1].floatValue ();\r
-if (quality2.annotations != null && quality2.annotations.length < alWidth) {\r
-quality2.annotations =  new Array (alWidth);\r
-}qmin = this.qualityRange[0].floatValue ();\r
-qmax = this.qualityRange[1].floatValue ();\r
-}for (var i = 0; i < alWidth; i++) {\r
-var value = 0;\r
-c = sequence[i];\r
-if (Character.isDigit (c)) {\r
-value = c.charCodeAt (0) - 48;\r
-} else if (c == '*') {\r
-value = 11;\r
-} else if (c == '+') {\r
-value = 10;\r
-}var vprop = value - min;\r
-vprop /= max;\r
-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
-if (quality2 != null) {\r
-value = (this.quality.elementAt (i)).floatValue ();\r
-vprop = value - qmin;\r
-vprop /= qmax;\r
-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
-}}\r
-JU.DebugJS._ ("Conservation");\r
-}, "jalview.datamodel.AlignmentAnnotation,jalview.datamodel.AlignmentAnnotation,~N,~N");\r
-c$.calculateConservation = Clazz.defineMethod (c$, "calculateConservation", \r
-function (name, consHash, threshold, seqs, start, end, posOrNeg, consPercGaps, calcQuality) {\r
-var cons =  new jalview.analysis.Conservation (name, consHash, threshold, seqs, start, end);\r
-return jalview.analysis.Conservation.calculateConservation (cons, posOrNeg, consPercGaps, calcQuality);\r
-}, "~S,java.util.Hashtable,~N,java.util.List,~N,~N,~B,~N,~B");\r
-c$.calculateConservation = Clazz.defineMethod (c$, "calculateConservation", \r
-function (cons, b, consPercGaps, calcQuality) {\r
-cons.calculate ();\r
-cons.verdict (b, consPercGaps);\r
-if (calcQuality) {\r
-cons.findQuality ();\r
-}return cons;\r
-}, "jalview.analysis.Conservation,~B,~N,~B");\r
-});\r
+Clazz.declarePackage ("jalview.analysis");
+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", "JU.DebugJS"], function () {
+c$ = Clazz.decorateAsClass (function () {
+this.sequences = null;
+this.start = 0;
+this.end = 0;
+this.seqNums = null;
+this.maxLength = 0;
+this.seqNumsChanged = false;
+this.total = null;
+this.canonicaliseAa = true;
+this.quality = null;
+this.qualityRange = null;
+this.consString = "";
+this.consSequence = null;
+this.propHash = null;
+this.threshold = 0;
+this.name = "";
+this.cons2 = null;
+this.consSymbs = null;
+Clazz.instantialize (this, arguments);
+}, jalview.analysis, "Conservation");
+Clazz.prepareFields (c$, function () {
+this.qualityRange =  new Array (2);
+});
+Clazz.makeConstructor (c$, 
+function (name, propHash, threshold, sequences, start, end) {
+this.name = name;
+this.propHash = propHash;
+this.threshold = threshold;
+this.start = start;
+this.end = end;
+this.maxLength = end - start + 1;
+var s;
+var sSize = sequences.size ();
+var sarray =  new Array (sSize);
+this.sequences = sarray;
+try {
+for (s = 0; s < sSize; s++) {
+sarray[s] = sequences.get (s);
+if (sarray[s].getLength () > this.maxLength) {
+this.maxLength = sarray[s].getLength ();
+}}
+} catch (ex) {
+if (Clazz.exceptionOf (ex, ArrayIndexOutOfBoundsException)) {
+this.sequences =  new Array (0);
+this.maxLength = 0;
+} else {
+throw ex;
+}
+}
+}, "~S,java.util.Hashtable,~N,java.util.List,~N,~N");
+Clazz.defineMethod (c$, "calcSeqNum", 
+ function (i) {
+var sq = null;
+var sqnum = null;
+var sSize = this.sequences.length;
+if ((i > -1) && (i < sSize)) {
+sq = this.sequences[i].getSequenceAsString ();
+if (this.seqNums.size () <= i) {
+this.seqNums.addElement ( Clazz.newIntArray (sq.length + 1, 0));
+}if (sq.hashCode () != (this.seqNums.elementAt (i))[0]) {
+var j;
+var len;
+this.seqNumsChanged = true;
+len = sq.length;
+if (this.maxLength < len) {
+this.maxLength = len;
+}sqnum =  Clazz.newIntArray (len + 1, 0);
+sqnum[0] = sq.hashCode ();
+for (j = 1; j <= len; j++) {
+sqnum[j] = jalview.schemes.ResidueProperties.aaIndex[sq.charCodeAt (j - 1)];
+}
+this.seqNums.setElementAt (sqnum, i);
+} else {
+System.out.println ("SEQUENCE HAS BEEN DELETED!!!");
+}} else {
+System.err.println ("ERROR: calcSeqNum called with out of range sequence index for Alignment\n");
+}}, "~N");
+Clazz.defineMethod (c$, "calculate", 
+function () {
+var resultHash;
+var ht;
+var thresh;
+var j;
+var jSize = this.sequences.length;
+var values;
+var type;
+var res = null;
+var c;
+var enumeration2;
+this.total =  new Array (this.maxLength);
+for (var i = this.start; i <= this.end; i++) {
+values =  Clazz.newIntArray (255, 0);
+for (j = 0; j < jSize; j++) {
+if (this.sequences[j].getLength () > i) {
+c = this.sequences[j].getCharAt (i);
+if (this.canonicaliseAa) {
+c = String.fromCharCode (jalview.schemes.ResidueProperties.aaIndex[this.sequences[j].getCharAt (i).charCodeAt (0)]);
+if (c.charCodeAt (0) > 20) {
+c = '-';
+} else {
+c = jalview.schemes.ResidueProperties.aa[c.charCodeAt (0)].charAt (0);
+}} else {
+if (c == '.' || c == ' ') {
+c = '-';
+}if (!this.canonicaliseAa && 'a' <= c && c <= 'z') {
+c = String.fromCharCode (c.charCodeAt (0) - (32));
+}}values[c.charCodeAt (0)]++;
+} else {
+values['-'.charCodeAt (0)]++;
+}}
+thresh = Clazz.doubleToInt ((this.threshold * (jSize)) / 100);
+resultHash =  new java.util.Hashtable ();
+for (var v = '-'; v < 'Z'; v = String.fromCharCode (v.charCodeAt (0) + 1)) {
+if (values[v.charCodeAt (0)] > thresh) {
+res = String.valueOf (v);
+enumeration2 = this.propHash.keys ();
+while (enumeration2.hasMoreElements ()) {
+type = enumeration2.nextElement ();
+ht = this.propHash.get (type);
+if (!resultHash.containsKey (type)) {
+if (ht.containsKey (res)) {
+resultHash.put (type, ht.get (res));
+} else {
+resultHash.put (type, ht.get ("-"));
+}} else if ((resultHash.get (type)).equals (ht.get (res)) == false) {
+resultHash.put (type,  new Integer (-1));
+}}
+}}
+if (this.total.length > 0) {
+this.total[i - this.start] = resultHash;
+}}
+});
+Clazz.defineMethod (c$, "countConsNGaps", 
+function (j) {
+var count = 0;
+var cons = 0;
+var nres = 0;
+var r =  Clazz.newIntArray (2, 0);
+var f = '$';
+var i;
+var iSize = this.sequences.length;
+var c;
+for (i = 0; i < iSize; i++) {
+if (j >= this.sequences[i].getLength ()) {
+count++;
+continue;
+}c = this.sequences[i].getCharAt (j);
+if (jalview.util.Comparison.isGap ((c))) {
+count++;
+} else {
+nres++;
+if (nres == 1) {
+f = c;
+cons++;
+} else if (f == c) {
+cons++;
+}}}
+r[0] = (nres == cons) ? 1 : 0;
+r[1] = count;
+return r;
+}, "~N");
+Clazz.defineMethod (c$, "verdict", 
+function (consflag, percentageGaps) {
+var consString =  new StringBuffer ();
+var type;
+var result;
+var gapcons;
+var totGaps;
+var count;
+var pgaps;
+var resultHash;
+var enumeration;
+for (var i = 0; i < this.start; i++) {
+consString.append ('-');
+}
+this.consSymbs =  new Array (this.end - this.start + 1);
+for (var i = this.start; i <= this.end; i++) {
+gapcons = this.countConsNGaps (i);
+totGaps = gapcons[1];
+pgaps = (totGaps * 100) / this.sequences.length;
+this.consSymbs[i - this.start] =  String.instantialize ();
+if (percentageGaps > pgaps) {
+resultHash = this.total[i - this.start];
+count = 0;
+enumeration = resultHash.keys ();
+while (enumeration.hasMoreElements ()) {
+type = enumeration.nextElement ();
+result = resultHash.get (type);
+if (consflag) {
+if (result.intValue () == 1) {
+this.consSymbs[i - this.start] = type + " " + this.consSymbs[i - this.start];
+count++;
+}} else {
+if (result.intValue () != -1) {
+{
+if (result.intValue () == 0) {
+this.consSymbs[i - this.start] = this.consSymbs[i - this.start] + " !" + type;
+} else {
+this.consSymbs[i - this.start] = type + " " + this.consSymbs[i - this.start];
+}}count++;
+}}}
+if (count < 10) {
+consString.append ("" + count);
+} else {
+consString.append ((gapcons[0] == 1) ? "*" : "+");
+}} else {
+consString.append ('-');
+}}
+this.consSequence =  new jalview.datamodel.Sequence (this.name, consString.toString (), this.start, this.end);
+}, "~B,~N");
+Clazz.defineMethod (c$, "getConsSequence", 
+function () {
+return this.consSequence;
+});
+Clazz.defineMethod (c$, "findQuality", 
+function () {
+this.findQuality (0, this.maxLength - 1);
+});
+Clazz.defineMethod (c$, "percentIdentity2", 
+ function () {
+this.seqNums =  new java.util.Vector ();
+var i = 0;
+var iSize = this.sequences.length;
+for (i = 0; i < iSize; i++) {
+this.calcSeqNum (i);
+}
+if ((this.cons2 == null) || this.seqNumsChanged) {
+this.cons2 =  Clazz.newIntArray (this.maxLength, 24, 0);
+for (var j = 0; j < 24; j++) {
+for (i = 0; i < this.maxLength; i++) {
+this.cons2[i][j] = 0;
+}
+}
+var sqnum;
+var j = 0;
+while (j < this.sequences.length) {
+sqnum = this.seqNums.elementAt (j);
+for (i = 1; i < sqnum.length; i++) {
+this.cons2[i - 1][sqnum[i]]++;
+}
+for (i = sqnum.length - 1; i < this.maxLength; i++) {
+this.cons2[i][23]++;
+}
+j++;
+}
+}});
+Clazz.defineMethod (c$, "findQuality", 
+function (start, end) {
+this.quality =  new java.util.Vector ();
+var max = -10000;
+var BLOSUM62 = jalview.schemes.ResidueProperties.getBLOSUM62 ();
+this.percentIdentity2 ();
+var size = this.seqNums.size ();
+var lengths =  Clazz.newIntArray (size, 0);
+var tot;
+var bigtot;
+var sr;
+var tmp;
+var x;
+var xx;
+var l;
+var j;
+var i;
+var ii;
+var i2;
+var k;
+var seqNum;
+for (l = 0; l < size; l++) {
+lengths[l] = (this.seqNums.elementAt (l)).length - 1;
+}
+for (j = start; j <= end; j++) {
+bigtot = 0;
+x =  Clazz.newDoubleArray (24, 0);
+for (ii = 0; ii < 24; ii++) {
+x[ii] = 0;
+for (i2 = 0; i2 < 24; i2++) {
+x[ii] += ((this.cons2[j][i2] * BLOSUM62[ii][i2]) + 4);
+}
+x[ii] /= size;
+}
+for (k = 0; k < size; k++) {
+tot = 0;
+xx =  Clazz.newDoubleArray (24, 0);
+seqNum = (j < lengths[k]) ? (this.seqNums.elementAt (k))[j + 1] : 23;
+for (i = 0; i < 23; i++) {
+sr = 0;
+sr = BLOSUM62[i][seqNum] + 4;
+xx[i] = x[i] - sr;
+tot += (xx[i] * xx[i]);
+}
+bigtot += Math.sqrt (tot);
+}
+if (max < bigtot) {
+max = bigtot;
+}this.quality.addElement ( new Double (bigtot));
+}
+var newmax = -10000;
+for (j = start; j <= end; j++) {
+tmp = (this.quality.elementAt (j)).doubleValue ();
+tmp = ((max - tmp) * (size - this.cons2[j][23])) / size;
+this.quality.setElementAt ( new Double (tmp), j);
+if (tmp > newmax) {
+newmax = tmp;
+}}
+this.qualityRange[0] =  new Double (0);
+this.qualityRange[1] =  new Double (newmax);
+}, "~N,~N");
+Clazz.defineMethod (c$, "completeAnnotations", 
+function (conservation, quality2, istart, alWidth) {
+var sequence = this.getConsSequence ().getSequence ();
+var minR;
+var minG;
+var minB;
+var maxR;
+var maxG;
+var maxB;
+minR = 0.3;
+minG = 0.0;
+minB = 0;
+maxR = 1.0 - minR;
+maxG = 0.9 - minG;
+maxB = 0 - minB;
+var min = 0;
+var max = 11;
+var qmin = 0;
+var qmax = 0;
+var c;
+if (conservation.annotations != null && conservation.annotations.length < alWidth) {
+conservation.annotations =  new Array (alWidth);
+}if (quality2 != null) {
+quality2.graphMax = this.qualityRange[1].floatValue ();
+if (quality2.annotations != null && quality2.annotations.length < alWidth) {
+quality2.annotations =  new Array (alWidth);
+}qmin = this.qualityRange[0].floatValue ();
+qmax = this.qualityRange[1].floatValue ();
+}for (var i = 0; i < alWidth; i++) {
+var value = 0;
+c = sequence[i];
+if (Character.isDigit (c)) {
+value = c.charCodeAt (0) - 48;
+} else if (c == '*') {
+value = 11;
+} else if (c == '+') {
+value = 10;
+}var vprop = value - min;
+vprop /= max;
+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)));
+if (quality2 != null) {
+value = (this.quality.elementAt (i)).floatValue ();
+vprop = value - qmin;
+vprop /= qmax;
+quality2.annotations[i] =  new jalview.datamodel.Annotation (" ", String.valueOf (value), ' ', value,  new java.awt.Color (minR + (maxR * vprop), minG + (maxG * vprop), minB + (maxB * vprop)));
+}}
+JU.DebugJS._ ("Conservation");
+}, "jalview.datamodel.AlignmentAnnotation,jalview.datamodel.AlignmentAnnotation,~N,~N");
+c$.calculateConservation = Clazz.defineMethod (c$, "calculateConservation", 
+function (name, consHash, threshold, seqs, start, end, posOrNeg, consPercGaps, calcQuality) {
+var cons =  new jalview.analysis.Conservation (name, consHash, threshold, seqs, start, end);
+return jalview.analysis.Conservation.calculateConservation (cons, posOrNeg, consPercGaps, calcQuality);
+}, "~S,java.util.Hashtable,~N,java.util.List,~N,~N,~B,~N,~B");
+c$.calculateConservation = Clazz.defineMethod (c$, "calculateConservation", 
+function (cons, b, consPercGaps, calcQuality) {
+cons.calculate ();
+cons.verdict (b, consPercGaps);
+if (calcQuality) {
+cons.findQuality ();
+}return cons;
+}, "jalview.analysis.Conservation,~B,~N,~B");
+});