X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=bin%2Fjalview%2Fanalysis%2FNJTree.js;h=8f3a36749a7cc70c13b1f12c85b06eda321cae94;hp=24a8fc55dd910ce317f5581ff41e82e2e823e237;hb=7301a2415adab88038b291fc54caeeb3a5a47a44;hpb=6154cb57a6eac3bb1344b8342495f5bb701ee921 diff --git a/bin/jalview/analysis/NJTree.js b/bin/jalview/analysis/NJTree.js index 24a8fc5..8f3a367 100644 --- a/bin/jalview/analysis/NJTree.js +++ b/bin/jalview/analysis/NJTree.js @@ -1,577 +1,577 @@ -Clazz.declarePackage ("jalview.analysis"); -Clazz.load (["java.util.Vector"], ["jalview.analysis.Cluster", "$.NJTree"], ["jalview.analysis.SequenceIdMatcher", "jalview.datamodel.AlignmentView", "$.CigarArray", "$.NodeTransformI", "$.SeqCigar", "$.Sequence", "$.SequenceI", "$.SequenceNode", "jalview.io.NewickFile", "jalview.schemes.ResidueProperties", "jalview.util.Format", "java.lang.StringBuffer"], function () { -c$ = Clazz.decorateAsClass (function () { -this.$cluster = null; -this.sequence = null; -this.seqData = null; -this.done = null; -this.noseqs = 0; -this.noClus = 0; -this.distance = null; -this.mini = 0; -this.minj = 0; -this.ri = 0; -this.rj = 0; -this.groups = null; -this.maxdist = null; -this.top = null; -this.maxDistValue = 0; -this.maxheight = 0; -this.ycount = 0; -this.node = null; -this.type = null; -this.pwtype = null; -this.found = null; -this.leaves = null; -this.hasDistances = true; -this.hasBootstrap = false; -this.hasRootDistance = true; -this._lycount = 0; -this._lylimit = 0; -Clazz.instantialize (this, arguments); -}, jalview.analysis, "NJTree"); -Clazz.prepareFields (c$, function () { -this.groups = new java.util.Vector (); -}); -Clazz.makeConstructor (c$, -function (seqs, odata, treefile) { -this.construct (seqs, treefile); -if (odata != null) { -this.seqData = odata; -}}, "~A,jalview.datamodel.AlignmentView,jalview.io.NewickFile"); -Clazz.makeConstructor (c$, -function (seqs, treefile) { -this.sequence = seqs; -this.top = treefile.getTree (); -this.hasDistances = treefile.HasDistances (); -this.hasBootstrap = treefile.HasBootstrap (); -this.hasRootDistance = treefile.HasRootDistance (); -this.maxheight = this.findHeight (this.top); -var algnIds = new jalview.analysis.SequenceIdMatcher (seqs); -var leaves = new java.util.Vector (); -this.findLeaves (this.top, leaves); -var i = 0; -var namesleft = seqs.length; -var j; -var nam; -var realnam; -var one2many = new java.util.Vector (); -var countOne2Many = 0; -while (i < leaves.size ()) { -j = leaves.elementAt (i++); -realnam = j.getName (); -nam = null; -if (namesleft > -1) { -nam = algnIds.findIdMatch (realnam); -}if (nam != null) { -j.setElement (nam); -if (one2many.contains (nam)) { -countOne2Many++; -} else { -one2many.addElement (nam); -namesleft--; -}} else { -j.setElement ( new jalview.datamodel.Sequence (realnam, "THISISAPLACEHLDER")); -j.setPlaceholder (true); -}} -}, "~A,jalview.io.NewickFile"); -Clazz.makeConstructor (c$, -function (sequence, seqData, type, pwtype, sm, start, end) { -this.sequence = sequence; -this.node = new java.util.Vector (); -this.type = type; -this.pwtype = pwtype; -if (seqData != null) { -this.seqData = seqData; -} else { -var seqs = new Array (sequence.length); -for (var i = 0; i < sequence.length; i++) { -seqs[i] = new jalview.datamodel.SeqCigar (sequence[i], start, end); -} -var sdata = new jalview.datamodel.CigarArray (seqs); -sdata.addOperation ('M', end - start + 1); -this.seqData = new jalview.datamodel.AlignmentView (sdata, start); -}if (!(type.equals ("NJ"))) { -type = "AV"; -}if (sm == null && !(pwtype.equals ("PID"))) { -if (jalview.schemes.ResidueProperties.getScoreMatrix (pwtype) == null) { -pwtype = "BLOSUM62"; -}}var i = 0; -this.done = Clazz.newIntArray (sequence.length, 0); -while ((i < sequence.length) && (sequence[i] != null)) { -this.done[i] = 0; -i++; -} -this.noseqs = i++; -this.distance = this.findDistances (sm); -this.makeLeaves (); -this.noClus = this.$cluster.size (); -this.cluster (); -}, "~A,jalview.datamodel.AlignmentView,~S,~S,jalview.api.analysis.ScoreModelI,~N,~N"); -Clazz.overrideMethod (c$, "toString", -function () { -var fout = new jalview.io.NewickFile (this.getTopNode ()); -return fout.print (this.isHasBootstrap (), this.isHasDistances (), this.isHasRootDistance ()); -}); -Clazz.defineMethod (c$, "UpdatePlaceHolders", -function (list) { -var leaves = new java.util.Vector (); -this.findLeaves (this.top, leaves); -var sz = leaves.size (); -var seqmatcher = null; -var i = 0; -while (i < sz) { -var leaf = leaves.elementAt (i++); -if (list.contains (leaf.element ())) { -leaf.setPlaceholder (false); -} else { -if (seqmatcher == null) { -var seqs = new Array (list.size ()); -for (var j = 0; j < seqs.length; j++) { -seqs[j] = list.get (j); -} -seqmatcher = new jalview.analysis.SequenceIdMatcher (seqs); -}var nam = seqmatcher.findIdMatch (leaf.getName ()); -if (nam != null) { -if (!leaf.isPlaceholder ()) { -}leaf.setPlaceholder (false); -leaf.setElement (nam); -} else { -if (!leaf.isPlaceholder ()) { -leaf.setElement ( new jalview.datamodel.Sequence (leaf.getName (), "THISISAPLACEHLDER")); -}leaf.setPlaceholder (true); -}}} -}, "java.util.List"); -Clazz.defineMethod (c$, "renameAssociatedNodes", -function () { -this.applyToNodes (((Clazz.isClassDefined ("jalview.analysis.NJTree$1") ? 0 : jalview.analysis.NJTree.$NJTree$1$ ()), Clazz.innerTypeInstance (jalview.analysis.NJTree$1, this, null))); -}); -Clazz.defineMethod (c$, "cluster", -function () { -while (this.noClus > 2) { -if (this.type.equals ("NJ")) { -this.findMinNJDistance (); -} else { -this.findMinDistance (); -}var c = this.joinClusters (this.mini, this.minj); -this.done[this.minj] = 1; -this.$cluster.setElementAt (null, this.minj); -this.$cluster.setElementAt (c, this.mini); -this.noClus--; -} -var onefound = false; -var one = -1; -var two = -1; -for (var i = 0; i < this.noseqs; i++) { -if (this.done[i] != 1) { -if (onefound == false) { -two = i; -onefound = true; -} else { -one = i; -}}} -this.joinClusters (one, two); -this.top = (this.node.elementAt (one)); -this.reCount (this.top); -this.findHeight (this.top); -this.findMaxDist (this.top); -}); -Clazz.defineMethod (c$, "joinClusters", -function (i, j) { -var dist = this.distance[i][j]; -var noi = (this.$cluster.elementAt (i)).value.length; -var noj = (this.$cluster.elementAt (j)).value.length; -var value = Clazz.newIntArray (noi + noj, 0); -for (var ii = 0; ii < noi; ii++) { -value[ii] = (this.$cluster.elementAt (i)).value[ii]; -} -for (var ii = noi; ii < (noi + noj); ii++) { -value[ii] = (this.$cluster.elementAt (j)).value[ii - noi]; -} -var c = new jalview.analysis.Cluster (value); -this.ri = this.findr (i, j); -this.rj = this.findr (j, i); -if (this.type.equals ("NJ")) { -this.findClusterNJDistance (i, j); -} else { -this.findClusterDistance (i, j); -}var sn = new jalview.datamodel.SequenceNode (); -sn.setLeft ((this.node.elementAt (i))); -sn.setRight ((this.node.elementAt (j))); -var tmpi = (this.node.elementAt (i)); -var tmpj = (this.node.elementAt (j)); -if (this.type.equals ("NJ")) { -this.findNewNJDistances (tmpi, tmpj, dist); -} else { -this.findNewDistances (tmpi, tmpj, dist); -}tmpi.setParent (sn); -tmpj.setParent (sn); -this.node.setElementAt (sn, i); -return c; -}, "~N,~N"); -Clazz.defineMethod (c$, "findNewNJDistances", -function (tmpi, tmpj, dist) { -tmpi.dist = ((dist + this.ri) - this.rj) / 2; -tmpj.dist = (dist - tmpi.dist); -if (tmpi.dist < 0) { -tmpi.dist = 0; -}if (tmpj.dist < 0) { -tmpj.dist = 0; -}}, "jalview.datamodel.SequenceNode,jalview.datamodel.SequenceNode,~N"); -Clazz.defineMethod (c$, "findNewDistances", -function (tmpi, tmpj, dist) { -var ih = 0; -var jh = 0; -var sni = tmpi; -var snj = tmpj; -while (sni != null) { -ih = ih + sni.dist; -sni = sni.left (); -} -while (snj != null) { -jh = jh + snj.dist; -snj = snj.left (); -} -tmpi.dist = ((dist / 2) - ih); -tmpj.dist = ((dist / 2) - jh); -}, "jalview.datamodel.SequenceNode,jalview.datamodel.SequenceNode,~N"); -Clazz.defineMethod (c$, "findClusterDistance", -function (i, j) { -var noi = (this.$cluster.elementAt (i)).value.length; -var noj = (this.$cluster.elementAt (j)).value.length; -var newdist = Clazz.newFloatArray (this.noseqs, 0); -for (var l = 0; l < this.noseqs; l++) { -if ((l != i) && (l != j)) { -newdist[l] = ((this.distance[i][l] * noi) + (this.distance[j][l] * noj)) / (noi + noj); -} else { -newdist[l] = 0; -}} -for (var ii = 0; ii < this.noseqs; ii++) { -this.distance[i][ii] = newdist[ii]; -this.distance[ii][i] = newdist[ii]; -} -}, "~N,~N"); -Clazz.defineMethod (c$, "findClusterNJDistance", -function (i, j) { -var newdist = Clazz.newFloatArray (this.noseqs, 0); -for (var l = 0; l < this.noseqs; l++) { -if ((l != i) && (l != j)) { -newdist[l] = ((this.distance[i][l] + this.distance[j][l]) - this.distance[i][j]) / 2; -} else { -newdist[l] = 0; -}} -for (var ii = 0; ii < this.noseqs; ii++) { -this.distance[i][ii] = newdist[ii]; -this.distance[ii][i] = newdist[ii]; -} -}, "~N,~N"); -Clazz.defineMethod (c$, "findr", -function (i, j) { -var tmp = 1; -for (var k = 0; k < this.noseqs; k++) { -if ((k != i) && (k != j) && (this.done[k] != 1)) { -tmp = tmp + this.distance[i][k]; -}} -if (this.noClus > 2) { -tmp = tmp / (this.noClus - 2); -}return tmp; -}, "~N,~N"); -Clazz.defineMethod (c$, "findMinNJDistance", -function () { -var min = 100000; -for (var i = 0; i < (this.noseqs - 1); i++) { -for (var j = i + 1; j < this.noseqs; j++) { -if ((this.done[i] != 1) && (this.done[j] != 1)) { -var tmp = this.distance[i][j] - (this.findr (i, j) + this.findr (j, i)); -if (tmp < min) { -this.mini = i; -this.minj = j; -min = tmp; -}}} -} -return min; -}); -Clazz.defineMethod (c$, "findMinDistance", -function () { -var min = 100000; -for (var i = 0; i < (this.noseqs - 1); i++) { -for (var j = i + 1; j < this.noseqs; j++) { -if ((this.done[i] != 1) && (this.done[j] != 1)) { -if (this.distance[i][j] < min) { -this.mini = i; -this.minj = j; -min = this.distance[i][j]; -}}} -} -return min; -}); -Clazz.defineMethod (c$, "findDistances", -function (_pwmatrix) { -var distance = Clazz.newFloatArray (this.noseqs, this.noseqs, 0); -if (_pwmatrix == null) { -_pwmatrix = jalview.schemes.ResidueProperties.getScoreModel (this.pwtype); -if (_pwmatrix == null) { -_pwmatrix = jalview.schemes.ResidueProperties.getScoreMatrix ("BLOSUM62"); -}}distance = _pwmatrix.findDistances (this.seqData); -return distance; -}, "jalview.api.analysis.ScoreModelI"); -Clazz.defineMethod (c$, "makeLeaves", -function () { -this.$cluster = new java.util.Vector (); -for (var i = 0; i < this.noseqs; i++) { -var sn = new jalview.datamodel.SequenceNode (); -sn.setElement (this.sequence[i]); -sn.setName (this.sequence[i].getName ()); -this.node.addElement (sn); -var value = Clazz.newIntArray (1, 0); -value[0] = i; -var c = new jalview.analysis.Cluster (value); -this.$cluster.addElement (c); -} -}); -Clazz.defineMethod (c$, "findLeaves", -function (node, leaves) { -if (node == null) { -return leaves; -}if ((node.left () == null) && (node.right () == null)) { -leaves.addElement (node); -return leaves; -} else { -this.findLeaves (node.left (), leaves); -this.findLeaves (node.right (), leaves); -}return leaves; -}, "jalview.datamodel.SequenceNode,java.util.Vector"); -Clazz.defineMethod (c$, "findLeaf", -function (node, count) { -this.found = this._findLeaf (node, count); -return this.found; -}, "jalview.datamodel.SequenceNode,~N"); -Clazz.defineMethod (c$, "_findLeaf", -function (node, count) { -if (node == null) { -return null; -}if (node.ycount == count) { -this.found = node.element (); -return this.found; -} else { -this._findLeaf (node.left (), count); -this._findLeaf (node.right (), count); -}return this.found; -}, "jalview.datamodel.SequenceNode,~N"); -Clazz.defineMethod (c$, "printNode", -function (node) { -if (node == null) { -return; -}if ((node.left () == null) && (node.right () == null)) { -System.out.println ("Leaf = " + (node.element ()).getName ()); -System.out.println ("Dist " + node.dist); -System.out.println ("Boot " + node.getBootstrap ()); -} else { -System.out.println ("Dist " + node.dist); -this.printNode (node.left ()); -this.printNode (node.right ()); -}}, "jalview.datamodel.SequenceNode"); -Clazz.defineMethod (c$, "findMaxDist", -function (node) { -if (node == null) { -return; -}if ((node.left () == null) && (node.right () == null)) { -var dist = node.dist; -if (dist > this.maxDistValue) { -this.maxdist = node; -this.maxDistValue = dist; -}} else { -this.findMaxDist (node.left ()); -this.findMaxDist (node.right ()); -}}, "jalview.datamodel.SequenceNode"); -Clazz.defineMethod (c$, "getGroups", -function () { -return this.groups; -}); -Clazz.defineMethod (c$, "getMaxHeight", -function () { -return this.maxheight; -}); -Clazz.defineMethod (c$, "groupNodes", -function (node, threshold) { -if (node == null) { -return; -}if ((node.height / this.maxheight) > threshold) { -this.groups.addElement (node); -} else { -this.groupNodes (node.left (), threshold); -this.groupNodes (node.right (), threshold); -}}, "jalview.datamodel.SequenceNode,~N"); -Clazz.defineMethod (c$, "findHeight", -function (node) { -if (node == null) { -return this.maxheight; -}if ((node.left () == null) && (node.right () == null)) { -node.height = (node.parent ()).height + node.dist; -if (node.height > this.maxheight) { -return node.height; -} else { -return this.maxheight; -}} else { -if (node.parent () != null) { -node.height = (node.parent ()).height + node.dist; -} else { -this.maxheight = 0; -node.height = 0.0; -}this.maxheight = this.findHeight ((node.left ())); -this.maxheight = this.findHeight ((node.right ())); -}return this.maxheight; -}, "jalview.datamodel.SequenceNode"); -Clazz.defineMethod (c$, "reRoot", -function () { -if (this.maxdist != null) { -this.ycount = 0; -var tmpdist = this.maxdist.dist; -var sn = new jalview.datamodel.SequenceNode (); -sn.setParent (null); -var snr = this.maxdist.parent (); -this.changeDirection (snr, this.maxdist); -System.out.println ("Printing reversed tree"); -this.printN (snr); -snr.dist = tmpdist / 2; -this.maxdist.dist = tmpdist / 2; -snr.setParent (sn); -this.maxdist.setParent (sn); -sn.setRight (snr); -sn.setLeft (this.maxdist); -this.top = sn; -this.ycount = 0; -this.reCount (this.top); -this.findHeight (this.top); -}return this.top; -}); -Clazz.defineMethod (c$, "hasOriginalSequenceData", -function () { -return this.seqData != null; -}); -Clazz.defineMethod (c$, "printOriginalSequenceData", -function (gapChar) { -if (this.seqData == null) { -return null; -}var sb = new StringBuffer (); -var seqdatas = this.seqData.getSequenceStrings (gapChar); -for (var i = 0; i < seqdatas.length; i++) { -sb.append ( new jalview.util.Format ("%-15s").form (this.sequence[i].getName ())); -sb.append (" " + seqdatas[i] + "\n"); -} -return sb.toString (); -}, "~S"); -Clazz.defineMethod (c$, "printN", -function (node) { -if (node == null) { -return; -}if ((node.left () != null) && (node.right () != null)) { -this.printN (node.left ()); -this.printN (node.right ()); -} else { -System.out.println (" name = " + (node.element ()).getName ()); -}System.out.println (" dist = " + node.dist + " " + node.count + " " + node.height); -}, "jalview.datamodel.SequenceNode"); -Clazz.defineMethod (c$, "reCount", -function (node) { -this.ycount = 0; -this._lycount = 0; -this._reCount (node); -}, "jalview.datamodel.SequenceNode"); -Clazz.defineMethod (c$, "_reCount", -function (node) { -if (node == null) { -return; -}this._lycount++; -if ((node.left () != null) && (node.right () != null)) { -this._reCount (node.left ()); -this._reCount (node.right ()); -var l = node.left (); -var r = node.right (); -node.count = l.count + r.count; -node.ycount = (l.ycount + r.ycount) / 2; -} else { -node.count = 1; -node.ycount = this.ycount++; -}this._lycount--; -}, "jalview.datamodel.SequenceNode"); -Clazz.defineMethod (c$, "swapNodes", -function (node) { -if (node == null) { -return; -}var tmp = node.left (); -node.setLeft (node.right ()); -node.setRight (tmp); -}, "jalview.datamodel.SequenceNode"); -Clazz.defineMethod (c$, "changeDirection", -function (node, dir) { -if (node == null) { -return; -}if (node.parent () !== this.top) { -this.changeDirection (node.parent (), node); -var tmp = node.parent (); -if (dir === node.left ()) { -node.setParent (dir); -node.setLeft (tmp); -} else if (dir === node.right ()) { -node.setParent (dir); -node.setRight (tmp); -}} else { -if (dir === node.left ()) { -node.setParent (node.left ()); -if (this.top.left () === node) { -node.setRight (this.top.right ()); -} else { -node.setRight (this.top.left ()); -}} else { -node.setParent (node.right ()); -if (this.top.left () === node) { -node.setLeft (this.top.right ()); -} else { -node.setLeft (this.top.left ()); -}}}}, "jalview.datamodel.SequenceNode,jalview.datamodel.SequenceNode"); -Clazz.defineMethod (c$, "getMaxDist", -function () { -return this.maxdist; -}); -Clazz.defineMethod (c$, "getTopNode", -function () { -return this.top; -}); -Clazz.defineMethod (c$, "isHasDistances", -function () { -return this.hasDistances; -}); -Clazz.defineMethod (c$, "isHasBootstrap", -function () { -return this.hasBootstrap; -}); -Clazz.defineMethod (c$, "isHasRootDistance", -function () { -return this.hasRootDistance; -}); -Clazz.defineMethod (c$, "applyToNodes", -function (nodeTransformI) { -for (var nodes = this.node.elements (); nodes.hasMoreElements (); nodeTransformI.transform (nodes.nextElement ())) { -;} -}, "jalview.datamodel.NodeTransformI"); -c$.$NJTree$1$ = function () { -Clazz.pu$h (); -c$ = Clazz.declareAnonymous (jalview.analysis, "NJTree$1", null, jalview.datamodel.NodeTransformI); -Clazz.defineMethod (c$, "transform", -function (node) { -var el = node.element (); -if (el != null && Clazz.instanceOf (el, jalview.datamodel.SequenceI)) { -node.setName ((el).getName ()); -}}, "jalview.datamodel.BinaryNode"); -c$ = Clazz.p0p (); -}; -c$ = Clazz.decorateAsClass (function () { -this.value = null; -Clazz.instantialize (this, arguments); -}, jalview.analysis, "Cluster"); -Clazz.makeConstructor (c$, -function (value) { -this.value = value; -}, "~A"); -}); +Clazz.declarePackage ("jalview.analysis"); +Clazz.load (["java.util.Vector"], ["jalview.analysis.Cluster", "$.NJTree"], ["jalview.analysis.SequenceIdMatcher", "jalview.datamodel.AlignmentView", "$.CigarArray", "$.NodeTransformI", "$.SeqCigar", "$.Sequence", "$.SequenceI", "$.SequenceNode", "jalview.io.NewickFile", "jalview.schemes.ResidueProperties", "jalview.util.Format", "java.lang.StringBuffer"], function () { +c$ = Clazz.decorateAsClass (function () { +this.$cluster = null; +this.sequence = null; +this.seqData = null; +this.done = null; +this.noseqs = 0; +this.noClus = 0; +this.distance = null; +this.mini = 0; +this.minj = 0; +this.ri = 0; +this.rj = 0; +this.groups = null; +this.maxdist = null; +this.top = null; +this.maxDistValue = 0; +this.maxheight = 0; +this.ycount = 0; +this.node = null; +this.type = null; +this.pwtype = null; +this.found = null; +this.leaves = null; +this.hasDistances = true; +this.hasBootstrap = false; +this.hasRootDistance = true; +this._lycount = 0; +this._lylimit = 0; +Clazz.instantialize (this, arguments); +}, jalview.analysis, "NJTree"); +Clazz.prepareFields (c$, function () { +this.groups = new java.util.Vector (); +}); +Clazz.makeConstructor (c$, +function (seqs, odata, treefile) { +this.construct (seqs, treefile); +if (odata != null) { +this.seqData = odata; +}}, "~A,jalview.datamodel.AlignmentView,jalview.io.NewickFile"); +Clazz.makeConstructor (c$, +function (seqs, treefile) { +this.sequence = seqs; +this.top = treefile.getTree (); +this.hasDistances = treefile.HasDistances (); +this.hasBootstrap = treefile.HasBootstrap (); +this.hasRootDistance = treefile.HasRootDistance (); +this.maxheight = this.findHeight (this.top); +var algnIds = new jalview.analysis.SequenceIdMatcher (seqs); +var leaves = new java.util.Vector (); +this.findLeaves (this.top, leaves); +var i = 0; +var namesleft = seqs.length; +var j; +var nam; +var realnam; +var one2many = new java.util.Vector (); +var countOne2Many = 0; +while (i < leaves.size ()) { +j = leaves.elementAt (i++); +realnam = j.getName (); +nam = null; +if (namesleft > -1) { +nam = algnIds.findIdMatch (realnam); +}if (nam != null) { +j.setElement (nam); +if (one2many.contains (nam)) { +countOne2Many++; +} else { +one2many.addElement (nam); +namesleft--; +}} else { +j.setElement ( new jalview.datamodel.Sequence (realnam, "THISISAPLACEHLDER")); +j.setPlaceholder (true); +}} +}, "~A,jalview.io.NewickFile"); +Clazz.makeConstructor (c$, +function (sequence, seqData, type, pwtype, sm, start, end) { +this.sequence = sequence; +this.node = new java.util.Vector (); +this.type = type; +this.pwtype = pwtype; +if (seqData != null) { +this.seqData = seqData; +} else { +var seqs = new Array (sequence.length); +for (var i = 0; i < sequence.length; i++) { +seqs[i] = new jalview.datamodel.SeqCigar (sequence[i], start, end); +} +var sdata = new jalview.datamodel.CigarArray (seqs); +sdata.addOperation ('M', end - start + 1); +this.seqData = new jalview.datamodel.AlignmentView (sdata, start); +}if (!(type.equals ("NJ"))) { +type = "AV"; +}if (sm == null && !(pwtype.equals ("PID"))) { +if (jalview.schemes.ResidueProperties.getScoreMatrix (pwtype) == null) { +pwtype = "BLOSUM62"; +}}var i = 0; +this.done = Clazz.newIntArray (sequence.length, 0); +while ((i < sequence.length) && (sequence[i] != null)) { +this.done[i] = 0; +i++; +} +this.noseqs = i++; +this.distance = this.findDistances (sm); +this.makeLeaves (); +this.noClus = this.$cluster.size (); +this.cluster (); +}, "~A,jalview.datamodel.AlignmentView,~S,~S,jalview.api.analysis.ScoreModelI,~N,~N"); +Clazz.overrideMethod (c$, "toString", +function () { +var fout = new jalview.io.NewickFile (this.getTopNode ()); +return fout.print (this.isHasBootstrap (), this.isHasDistances (), this.isHasRootDistance ()); +}); +Clazz.defineMethod (c$, "UpdatePlaceHolders", +function (list) { +var leaves = new java.util.Vector (); +this.findLeaves (this.top, leaves); +var sz = leaves.size (); +var seqmatcher = null; +var i = 0; +while (i < sz) { +var leaf = leaves.elementAt (i++); +if (list.contains (leaf.element ())) { +leaf.setPlaceholder (false); +} else { +if (seqmatcher == null) { +var seqs = new Array (list.size ()); +for (var j = 0; j < seqs.length; j++) { +seqs[j] = list.get (j); +} +seqmatcher = new jalview.analysis.SequenceIdMatcher (seqs); +}var nam = seqmatcher.findIdMatch (leaf.getName ()); +if (nam != null) { +if (!leaf.isPlaceholder ()) { +}leaf.setPlaceholder (false); +leaf.setElement (nam); +} else { +if (!leaf.isPlaceholder ()) { +leaf.setElement ( new jalview.datamodel.Sequence (leaf.getName (), "THISISAPLACEHLDER")); +}leaf.setPlaceholder (true); +}}} +}, "java.util.List"); +Clazz.defineMethod (c$, "renameAssociatedNodes", +function () { +this.applyToNodes (((Clazz.isClassDefined ("jalview.analysis.NJTree$1") ? 0 : jalview.analysis.NJTree.$NJTree$1$ ()), Clazz.innerTypeInstance (jalview.analysis.NJTree$1, this, null))); +}); +Clazz.defineMethod (c$, "cluster", +function () { +while (this.noClus > 2) { +if (this.type.equals ("NJ")) { +this.findMinNJDistance (); +} else { +this.findMinDistance (); +}var c = this.joinClusters (this.mini, this.minj); +this.done[this.minj] = 1; +this.$cluster.setElementAt (null, this.minj); +this.$cluster.setElementAt (c, this.mini); +this.noClus--; +} +var onefound = false; +var one = -1; +var two = -1; +for (var i = 0; i < this.noseqs; i++) { +if (this.done[i] != 1) { +if (onefound == false) { +two = i; +onefound = true; +} else { +one = i; +}}} +this.joinClusters (one, two); +this.top = (this.node.elementAt (one)); +this.reCount (this.top); +this.findHeight (this.top); +this.findMaxDist (this.top); +}); +Clazz.defineMethod (c$, "joinClusters", +function (i, j) { +var dist = this.distance[i][j]; +var noi = (this.$cluster.elementAt (i)).value.length; +var noj = (this.$cluster.elementAt (j)).value.length; +var value = Clazz.newIntArray (noi + noj, 0); +for (var ii = 0; ii < noi; ii++) { +value[ii] = (this.$cluster.elementAt (i)).value[ii]; +} +for (var ii = noi; ii < (noi + noj); ii++) { +value[ii] = (this.$cluster.elementAt (j)).value[ii - noi]; +} +var c = new jalview.analysis.Cluster (value); +this.ri = this.findr (i, j); +this.rj = this.findr (j, i); +if (this.type.equals ("NJ")) { +this.findClusterNJDistance (i, j); +} else { +this.findClusterDistance (i, j); +}var sn = new jalview.datamodel.SequenceNode (); +sn.setLeft ((this.node.elementAt (i))); +sn.setRight ((this.node.elementAt (j))); +var tmpi = (this.node.elementAt (i)); +var tmpj = (this.node.elementAt (j)); +if (this.type.equals ("NJ")) { +this.findNewNJDistances (tmpi, tmpj, dist); +} else { +this.findNewDistances (tmpi, tmpj, dist); +}tmpi.setParent (sn); +tmpj.setParent (sn); +this.node.setElementAt (sn, i); +return c; +}, "~N,~N"); +Clazz.defineMethod (c$, "findNewNJDistances", +function (tmpi, tmpj, dist) { +tmpi.dist = ((dist + this.ri) - this.rj) / 2; +tmpj.dist = (dist - tmpi.dist); +if (tmpi.dist < 0) { +tmpi.dist = 0; +}if (tmpj.dist < 0) { +tmpj.dist = 0; +}}, "jalview.datamodel.SequenceNode,jalview.datamodel.SequenceNode,~N"); +Clazz.defineMethod (c$, "findNewDistances", +function (tmpi, tmpj, dist) { +var ih = 0; +var jh = 0; +var sni = tmpi; +var snj = tmpj; +while (sni != null) { +ih = ih + sni.dist; +sni = sni.left (); +} +while (snj != null) { +jh = jh + snj.dist; +snj = snj.left (); +} +tmpi.dist = ((dist / 2) - ih); +tmpj.dist = ((dist / 2) - jh); +}, "jalview.datamodel.SequenceNode,jalview.datamodel.SequenceNode,~N"); +Clazz.defineMethod (c$, "findClusterDistance", +function (i, j) { +var noi = (this.$cluster.elementAt (i)).value.length; +var noj = (this.$cluster.elementAt (j)).value.length; +var newdist = Clazz.newFloatArray (this.noseqs, 0); +for (var l = 0; l < this.noseqs; l++) { +if ((l != i) && (l != j)) { +newdist[l] = ((this.distance[i][l] * noi) + (this.distance[j][l] * noj)) / (noi + noj); +} else { +newdist[l] = 0; +}} +for (var ii = 0; ii < this.noseqs; ii++) { +this.distance[i][ii] = newdist[ii]; +this.distance[ii][i] = newdist[ii]; +} +}, "~N,~N"); +Clazz.defineMethod (c$, "findClusterNJDistance", +function (i, j) { +var newdist = Clazz.newFloatArray (this.noseqs, 0); +for (var l = 0; l < this.noseqs; l++) { +if ((l != i) && (l != j)) { +newdist[l] = ((this.distance[i][l] + this.distance[j][l]) - this.distance[i][j]) / 2; +} else { +newdist[l] = 0; +}} +for (var ii = 0; ii < this.noseqs; ii++) { +this.distance[i][ii] = newdist[ii]; +this.distance[ii][i] = newdist[ii]; +} +}, "~N,~N"); +Clazz.defineMethod (c$, "findr", +function (i, j) { +var tmp = 1; +for (var k = 0; k < this.noseqs; k++) { +if ((k != i) && (k != j) && (this.done[k] != 1)) { +tmp = tmp + this.distance[i][k]; +}} +if (this.noClus > 2) { +tmp = tmp / (this.noClus - 2); +}return tmp; +}, "~N,~N"); +Clazz.defineMethod (c$, "findMinNJDistance", +function () { +var min = 100000; +for (var i = 0; i < (this.noseqs - 1); i++) { +for (var j = i + 1; j < this.noseqs; j++) { +if ((this.done[i] != 1) && (this.done[j] != 1)) { +var tmp = this.distance[i][j] - (this.findr (i, j) + this.findr (j, i)); +if (tmp < min) { +this.mini = i; +this.minj = j; +min = tmp; +}}} +} +return min; +}); +Clazz.defineMethod (c$, "findMinDistance", +function () { +var min = 100000; +for (var i = 0; i < (this.noseqs - 1); i++) { +for (var j = i + 1; j < this.noseqs; j++) { +if ((this.done[i] != 1) && (this.done[j] != 1)) { +if (this.distance[i][j] < min) { +this.mini = i; +this.minj = j; +min = this.distance[i][j]; +}}} +} +return min; +}); +Clazz.defineMethod (c$, "findDistances", +function (_pwmatrix) { +var distance = Clazz.newFloatArray (this.noseqs, this.noseqs, 0); +if (_pwmatrix == null) { +_pwmatrix = jalview.schemes.ResidueProperties.getScoreModel (this.pwtype); +if (_pwmatrix == null) { +_pwmatrix = jalview.schemes.ResidueProperties.getScoreMatrix ("BLOSUM62"); +}}distance = _pwmatrix.findDistances (this.seqData); +return distance; +}, "jalview.api.analysis.ScoreModelI"); +Clazz.defineMethod (c$, "makeLeaves", +function () { +this.$cluster = new java.util.Vector (); +for (var i = 0; i < this.noseqs; i++) { +var sn = new jalview.datamodel.SequenceNode (); +sn.setElement (this.sequence[i]); +sn.setName (this.sequence[i].getName ()); +this.node.addElement (sn); +var value = Clazz.newIntArray (1, 0); +value[0] = i; +var c = new jalview.analysis.Cluster (value); +this.$cluster.addElement (c); +} +}); +Clazz.defineMethod (c$, "findLeaves", +function (node, leaves) { +if (node == null) { +return leaves; +}if ((node.left () == null) && (node.right () == null)) { +leaves.addElement (node); +return leaves; +} else { +this.findLeaves (node.left (), leaves); +this.findLeaves (node.right (), leaves); +}return leaves; +}, "jalview.datamodel.SequenceNode,java.util.Vector"); +Clazz.defineMethod (c$, "findLeaf", +function (node, count) { +this.found = this._findLeaf (node, count); +return this.found; +}, "jalview.datamodel.SequenceNode,~N"); +Clazz.defineMethod (c$, "_findLeaf", +function (node, count) { +if (node == null) { +return null; +}if (node.ycount == count) { +this.found = node.element (); +return this.found; +} else { +this._findLeaf (node.left (), count); +this._findLeaf (node.right (), count); +}return this.found; +}, "jalview.datamodel.SequenceNode,~N"); +Clazz.defineMethod (c$, "printNode", +function (node) { +if (node == null) { +return; +}if ((node.left () == null) && (node.right () == null)) { +System.out.println ("Leaf = " + (node.element ()).getName ()); +System.out.println ("Dist " + node.dist); +System.out.println ("Boot " + node.getBootstrap ()); +} else { +System.out.println ("Dist " + node.dist); +this.printNode (node.left ()); +this.printNode (node.right ()); +}}, "jalview.datamodel.SequenceNode"); +Clazz.defineMethod (c$, "findMaxDist", +function (node) { +if (node == null) { +return; +}if ((node.left () == null) && (node.right () == null)) { +var dist = node.dist; +if (dist > this.maxDistValue) { +this.maxdist = node; +this.maxDistValue = dist; +}} else { +this.findMaxDist (node.left ()); +this.findMaxDist (node.right ()); +}}, "jalview.datamodel.SequenceNode"); +Clazz.defineMethod (c$, "getGroups", +function () { +return this.groups; +}); +Clazz.defineMethod (c$, "getMaxHeight", +function () { +return this.maxheight; +}); +Clazz.defineMethod (c$, "groupNodes", +function (node, threshold) { +if (node == null) { +return; +}if ((node.height / this.maxheight) > threshold) { +this.groups.addElement (node); +} else { +this.groupNodes (node.left (), threshold); +this.groupNodes (node.right (), threshold); +}}, "jalview.datamodel.SequenceNode,~N"); +Clazz.defineMethod (c$, "findHeight", +function (node) { +if (node == null) { +return this.maxheight; +}if ((node.left () == null) && (node.right () == null)) { +node.height = (node.parent ()).height + node.dist; +if (node.height > this.maxheight) { +return node.height; +} else { +return this.maxheight; +}} else { +if (node.parent () != null) { +node.height = (node.parent ()).height + node.dist; +} else { +this.maxheight = 0; +node.height = 0.0; +}this.maxheight = this.findHeight ((node.left ())); +this.maxheight = this.findHeight ((node.right ())); +}return this.maxheight; +}, "jalview.datamodel.SequenceNode"); +Clazz.defineMethod (c$, "reRoot", +function () { +if (this.maxdist != null) { +this.ycount = 0; +var tmpdist = this.maxdist.dist; +var sn = new jalview.datamodel.SequenceNode (); +sn.setParent (null); +var snr = this.maxdist.parent (); +this.changeDirection (snr, this.maxdist); +System.out.println ("Printing reversed tree"); +this.printN (snr); +snr.dist = tmpdist / 2; +this.maxdist.dist = tmpdist / 2; +snr.setParent (sn); +this.maxdist.setParent (sn); +sn.setRight (snr); +sn.setLeft (this.maxdist); +this.top = sn; +this.ycount = 0; +this.reCount (this.top); +this.findHeight (this.top); +}return this.top; +}); +Clazz.defineMethod (c$, "hasOriginalSequenceData", +function () { +return this.seqData != null; +}); +Clazz.defineMethod (c$, "printOriginalSequenceData", +function (gapChar) { +if (this.seqData == null) { +return null; +}var sb = new StringBuffer (); +var seqdatas = this.seqData.getSequenceStrings (gapChar); +for (var i = 0; i < seqdatas.length; i++) { +sb.append ( new jalview.util.Format ("%-15s").form (this.sequence[i].getName ())); +sb.append (" " + seqdatas[i] + "\n"); +} +return sb.toString (); +}, "~S"); +Clazz.defineMethod (c$, "printN", +function (node) { +if (node == null) { +return; +}if ((node.left () != null) && (node.right () != null)) { +this.printN (node.left ()); +this.printN (node.right ()); +} else { +System.out.println (" name = " + (node.element ()).getName ()); +}System.out.println (" dist = " + node.dist + " " + node.count + " " + node.height); +}, "jalview.datamodel.SequenceNode"); +Clazz.defineMethod (c$, "reCount", +function (node) { +this.ycount = 0; +this._lycount = 0; +this._reCount (node); +}, "jalview.datamodel.SequenceNode"); +Clazz.defineMethod (c$, "_reCount", +function (node) { +if (node == null) { +return; +}this._lycount++; +if ((node.left () != null) && (node.right () != null)) { +this._reCount (node.left ()); +this._reCount (node.right ()); +var l = node.left (); +var r = node.right (); +node.count = l.count + r.count; +node.ycount = (l.ycount + r.ycount) / 2; +} else { +node.count = 1; +node.ycount = this.ycount++; +}this._lycount--; +}, "jalview.datamodel.SequenceNode"); +Clazz.defineMethod (c$, "swapNodes", +function (node) { +if (node == null) { +return; +}var tmp = node.left (); +node.setLeft (node.right ()); +node.setRight (tmp); +}, "jalview.datamodel.SequenceNode"); +Clazz.defineMethod (c$, "changeDirection", +function (node, dir) { +if (node == null) { +return; +}if (node.parent () !== this.top) { +this.changeDirection (node.parent (), node); +var tmp = node.parent (); +if (dir === node.left ()) { +node.setParent (dir); +node.setLeft (tmp); +} else if (dir === node.right ()) { +node.setParent (dir); +node.setRight (tmp); +}} else { +if (dir === node.left ()) { +node.setParent (node.left ()); +if (this.top.left () === node) { +node.setRight (this.top.right ()); +} else { +node.setRight (this.top.left ()); +}} else { +node.setParent (node.right ()); +if (this.top.left () === node) { +node.setLeft (this.top.right ()); +} else { +node.setLeft (this.top.left ()); +}}}}, "jalview.datamodel.SequenceNode,jalview.datamodel.SequenceNode"); +Clazz.defineMethod (c$, "getMaxDist", +function () { +return this.maxdist; +}); +Clazz.defineMethod (c$, "getTopNode", +function () { +return this.top; +}); +Clazz.defineMethod (c$, "isHasDistances", +function () { +return this.hasDistances; +}); +Clazz.defineMethod (c$, "isHasBootstrap", +function () { +return this.hasBootstrap; +}); +Clazz.defineMethod (c$, "isHasRootDistance", +function () { +return this.hasRootDistance; +}); +Clazz.defineMethod (c$, "applyToNodes", +function (nodeTransformI) { +for (var nodes = this.node.elements (); nodes.hasMoreElements (); nodeTransformI.transform (nodes.nextElement ())) { +;} +}, "jalview.datamodel.NodeTransformI"); +c$.$NJTree$1$ = function () { +Clazz.pu$h (); +c$ = Clazz.declareAnonymous (jalview.analysis, "NJTree$1", null, jalview.datamodel.NodeTransformI); +Clazz.defineMethod (c$, "transform", +function (node) { +var el = node.element (); +if (el != null && Clazz.instanceOf (el, jalview.datamodel.SequenceI)) { +node.setName ((el).getName ()); +}}, "jalview.datamodel.BinaryNode"); +c$ = Clazz.p0p (); +}; +c$ = Clazz.decorateAsClass (function () { +this.value = null; +Clazz.instantialize (this, arguments); +}, jalview.analysis, "Cluster"); +Clazz.makeConstructor (c$, +function (value) { +this.value = value; +}, "~A"); +});