X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=bin%2Fjalview%2Fanalysis%2FAAFrequency.js;h=a7a69d179e2de4f075a73d7282c52830ef609c34;hp=8e3d4c55822045cf53dab2ac6806b0965b51fea9;hb=7301a2415adab88038b291fc54caeeb3a5a47a44;hpb=6154cb57a6eac3bb1344b8342495f5bb701ee921 diff --git a/bin/jalview/analysis/AAFrequency.js b/bin/jalview/analysis/AAFrequency.js index 8e3d4c5..a7a69d1 100644 --- a/bin/jalview/analysis/AAFrequency.js +++ b/bin/jalview/analysis/AAFrequency.js @@ -1,308 +1,308 @@ -Clazz.declarePackage ("jalview.analysis"); -Clazz.load (null, "jalview.analysis.AAFrequency", ["jalview.analysis.CodingUtils", "jalview.datamodel.Annotation", "jalview.util.Format", "$.MappingUtils", "$.QuickSort", "java.lang.Float", "$.StringBuilder", "java.util.Arrays", "$.Hashtable"], function () { -c$ = Clazz.declareType (jalview.analysis, "AAFrequency"); -c$.calculate = Clazz.defineMethod (c$, "calculate", -function (list, start, end) { -return jalview.analysis.AAFrequency.calculate (list, start, end, false); -}, "java.util.List,~N,~N"); -c$.calculate = Clazz.defineMethod (c$, "calculate", -function (sequences, start, end, profile) { -var seqs = new Array (sequences.size ()); -var width = 0; -{ -for (var i = 0; i < sequences.size (); i++) { -seqs[i] = sequences.get (i); -if (seqs[i].getLength () > width) { -width = seqs[i].getLength (); -}} -var reply = new Array (width); -if (end >= width) { -end = width; -}jalview.analysis.AAFrequency.calculate (seqs, start, end, reply, profile); -return reply; -}}, "java.util.List,~N,~N,~B"); -c$.calculate = Clazz.defineMethod (c$, "calculate", -function (sequences, start, end, result, profile) { -var residueHash; -var maxCount; -var nongap; -var i; -var j; -var v; -var jSize = sequences.length; -var maxResidue; -var c = '-'; -var percentage; -var values = Clazz.newIntArray (255, 0); -var seq; -for (i = start; i < end; i++) { -residueHash = new java.util.Hashtable (); -maxCount = 0; -maxResidue = ""; -nongap = 0; -values = Clazz.newIntArray (255, 0); -for (j = 0; j < jSize; j++) { -if (sequences[j] == null) { -System.err.println ("WARNING: Consensus skipping null sequence - possible race condition."); -continue; -}seq = sequences[j].getSequence (); -if (seq.length > i) { -c = seq[i]; -if (c == '.' || c == ' ') { -c = '-'; -}if (c == '-') { -values['-'.charCodeAt (0)]++; -continue; -} else if ('a' <= c && c <= 'z') { -c = String.fromCharCode (c.charCodeAt (0) + -32); -}nongap++; -values[c.charCodeAt (0)]++; -} else { -values['-'.charCodeAt (0)]++; -}} -if (jSize == 1) { -maxResidue = String.valueOf (c); -maxCount = 1; -} else { -for (v = 65; v <= 90; v++) { -if (values[v] < 1 || values[v] < maxCount) { -continue; -}if (values[v] > maxCount) { -maxResidue = jalview.analysis.AAFrequency.CHARS[v - 65]; -} else if (values[v] == maxCount) { -maxResidue += jalview.analysis.AAFrequency.CHARS[v - 65]; -}maxCount = values[v]; -} -}if (maxResidue.length == 0) { -maxResidue = "-"; -}if (profile) { -residueHash.put ("P", Clazz.newArray (-1, [values, Clazz.newIntArray (-1, [jSize, nongap])])); -}residueHash.put ("C", new Integer (maxCount)); -residueHash.put ("R", maxResidue); -percentage = (maxCount * 100) / jSize; -residueHash.put ("G", new Float (percentage)); -if (nongap > 0) { -percentage = (maxCount * 100) / nongap; -}residueHash.put ("N", new Float (percentage)); -result[i] = residueHash; -} -}, "~A,~N,~N,~A,~B"); -c$.completeConsensus = Clazz.defineMethod (c$, "completeConsensus", -function (consensus, hconsensus, iStart, width, ignoreGapsInConsensusCalculation, includeAllConsSymbols, nseq) { -jalview.analysis.AAFrequency.completeConsensus (consensus, hconsensus, iStart, width, ignoreGapsInConsensusCalculation, includeAllConsSymbols, null, nseq); -}, "jalview.datamodel.AlignmentAnnotation,~A,~N,~N,~B,~B,~N"); -c$.completeConsensus = Clazz.defineMethod (c$, "completeConsensus", -function (consensus, hconsensus, iStart, width, ignoreGapsInConsensusCalculation, includeAllConsSymbols, alphabet, nseq) { -if (consensus == null || consensus.annotations == null || consensus.annotations.length < width) { -return; -}var fmt = jalview.analysis.AAFrequency.getPercentageFormat (nseq); -for (var i = iStart; i < width; i++) { -var hci; -if (i >= hconsensus.length || ((hci = hconsensus[i]) == null)) { -consensus.annotations[i] = null; -continue; -}var fv = hci.get (ignoreGapsInConsensusCalculation ? "N" : "G"); -if (fv == null) { -consensus.annotations[i] = null; -continue; -}var value = fv.floatValue (); -var maxRes = hci.get ("R").toString (); -var mouseOver = new StringBuilder (64); -if (maxRes.length > 1) { -mouseOver.append ("[").append (maxRes).append ("] "); -maxRes = "+"; -} else { -mouseOver.append (hci.get ("R") + " "); -}var profile = hci.get ("P"); -if (profile != null && includeAllConsSymbols) { -var sequenceCount = profile[1][0]; -var nonGappedCount = profile[1][1]; -var normalisedBy = ignoreGapsInConsensusCalculation ? nonGappedCount : sequenceCount; -mouseOver.setLength (0); -if (alphabet != null) { -for (var c = 0; c < alphabet.length; c++) { -var tval = profile[0][alphabet[c].charCodeAt (0)] * 100 / normalisedBy; -mouseOver.append (((c == 0) ? "" : "; ")).append (alphabet[c]).append (" ").append (((fmt != null) ? fmt.formDouble (tval) : (Clazz.floatToInt (tval)))).append ("%"); -} -} else { -var ca = Clazz.newCharArray (profile[0].length, '\0'); -var vl = Clazz.newFloatArray (profile[0].length, 0); -for (var c = 0; c < ca.length; c++) { -ca[c] = String.fromCharCode (c); -vl[c] = profile[0][c]; -} -jalview.util.QuickSort.sortFloatChar (vl, ca); -for (var p = 0, c = ca.length - 1; profile[0][ca[c].charCodeAt (0)] > 0; c--) { -var residue = ca[c]; -if (residue != '-') { -var tval = profile[0][residue.charCodeAt (0)] * 100 / normalisedBy; -mouseOver.append ((((p == 0) ? "" : "; "))).append (residue).append (" ").append (((fmt != null) ? fmt.formDouble (tval) : (Clazz.floatToInt (tval)))).append ("%"); -p++; -}} -}} else { -mouseOver.append ((((fmt != null) ? fmt.formDouble (value) : (Clazz.floatToInt (value))))).append ("%"); -}consensus.annotations[i] = new jalview.datamodel.Annotation (maxRes, mouseOver.toString (), ' ', value); -} -}, "jalview.datamodel.AlignmentAnnotation,~A,~N,~N,~B,~B,~A,~N"); -c$.getPercentageFormat = Clazz.defineMethod (c$, "getPercentageFormat", -function (nseq) { -var scale = 0; -while (nseq >= 10) { -scale++; -nseq /= 10; -} -return scale <= 1 ? null : new jalview.util.Format ("%3." + (scale - 1) + "f"); -}, "~N"); -c$.extractProfile = Clazz.defineMethod (c$, "extractProfile", -function (hconsensus, ignoreGaps) { -var rtnval = Clazz.newIntArray (64, 0); -var profile = hconsensus.get ("P"); -if (profile == null) { -return null; -}var ca = Clazz.newCharArray (profile[0].length, '\0'); -var vl = Clazz.newFloatArray (profile[0].length, 0); -for (var c = 0; c < ca.length; c++) { -ca[c] = String.fromCharCode (c); -vl[c] = profile[0][c]; -} -jalview.util.QuickSort.sortFloatChar (vl, ca); -var nextArrayPos = 2; -var totalPercentage = 0; -var distinctValuesCount = 0; -var divisor = profile[1][ignoreGaps ? 1 : 0]; -for (var c = ca.length - 1; profile[0][ca[c].charCodeAt (0)] > 0; c--) { -if (ca[c] != '-') { -rtnval[nextArrayPos++] = (ca[c]).charCodeAt (0); -var percentage = Clazz.floatToInt (profile[0][ca[c].charCodeAt (0)] * 100 / divisor); -rtnval[nextArrayPos++] = percentage; -totalPercentage += percentage; -distinctValuesCount++; -}} -rtnval[0] = distinctValuesCount; -rtnval[1] = totalPercentage; -var result = Clazz.newIntArray (rtnval.length + 1, 0); -result[0] = 0; -System.arraycopy (rtnval, 0, result, 1, rtnval.length); -return result; -}, "java.util.Hashtable,~B"); -c$.extractCdnaProfile = Clazz.defineMethod (c$, "extractCdnaProfile", -function (hashtable, ignoreGaps) { -var codonCounts = hashtable.get ("P"); -var sortedCounts = Clazz.newIntArray (codonCounts.length - 2, 0); -System.arraycopy (codonCounts, 2, sortedCounts, 0, codonCounts.length - 2); -var result = Clazz.newIntArray (3 + 2 * sortedCounts.length, 0); -result[0] = 2; -var codons = Clazz.newCharArray (sortedCounts.length, '\0'); -for (var i = 0; i < codons.length; i++) { -codons[i] = String.fromCharCode (i); -} -jalview.util.QuickSort.sortIntChar (sortedCounts, codons); -var totalPercentage = 0; -var distinctValuesCount = 0; -var j = 3; -var divisor = ignoreGaps ? codonCounts[1] : codonCounts[0]; -for (var i = codons.length - 1; i >= 0; i--) { -var codonCount = sortedCounts[i]; -if (codonCount == 0) { -break; -}distinctValuesCount++; -result[j++] = (codons[i]).charCodeAt (0); -var percentage = Clazz.doubleToInt (codonCount * 100 / divisor); -result[j++] = percentage; -totalPercentage += percentage; -} -result[2] = totalPercentage; -result[1] = distinctValuesCount; -return java.util.Arrays.copyOfRange (result, 0, j); -}, "java.util.Hashtable,~B"); -c$.calculateCdna = Clazz.defineMethod (c$, "calculateCdna", -function (alignment, mappings, hconsensus, col0, col1) { -var gapCharacter = alignment.getGapCharacter (); -for (var col = col0; col < col1; col++) { -var columnHash = new java.util.Hashtable (); -var codonCounts = Clazz.newIntArray (66, 0); -codonCounts[0] = alignment.getSequences ().size (); -var ungappedCount = 0; -for (var seq, $seq = alignment.getSequences ().iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) { -if (seq.getCharAt (col) == gapCharacter) { -continue; -}var codon = jalview.util.MappingUtils.findCodonFor (seq, col, mappings); -var codonEncoded = jalview.analysis.CodingUtils.encodeCodon (codon); -if (codonEncoded >= 0) { -codonCounts[codonEncoded + 2]++; -ungappedCount++; -}} -codonCounts[1] = ungappedCount; -columnHash.put ("P", codonCounts); -hconsensus[col] = columnHash; -} -}, "jalview.datamodel.AlignmentI,java.util.Set,~A,~N,~N"); -c$.completeCdnaConsensus = Clazz.defineMethod (c$, "completeCdnaConsensus", -function (consensusAnnotation, consensusData, showProfileLogo, nseqs) { -if (consensusAnnotation == null || consensusAnnotation.annotations == null || consensusAnnotation.annotations.length < consensusData.length) { -return; -}consensusAnnotation.scaleColLabel = true; -for (var col = 0; col < consensusData.length; col++) { -var hci = consensusData[col]; -if (hci == null) { -continue; -}var codonCounts = hci.get ("P"); -var totalCount = 0; -var codons = Clazz.newCharArray (codonCounts.length - 2, '\0'); -for (var j = 2; j < codonCounts.length; j++) { -var codonCount = codonCounts[j]; -codons[j - 2] = String.fromCharCode (j - 2); -totalCount += codonCount; -} -var sortedCodonCounts = Clazz.newIntArray (codonCounts.length - 2, 0); -System.arraycopy (codonCounts, 2, sortedCodonCounts, 0, codonCounts.length - 2); -jalview.util.QuickSort.sortIntChar (sortedCodonCounts, codons); -var modalCodonEncoded = (codons[codons.length - 1]).charCodeAt (0); -var modalCodonCount = sortedCodonCounts[codons.length - 1]; -var modalCodon = String.valueOf (jalview.analysis.CodingUtils.decodeCodon (modalCodonEncoded)); -if (sortedCodonCounts.length > 1 && sortedCodonCounts[codons.length - 2] == modalCodonEncoded) { -modalCodon = "+"; -}var pid = sortedCodonCounts[sortedCodonCounts.length - 1] * 100 / totalCount; -var mouseOver = new StringBuilder (32); -var samePercent = new StringBuilder (); -var percent = null; -var lastPercent = null; -var fmt = jalview.analysis.AAFrequency.getPercentageFormat (nseqs); -for (var j = codons.length - 1; j >= 0; j--) { -var codonCount = sortedCodonCounts[j]; -if (codonCount == 0) { -if (samePercent.length () > 0) { -mouseOver.append (samePercent).append (": ").append (percent).append ("% "); -}break; -}var codonEncoded = (codons[j]).charCodeAt (0); -var pct = Clazz.doubleToInt (codonCount * 100 / totalCount); -var codon = String.valueOf (jalview.analysis.CodingUtils.decodeCodon (codonEncoded)); -percent = fmt == null ? Integer.toString (pct) : fmt.formLong (pct); -if (showProfileLogo || codonCount == modalCodonCount) { -if (percent.equals (lastPercent) && j > 0) { -samePercent.append (samePercent.length () == 0 ? "" : ", "); -samePercent.append (codon); -} else { -if (samePercent.length () > 0) { -mouseOver.append (samePercent).append (": ").append (lastPercent).append ("% "); -}samePercent.setLength (0); -samePercent.append (codon); -}lastPercent = percent; -}} -consensusAnnotation.annotations[col] = new jalview.datamodel.Annotation (modalCodon, mouseOver.toString (), ' ', pid); -} -}, "jalview.datamodel.AlignmentAnnotation,~A,~B,~N"); -Clazz.defineStatics (c$, -"TO_UPPER_CASE", -32, -"MAXCOUNT", "C", -"MAXRESIDUE", "R", -"PID_GAPS", "G", -"PID_NOGAPS", "N", -"PROFILE", "P", -"ENCODED_CHARS", "E"); -c$.CHARS = c$.prototype.CHARS = new Array (26); -{ -for (var c = 'A'; c <= 'Z'; c = String.fromCharCode (c.charCodeAt (0) + 1)) { -jalview.analysis.AAFrequency.CHARS[c.charCodeAt (0) - 65] = String.valueOf (c); -} -}}); +Clazz.declarePackage ("jalview.analysis"); +Clazz.load (null, "jalview.analysis.AAFrequency", ["jalview.analysis.CodingUtils", "jalview.datamodel.Annotation", "jalview.util.Format", "$.MappingUtils", "$.QuickSort", "java.lang.Float", "$.StringBuilder", "java.util.Arrays", "$.Hashtable"], function () { +c$ = Clazz.declareType (jalview.analysis, "AAFrequency"); +c$.calculate = Clazz.defineMethod (c$, "calculate", +function (list, start, end) { +return jalview.analysis.AAFrequency.calculate (list, start, end, false); +}, "java.util.List,~N,~N"); +c$.calculate = Clazz.defineMethod (c$, "calculate", +function (sequences, start, end, profile) { +var seqs = new Array (sequences.size ()); +var width = 0; +{ +for (var i = 0; i < sequences.size (); i++) { +seqs[i] = sequences.get (i); +if (seqs[i].getLength () > width) { +width = seqs[i].getLength (); +}} +var reply = new Array (width); +if (end >= width) { +end = width; +}jalview.analysis.AAFrequency.calculate (seqs, start, end, reply, profile); +return reply; +}}, "java.util.List,~N,~N,~B"); +c$.calculate = Clazz.defineMethod (c$, "calculate", +function (sequences, start, end, result, profile) { +var residueHash; +var maxCount; +var nongap; +var i; +var j; +var v; +var jSize = sequences.length; +var maxResidue; +var c = '-'; +var percentage; +var values = Clazz.newIntArray (255, 0); +var seq; +for (i = start; i < end; i++) { +residueHash = new java.util.Hashtable (); +maxCount = 0; +maxResidue = ""; +nongap = 0; +values = Clazz.newIntArray (255, 0); +for (j = 0; j < jSize; j++) { +if (sequences[j] == null) { +System.err.println ("WARNING: Consensus skipping null sequence - possible race condition."); +continue; +}seq = sequences[j].getSequence (); +if (seq.length > i) { +c = seq[i]; +if (c == '.' || c == ' ') { +c = '-'; +}if (c == '-') { +values['-'.charCodeAt (0)]++; +continue; +} else if ('a' <= c && c <= 'z') { +c = String.fromCharCode (c.charCodeAt (0) + -32); +}nongap++; +values[c.charCodeAt (0)]++; +} else { +values['-'.charCodeAt (0)]++; +}} +if (jSize == 1) { +maxResidue = String.valueOf (c); +maxCount = 1; +} else { +for (v = 65; v <= 90; v++) { +if (values[v] < 1 || values[v] < maxCount) { +continue; +}if (values[v] > maxCount) { +maxResidue = jalview.analysis.AAFrequency.CHARS[v - 65]; +} else if (values[v] == maxCount) { +maxResidue += jalview.analysis.AAFrequency.CHARS[v - 65]; +}maxCount = values[v]; +} +}if (maxResidue.length == 0) { +maxResidue = "-"; +}if (profile) { +residueHash.put ("P", Clazz.newArray (-1, [values, Clazz.newIntArray (-1, [jSize, nongap])])); +}residueHash.put ("C", new Integer (maxCount)); +residueHash.put ("R", maxResidue); +percentage = (maxCount * 100) / jSize; +residueHash.put ("G", new Float (percentage)); +if (nongap > 0) { +percentage = (maxCount * 100) / nongap; +}residueHash.put ("N", new Float (percentage)); +result[i] = residueHash; +} +}, "~A,~N,~N,~A,~B"); +c$.completeConsensus = Clazz.defineMethod (c$, "completeConsensus", +function (consensus, hconsensus, iStart, width, ignoreGapsInConsensusCalculation, includeAllConsSymbols, nseq) { +jalview.analysis.AAFrequency.completeConsensus (consensus, hconsensus, iStart, width, ignoreGapsInConsensusCalculation, includeAllConsSymbols, null, nseq); +}, "jalview.datamodel.AlignmentAnnotation,~A,~N,~N,~B,~B,~N"); +c$.completeConsensus = Clazz.defineMethod (c$, "completeConsensus", +function (consensus, hconsensus, iStart, width, ignoreGapsInConsensusCalculation, includeAllConsSymbols, alphabet, nseq) { +if (consensus == null || consensus.annotations == null || consensus.annotations.length < width) { +return; +}var fmt = jalview.analysis.AAFrequency.getPercentageFormat (nseq); +for (var i = iStart; i < width; i++) { +var hci; +if (i >= hconsensus.length || ((hci = hconsensus[i]) == null)) { +consensus.annotations[i] = null; +continue; +}var fv = hci.get (ignoreGapsInConsensusCalculation ? "N" : "G"); +if (fv == null) { +consensus.annotations[i] = null; +continue; +}var value = fv.floatValue (); +var maxRes = hci.get ("R").toString (); +var mouseOver = new StringBuilder (64); +if (maxRes.length > 1) { +mouseOver.append ("[").append (maxRes).append ("] "); +maxRes = "+"; +} else { +mouseOver.append (hci.get ("R") + " "); +}var profile = hci.get ("P"); +if (profile != null && includeAllConsSymbols) { +var sequenceCount = profile[1][0]; +var nonGappedCount = profile[1][1]; +var normalisedBy = ignoreGapsInConsensusCalculation ? nonGappedCount : sequenceCount; +mouseOver.setLength (0); +if (alphabet != null) { +for (var c = 0; c < alphabet.length; c++) { +var tval = profile[0][alphabet[c].charCodeAt (0)] * 100 / normalisedBy; +mouseOver.append (((c == 0) ? "" : "; ")).append (alphabet[c]).append (" ").append (((fmt != null) ? fmt.formDouble (tval) : (Clazz.floatToInt (tval)))).append ("%"); +} +} else { +var ca = Clazz.newCharArray (profile[0].length, '\0'); +var vl = Clazz.newFloatArray (profile[0].length, 0); +for (var c = 0; c < ca.length; c++) { +ca[c] = String.fromCharCode (c); +vl[c] = profile[0][c]; +} +jalview.util.QuickSort.sortFloatChar (vl, ca); +for (var p = 0, c = ca.length - 1; profile[0][ca[c].charCodeAt (0)] > 0; c--) { +var residue = ca[c]; +if (residue != '-') { +var tval = profile[0][residue.charCodeAt (0)] * 100 / normalisedBy; +mouseOver.append ((((p == 0) ? "" : "; "))).append (residue).append (" ").append (((fmt != null) ? fmt.formDouble (tval) : (Clazz.floatToInt (tval)))).append ("%"); +p++; +}} +}} else { +mouseOver.append ((((fmt != null) ? fmt.formDouble (value) : (Clazz.floatToInt (value))))).append ("%"); +}consensus.annotations[i] = new jalview.datamodel.Annotation (maxRes, mouseOver.toString (), ' ', value); +} +}, "jalview.datamodel.AlignmentAnnotation,~A,~N,~N,~B,~B,~A,~N"); +c$.getPercentageFormat = Clazz.defineMethod (c$, "getPercentageFormat", +function (nseq) { +var scale = 0; +while (nseq >= 10) { +scale++; +nseq /= 10; +} +return scale <= 1 ? null : new jalview.util.Format ("%3." + (scale - 1) + "f"); +}, "~N"); +c$.extractProfile = Clazz.defineMethod (c$, "extractProfile", +function (hconsensus, ignoreGaps) { +var rtnval = Clazz.newIntArray (64, 0); +var profile = hconsensus.get ("P"); +if (profile == null) { +return null; +}var ca = Clazz.newCharArray (profile[0].length, '\0'); +var vl = Clazz.newFloatArray (profile[0].length, 0); +for (var c = 0; c < ca.length; c++) { +ca[c] = String.fromCharCode (c); +vl[c] = profile[0][c]; +} +jalview.util.QuickSort.sortFloatChar (vl, ca); +var nextArrayPos = 2; +var totalPercentage = 0; +var distinctValuesCount = 0; +var divisor = profile[1][ignoreGaps ? 1 : 0]; +for (var c = ca.length - 1; profile[0][ca[c].charCodeAt (0)] > 0; c--) { +if (ca[c] != '-') { +rtnval[nextArrayPos++] = (ca[c]).charCodeAt (0); +var percentage = Clazz.floatToInt (profile[0][ca[c].charCodeAt (0)] * 100 / divisor); +rtnval[nextArrayPos++] = percentage; +totalPercentage += percentage; +distinctValuesCount++; +}} +rtnval[0] = distinctValuesCount; +rtnval[1] = totalPercentage; +var result = Clazz.newIntArray (rtnval.length + 1, 0); +result[0] = 0; +System.arraycopy (rtnval, 0, result, 1, rtnval.length); +return result; +}, "java.util.Hashtable,~B"); +c$.extractCdnaProfile = Clazz.defineMethod (c$, "extractCdnaProfile", +function (hashtable, ignoreGaps) { +var codonCounts = hashtable.get ("P"); +var sortedCounts = Clazz.newIntArray (codonCounts.length - 2, 0); +System.arraycopy (codonCounts, 2, sortedCounts, 0, codonCounts.length - 2); +var result = Clazz.newIntArray (3 + 2 * sortedCounts.length, 0); +result[0] = 2; +var codons = Clazz.newCharArray (sortedCounts.length, '\0'); +for (var i = 0; i < codons.length; i++) { +codons[i] = String.fromCharCode (i); +} +jalview.util.QuickSort.sortIntChar (sortedCounts, codons); +var totalPercentage = 0; +var distinctValuesCount = 0; +var j = 3; +var divisor = ignoreGaps ? codonCounts[1] : codonCounts[0]; +for (var i = codons.length - 1; i >= 0; i--) { +var codonCount = sortedCounts[i]; +if (codonCount == 0) { +break; +}distinctValuesCount++; +result[j++] = (codons[i]).charCodeAt (0); +var percentage = Clazz.doubleToInt (codonCount * 100 / divisor); +result[j++] = percentage; +totalPercentage += percentage; +} +result[2] = totalPercentage; +result[1] = distinctValuesCount; +return java.util.Arrays.copyOfRange (result, 0, j); +}, "java.util.Hashtable,~B"); +c$.calculateCdna = Clazz.defineMethod (c$, "calculateCdna", +function (alignment, mappings, hconsensus, col0, col1) { +var gapCharacter = alignment.getGapCharacter (); +for (var col = col0; col < col1; col++) { +var columnHash = new java.util.Hashtable (); +var codonCounts = Clazz.newIntArray (66, 0); +codonCounts[0] = alignment.getSequences ().size (); +var ungappedCount = 0; +for (var seq, $seq = alignment.getSequences ().iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) { +if (seq.getCharAt (col) == gapCharacter) { +continue; +}var codon = jalview.util.MappingUtils.findCodonFor (seq, col, mappings); +var codonEncoded = jalview.analysis.CodingUtils.encodeCodon (codon); +if (codonEncoded >= 0) { +codonCounts[codonEncoded + 2]++; +ungappedCount++; +}} +codonCounts[1] = ungappedCount; +columnHash.put ("P", codonCounts); +hconsensus[col] = columnHash; +} +}, "jalview.datamodel.AlignmentI,java.util.Set,~A,~N,~N"); +c$.completeCdnaConsensus = Clazz.defineMethod (c$, "completeCdnaConsensus", +function (consensusAnnotation, consensusData, showProfileLogo, nseqs) { +if (consensusAnnotation == null || consensusAnnotation.annotations == null || consensusAnnotation.annotations.length < consensusData.length) { +return; +}consensusAnnotation.scaleColLabel = true; +for (var col = 0; col < consensusData.length; col++) { +var hci = consensusData[col]; +if (hci == null) { +continue; +}var codonCounts = hci.get ("P"); +var totalCount = 0; +var codons = Clazz.newCharArray (codonCounts.length - 2, '\0'); +for (var j = 2; j < codonCounts.length; j++) { +var codonCount = codonCounts[j]; +codons[j - 2] = String.fromCharCode (j - 2); +totalCount += codonCount; +} +var sortedCodonCounts = Clazz.newIntArray (codonCounts.length - 2, 0); +System.arraycopy (codonCounts, 2, sortedCodonCounts, 0, codonCounts.length - 2); +jalview.util.QuickSort.sortIntChar (sortedCodonCounts, codons); +var modalCodonEncoded = (codons[codons.length - 1]).charCodeAt (0); +var modalCodonCount = sortedCodonCounts[codons.length - 1]; +var modalCodon = String.valueOf (jalview.analysis.CodingUtils.decodeCodon (modalCodonEncoded)); +if (sortedCodonCounts.length > 1 && sortedCodonCounts[codons.length - 2] == modalCodonEncoded) { +modalCodon = "+"; +}var pid = sortedCodonCounts[sortedCodonCounts.length - 1] * 100 / totalCount; +var mouseOver = new StringBuilder (32); +var samePercent = new StringBuilder (); +var percent = null; +var lastPercent = null; +var fmt = jalview.analysis.AAFrequency.getPercentageFormat (nseqs); +for (var j = codons.length - 1; j >= 0; j--) { +var codonCount = sortedCodonCounts[j]; +if (codonCount == 0) { +if (samePercent.length () > 0) { +mouseOver.append (samePercent).append (": ").append (percent).append ("% "); +}break; +}var codonEncoded = (codons[j]).charCodeAt (0); +var pct = Clazz.doubleToInt (codonCount * 100 / totalCount); +var codon = String.valueOf (jalview.analysis.CodingUtils.decodeCodon (codonEncoded)); +percent = fmt == null ? Integer.toString (pct) : fmt.formLong (pct); +if (showProfileLogo || codonCount == modalCodonCount) { +if (percent.equals (lastPercent) && j > 0) { +samePercent.append (samePercent.length () == 0 ? "" : ", "); +samePercent.append (codon); +} else { +if (samePercent.length () > 0) { +mouseOver.append (samePercent).append (": ").append (lastPercent).append ("% "); +}samePercent.setLength (0); +samePercent.append (codon); +}lastPercent = percent; +}} +consensusAnnotation.annotations[col] = new jalview.datamodel.Annotation (modalCodon, mouseOver.toString (), ' ', pid); +} +}, "jalview.datamodel.AlignmentAnnotation,~A,~B,~N"); +Clazz.defineStatics (c$, +"TO_UPPER_CASE", -32, +"MAXCOUNT", "C", +"MAXRESIDUE", "R", +"PID_GAPS", "G", +"PID_NOGAPS", "N", +"PROFILE", "P", +"ENCODED_CHARS", "E"); +c$.CHARS = c$.prototype.CHARS = new Array (26); +{ +for (var c = 'A'; c <= 'Z'; c = String.fromCharCode (c.charCodeAt (0) + 1)) { +jalview.analysis.AAFrequency.CHARS[c.charCodeAt (0) - 65] = String.valueOf (c); +} +}});