X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=bin%2Fjalview%2Fanalysis%2FStructureFrequency.js;h=83c8f026b4617e023d51d7f9a51843663f876305;hp=6c90b65ed7bfb447e6b74757fef0084c619fca05;hb=8ffd05b3abe52c0b6b79b011c0966361f82d5fe6;hpb=6154cb57a6eac3bb1344b8342495f5bb701ee921 diff --git a/bin/jalview/analysis/StructureFrequency.js b/bin/jalview/analysis/StructureFrequency.js index 6c90b65..83c8f02 100644 --- a/bin/jalview/analysis/StructureFrequency.js +++ b/bin/jalview/analysis/StructureFrequency.js @@ -1,260 +1,260 @@ -Clazz.declarePackage ("jalview.analysis"); -Clazz.load (null, "jalview.analysis.StructureFrequency", ["jalview.datamodel.Annotation", "jalview.util.Format", "$.QuickSort", "java.lang.Float", "java.util.Hashtable", "javajs.util.AU"], function () { -c$ = Clazz.declareType (jalview.analysis, "StructureFrequency"); -c$.findPair = Clazz.defineMethod (c$, "findPair", -function (pairs, indice) { -for (var i = 0; i < pairs.length; i++) { -if (pairs[i].getBegin () == indice) { -return pairs[i].getEnd (); -}} -return -1; -}, "~A,~N"); -c$.calculate = Clazz.defineMethod (c$, "calculate", -function (sequences, start, end, result, profile, rnaStruc) { -var residueHash; -var maxResidue; -var struc = rnaStruc.getRNAStruc ().toCharArray (); -var rna = rnaStruc._rnasecstr; -var c; -var s; -var cEnd; -var count = 0; -var nonGap = 0; -var i; -var bpEnd = -1; -var j; -var jSize = sequences.length; -var values; -var pairs; -var percentage; -var wooble = true; -for (i = start; i < end; i++) { -residueHash = new java.util.Hashtable (); -maxResidue = "-"; -values = Clazz.newIntArray (255, 0); -pairs = Clazz.newIntArray (255, 255, 0); -bpEnd = -1; -if (i < struc.length) { -s = struc[i]; -} else { -s = '-'; -}if (s == '.' || s == ' ') { -s = '-'; -}if (s != '(' && s != '[') { -if (s == '-') { -values['-'.charCodeAt (0)]++; -}} else { -bpEnd = jalview.analysis.StructureFrequency.findPair (rna, i); -if (bpEnd > -1) { -for (j = 0; j < jSize; j++) { -if (sequences[j] == null) { -System.err.println ("WARNING: Consensus skipping null sequence - possible race condition."); -continue; -}c = sequences[j].getCharAt (i); -if (c == '.' || c == ' ') { -c = '-'; -}if (c == '-') { -values['-'.charCodeAt (0)]++; -continue; -}cEnd = sequences[j].getCharAt (bpEnd); -if (jalview.analysis.StructureFrequency.checkBpType (c, cEnd) == true) { -values['('.charCodeAt (0)]++; -maxResidue = "("; -wooble = true; -}if (jalview.analysis.StructureFrequency.checkBpType (c, cEnd) == false) { -wooble = false; -values['['.charCodeAt (0)]++; -maxResidue = "["; -}pairs[c.charCodeAt (0)][cEnd.charCodeAt (0)]++; -} -}}if (profile) { -residueHash.put ("P", Clazz.newArray (-1, [values, Clazz.newIntArray (-1, [jSize, (jSize - values['-'.charCodeAt (0)])])])); -residueHash.put ("B", pairs); -}if (wooble == true) { -count = values['('.charCodeAt (0)]; -}if (wooble == false) { -count = values['['.charCodeAt (0)]; -}residueHash.put ("C", new Integer (count)); -residueHash.put ("R", maxResidue); -percentage = (count * 100) / jSize; -residueHash.put ("G", new Float (percentage)); -if (result[i] == null) { -result[i] = residueHash; -}if (bpEnd > 0) { -values[')'.charCodeAt (0)] = values['('.charCodeAt (0)]; -values[']'.charCodeAt (0)] = values['['.charCodeAt (0)]; -values['('.charCodeAt (0)] = 0; -values['['.charCodeAt (0)] = 0; -residueHash = new java.util.Hashtable (); -if (wooble == true) { -maxResidue = ")"; -}if (wooble == false) { -maxResidue = "]"; -}if (profile) { -residueHash.put ("P", Clazz.newArray (-1, [values, Clazz.newIntArray (-1, [jSize, (jSize - values['-'.charCodeAt (0)])])])); -residueHash.put ("B", pairs); -}residueHash.put ("C", new Integer (count)); -residueHash.put ("R", maxResidue); -percentage = (count * 100) / jSize; -residueHash.put ("G", new Float (percentage)); -result[bpEnd] = residueHash; -}} -}, "~A,~N,~N,~A,~B,jalview.datamodel.AlignmentAnnotation"); -c$.checkBpType = Clazz.defineMethod (c$, "checkBpType", -function (up, down) { -if (up > 'Z') { -up = String.fromCharCode (up.charCodeAt (0) - 32); -}if (down > 'Z') { -down = String.fromCharCode (down.charCodeAt (0) - 32); -}switch (up) { -case 'A': -switch (down) { -case 'T': -return true; -case 'U': -return true; -} -break; -case 'C': -switch (down) { -case 'G': -return true; -} -break; -case 'T': -switch (down) { -case 'A': -return true; -case 'G': -return true; -} -break; -case 'G': -switch (down) { -case 'C': -return true; -case 'T': -return true; -case 'U': -return true; -} -break; -case 'U': -switch (down) { -case 'A': -return true; -case 'G': -return true; -} -break; -} -return false; -}, "~S,~S"); -c$.completeConsensus = Clazz.defineMethod (c$, "completeConsensus", -function (consensus, hconsensus, iStart, width, ignoreGapsInConsensusCalculation, includeAllConsSymbols, nseq) { -var tval; -var value; -if (consensus == null || consensus.annotations == null || consensus.annotations.length < width) { -return; -}var fmtstr = "%3.1f"; -var precision = 2; -while (nseq > 100) { -precision++; -nseq /= 10; -} -if (precision > 2) { -fmtstr = "%" + (2 + precision) + "." + precision + "f"; -}var fmt = new jalview.util.Format (fmtstr); -for (var i = iStart; i < width; i++) { -var hci; -if (i >= hconsensus.length || ((hci = hconsensus[i]) == null)) { -consensus.annotations[i] = null; -continue; -}value = 0; -var fv; -if (ignoreGapsInConsensusCalculation) { -fv = hci.get ("N"); -} else { -fv = hci.get ("G"); -}if (fv == null) { -consensus.annotations[i] = null; -continue; -}value = fv.floatValue (); -var maxRes = hci.get ("R").toString (); -var mouseOver = hci.get ("R") + " "; -if (maxRes.length > 1) { -mouseOver = "[" + maxRes + "] "; -maxRes = "+"; -}var profile = hci.get ("P"); -var pairs = hci.get ("B"); -if (pairs != null && includeAllConsSymbols) { -mouseOver = ""; -var ca = javajs.util.AU.newInt2 (625); -var vl = Clazz.newFloatArray (625, 0); -var x = 0; -for (var c = 65; c < 90; c++) { -for (var d = 65; d < 90; d++) { -ca[x] = Clazz.newIntArray (-1, [c, d]); -vl[x] = pairs[c][d]; -x++; -} -} -jalview.util.QuickSort.sortFloatObject (vl, ca); -var p = 0; -var divisor = profile[1][ignoreGapsInConsensusCalculation ? 1 : 0]; -for (var c = 624; c > 0; c--) { -if (vl[c] > 0) { -tval = (vl[c] * 100 / divisor); -mouseOver += ((p == 0) ? "" : "; ") + String.fromCharCode (ca[c][0]) + String.fromCharCode (ca[c][1]) + " " + fmt.formDouble (tval) + "%"; -p++; -}} -} else { -mouseOver += (fmt.formDouble (value) + "%"); -}consensus.annotations[i] = new jalview.datamodel.Annotation (maxRes, mouseOver, ' ', value); -} -}, "jalview.datamodel.AlignmentAnnotation,~A,~N,~N,~B,~B,~N"); -c$.extractProfile = Clazz.defineMethod (c$, "extractProfile", -function (hconsensus, ignoreGapsInConsensusCalculation) { -var rtnval = Clazz.newIntArray (74, 0); -var profile = hconsensus.get ("P"); -var pairs = hconsensus.get ("B"); -if (profile == null) { -return null; -}var ca = javajs.util.AU.newInt2 (625); -var vl = Clazz.newFloatArray (625, 0); -var x = 0; -for (var c = 65; c < 90; c++) { -for (var d = 65; d < 90; d++) { -ca[x] = Clazz.newIntArray (-1, [c, d]); -vl[x] = pairs[c][d]; -x++; -} -} -jalview.util.QuickSort.sortFloatObject (vl, ca); -var valuesCount = 0; -rtnval[1] = 0; -var offset = 2; -var divisor = profile[1][ignoreGapsInConsensusCalculation ? 1 : 0]; -for (var c = 624; c > 0; c--) { -if (vl[c] > 0) { -rtnval[offset++] = ca[c][0]; -rtnval[offset++] = ca[c][1]; -rtnval[offset] = Clazz.floatToInt (vl[c] * 100 / divisor); -rtnval[1] += rtnval[offset++]; -valuesCount++; -}} -rtnval[0] = valuesCount; -var result = Clazz.newIntArray (rtnval.length + 1, 0); -result[0] = 1; -System.arraycopy (rtnval, 0, result, 1, rtnval.length); -return result; -}, "java.util.Hashtable,~B"); -Clazz.defineStatics (c$, -"STRUCTURE_PROFILE_LENGTH", 74, -"MAXCOUNT", "C", -"MAXRESIDUE", "R", -"PID_GAPS", "G", -"PID_NOGAPS", "N", -"PROFILE", "P", -"PAIRPROFILE", "B"); -}); +Clazz.declarePackage ("jalview.analysis"); +Clazz.load (null, "jalview.analysis.StructureFrequency", ["jalview.datamodel.Annotation", "jalview.util.Format", "$.QuickSort", "java.lang.Float", "java.util.Hashtable", "javajs.util.AU"], function () { +c$ = Clazz.declareType (jalview.analysis, "StructureFrequency"); +c$.findPair = Clazz.defineMethod (c$, "findPair", +function (pairs, indice) { +for (var i = 0; i < pairs.length; i++) { +if (pairs[i].getBegin () == indice) { +return pairs[i].getEnd (); +}} +return -1; +}, "~A,~N"); +c$.calculate = Clazz.defineMethod (c$, "calculate", +function (sequences, start, end, result, profile, rnaStruc) { +var residueHash; +var maxResidue; +var struc = rnaStruc.getRNAStruc ().toCharArray (); +var rna = rnaStruc._rnasecstr; +var c; +var s; +var cEnd; +var count = 0; +var nonGap = 0; +var i; +var bpEnd = -1; +var j; +var jSize = sequences.length; +var values; +var pairs; +var percentage; +var wooble = true; +for (i = start; i < end; i++) { +residueHash = new java.util.Hashtable (); +maxResidue = "-"; +values = Clazz.newIntArray (255, 0); +pairs = Clazz.newIntArray (255, 255, 0); +bpEnd = -1; +if (i < struc.length) { +s = struc[i]; +} else { +s = '-'; +}if (s == '.' || s == ' ') { +s = '-'; +}if (s != '(' && s != '[') { +if (s == '-') { +values['-'.charCodeAt (0)]++; +}} else { +bpEnd = jalview.analysis.StructureFrequency.findPair (rna, i); +if (bpEnd > -1) { +for (j = 0; j < jSize; j++) { +if (sequences[j] == null) { +System.err.println ("WARNING: Consensus skipping null sequence - possible race condition."); +continue; +}c = sequences[j].getCharAt (i); +if (c == '.' || c == ' ') { +c = '-'; +}if (c == '-') { +values['-'.charCodeAt (0)]++; +continue; +}cEnd = sequences[j].getCharAt (bpEnd); +if (jalview.analysis.StructureFrequency.checkBpType (c, cEnd) == true) { +values['('.charCodeAt (0)]++; +maxResidue = "("; +wooble = true; +}if (jalview.analysis.StructureFrequency.checkBpType (c, cEnd) == false) { +wooble = false; +values['['.charCodeAt (0)]++; +maxResidue = "["; +}pairs[c.charCodeAt (0)][cEnd.charCodeAt (0)]++; +} +}}if (profile) { +residueHash.put ("P", Clazz.newArray (-1, [values, Clazz.newIntArray (-1, [jSize, (jSize - values['-'.charCodeAt (0)])])])); +residueHash.put ("B", pairs); +}if (wooble == true) { +count = values['('.charCodeAt (0)]; +}if (wooble == false) { +count = values['['.charCodeAt (0)]; +}residueHash.put ("C", new Integer (count)); +residueHash.put ("R", maxResidue); +percentage = (count * 100) / jSize; +residueHash.put ("G", new Float (percentage)); +if (result[i] == null) { +result[i] = residueHash; +}if (bpEnd > 0) { +values[')'.charCodeAt (0)] = values['('.charCodeAt (0)]; +values[']'.charCodeAt (0)] = values['['.charCodeAt (0)]; +values['('.charCodeAt (0)] = 0; +values['['.charCodeAt (0)] = 0; +residueHash = new java.util.Hashtable (); +if (wooble == true) { +maxResidue = ")"; +}if (wooble == false) { +maxResidue = "]"; +}if (profile) { +residueHash.put ("P", Clazz.newArray (-1, [values, Clazz.newIntArray (-1, [jSize, (jSize - values['-'.charCodeAt (0)])])])); +residueHash.put ("B", pairs); +}residueHash.put ("C", new Integer (count)); +residueHash.put ("R", maxResidue); +percentage = (count * 100) / jSize; +residueHash.put ("G", new Float (percentage)); +result[bpEnd] = residueHash; +}} +}, "~A,~N,~N,~A,~B,jalview.datamodel.AlignmentAnnotation"); +c$.checkBpType = Clazz.defineMethod (c$, "checkBpType", +function (up, down) { +if (up > 'Z') { +up = String.fromCharCode (up.charCodeAt (0) - 32); +}if (down > 'Z') { +down = String.fromCharCode (down.charCodeAt (0) - 32); +}switch (up) { +case 'A': +switch (down) { +case 'T': +return true; +case 'U': +return true; +} +break; +case 'C': +switch (down) { +case 'G': +return true; +} +break; +case 'T': +switch (down) { +case 'A': +return true; +case 'G': +return true; +} +break; +case 'G': +switch (down) { +case 'C': +return true; +case 'T': +return true; +case 'U': +return true; +} +break; +case 'U': +switch (down) { +case 'A': +return true; +case 'G': +return true; +} +break; +} +return false; +}, "~S,~S"); +c$.completeConsensus = Clazz.defineMethod (c$, "completeConsensus", +function (consensus, hconsensus, iStart, width, ignoreGapsInConsensusCalculation, includeAllConsSymbols, nseq) { +var tval; +var value; +if (consensus == null || consensus.annotations == null || consensus.annotations.length < width) { +return; +}var fmtstr = "%3.1f"; +var precision = 2; +while (nseq > 100) { +precision++; +nseq /= 10; +} +if (precision > 2) { +fmtstr = "%" + (2 + precision) + "." + precision + "f"; +}var fmt = new jalview.util.Format (fmtstr); +for (var i = iStart; i < width; i++) { +var hci; +if (i >= hconsensus.length || ((hci = hconsensus[i]) == null)) { +consensus.annotations[i] = null; +continue; +}value = 0; +var fv; +if (ignoreGapsInConsensusCalculation) { +fv = hci.get ("N"); +} else { +fv = hci.get ("G"); +}if (fv == null) { +consensus.annotations[i] = null; +continue; +}value = fv.floatValue (); +var maxRes = hci.get ("R").toString (); +var mouseOver = hci.get ("R") + " "; +if (maxRes.length > 1) { +mouseOver = "[" + maxRes + "] "; +maxRes = "+"; +}var profile = hci.get ("P"); +var pairs = hci.get ("B"); +if (pairs != null && includeAllConsSymbols) { +mouseOver = ""; +var ca = javajs.util.AU.newInt2 (625); +var vl = Clazz.newFloatArray (625, 0); +var x = 0; +for (var c = 65; c < 90; c++) { +for (var d = 65; d < 90; d++) { +ca[x] = Clazz.newIntArray (-1, [c, d]); +vl[x] = pairs[c][d]; +x++; +} +} +jalview.util.QuickSort.sortFloatObject (vl, ca); +var p = 0; +var divisor = profile[1][ignoreGapsInConsensusCalculation ? 1 : 0]; +for (var c = 624; c > 0; c--) { +if (vl[c] > 0) { +tval = (vl[c] * 100 / divisor); +mouseOver += ((p == 0) ? "" : "; ") + String.fromCharCode (ca[c][0]) + String.fromCharCode (ca[c][1]) + " " + fmt.formDouble (tval) + "%"; +p++; +}} +} else { +mouseOver += (fmt.formDouble (value) + "%"); +}consensus.annotations[i] = new jalview.datamodel.Annotation (maxRes, mouseOver, ' ', value); +} +}, "jalview.datamodel.AlignmentAnnotation,~A,~N,~N,~B,~B,~N"); +c$.extractProfile = Clazz.defineMethod (c$, "extractProfile", +function (hconsensus, ignoreGapsInConsensusCalculation) { +var rtnval = Clazz.newIntArray (74, 0); +var profile = hconsensus.get ("P"); +var pairs = hconsensus.get ("B"); +if (profile == null) { +return null; +}var ca = javajs.util.AU.newInt2 (625); +var vl = Clazz.newFloatArray (625, 0); +var x = 0; +for (var c = 65; c < 90; c++) { +for (var d = 65; d < 90; d++) { +ca[x] = Clazz.newIntArray (-1, [c, d]); +vl[x] = pairs[c][d]; +x++; +} +} +jalview.util.QuickSort.sortFloatObject (vl, ca); +var valuesCount = 0; +rtnval[1] = 0; +var offset = 2; +var divisor = profile[1][ignoreGapsInConsensusCalculation ? 1 : 0]; +for (var c = 624; c > 0; c--) { +if (vl[c] > 0) { +rtnval[offset++] = ca[c][0]; +rtnval[offset++] = ca[c][1]; +rtnval[offset] = Clazz.floatToInt (vl[c] * 100 / divisor); +rtnval[1] += rtnval[offset++]; +valuesCount++; +}} +rtnval[0] = valuesCount; +var result = Clazz.newIntArray (rtnval.length + 1, 0); +result[0] = 1; +System.arraycopy (rtnval, 0, result, 1, rtnval.length); +return result; +}, "java.util.Hashtable,~B"); +Clazz.defineStatics (c$, +"STRUCTURE_PROFILE_LENGTH", 74, +"MAXCOUNT", "C", +"MAXRESIDUE", "R", +"PID_GAPS", "G", +"PID_NOGAPS", "N", +"PROFILE", "P", +"PAIRPROFILE", "B"); +});