X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=site%2Fj2s%2Fjalview%2Fio%2FNewickFile.js;h=04ba3ff6511ca2cf4641e2d07b21ad92bc23d6fe;hp=71904aad758f1eb363e1f0a7ad60232041fdc9d4;hb=b9b7a352eee79b7764c3b09c9d19663075061d8c;hpb=7301a2415adab88038b291fc54caeeb3a5a47a44 diff --git a/site/j2s/jalview/io/NewickFile.js b/site/j2s/jalview/io/NewickFile.js index 71904aa..04ba3ff 100644 --- a/site/j2s/jalview/io/NewickFile.js +++ b/site/j2s/jalview/io/NewickFile.js @@ -1,408 +1,408 @@ -Clazz.declarePackage ("jalview.io"); -Clazz.load (["jalview.io.FileParse", "jalview.jsdev.RegExp"], "jalview.io.NewickFile", ["jalview.datamodel.SequenceNode", "jalview.util.MessageManager", "java.io.BufferedReader", "$.IOException", "java.lang.Float", "$.StringBuffer", "java.util.StringTokenizer"], function () { -c$ = Clazz.decorateAsClass (function () { -this.root = null; -this.$HasBootstrap = false; -this.$HasDistances = false; -this.RootHasDistance = false; -this.ReplaceUnderscores = false; -this.printRootInfo = true; -this.NodeSafeName = null; -this.QuoteChar = '\''; -Clazz.instantialize (this, arguments); -}, jalview.io, "NewickFile", jalview.io.FileParse); -Clazz.prepareFields (c$, function () { -this.NodeSafeName = Clazz.newArray (-1, [jalview.jsdev.RegExp.perlCode ("m/[\\[,:'()]/"), jalview.jsdev.RegExp.perlCode ("s/'/''/"), jalview.jsdev.RegExp.perlCode ("s/\\/w/_/")]); -}); -Clazz.makeConstructor (c$, -function (inStr) { -Clazz.superConstructor (this, jalview.io.NewickFile, [inStr, "Paste"]); -}, "~S"); -Clazz.makeConstructor (c$, -function (newtree) { -Clazz.superConstructor (this, jalview.io.NewickFile, []); -this.root = newtree; -}, "jalview.datamodel.SequenceNode"); -Clazz.makeConstructor (c$, -function (newtree, bootstrap) { -Clazz.superConstructor (this, jalview.io.NewickFile, []); -this.$HasBootstrap = bootstrap; -this.root = newtree; -}, "jalview.datamodel.SequenceNode,~B"); -Clazz.makeConstructor (c$, -function (newtree, bootstrap, distances) { -Clazz.superConstructor (this, jalview.io.NewickFile, []); -this.root = newtree; -this.$HasBootstrap = bootstrap; -this.$HasDistances = distances; -}, "jalview.datamodel.SequenceNode,~B,~B"); -Clazz.makeConstructor (c$, -function (newtree, bootstrap, distances, rootdistance) { -Clazz.superConstructor (this, jalview.io.NewickFile, []); -this.root = newtree; -this.$HasBootstrap = bootstrap; -this.$HasDistances = distances; -this.RootHasDistance = rootdistance; -}, "jalview.datamodel.SequenceNode,~B,~B,~B"); -Clazz.defineMethod (c$, "ErrorStringrange", - function (Error, Er, r, p, s) { -return ((Error == null) ? "" : Error) + Er + " at position " + p + " ( " + s.substring (((p - r) < 0) ? 0 : (p - r), ((p + r) > s.length) ? s.length : (p + r)) + " )\n"; -}, "~S,~S,~N,~N,~S"); -Clazz.defineMethod (c$, "HasBootstrap", -function () { -return this.$HasBootstrap; -}); -Clazz.defineMethod (c$, "HasDistances", -function () { -return this.$HasDistances; -}); -Clazz.defineMethod (c$, "HasRootDistance", -function () { -return this.RootHasDistance; -}); -Clazz.defineMethod (c$, "parse", -function () { -var nf; -{ -var file = new StringBuffer (); -while ((nf = this.nextLine ()) != null) { -file.append (nf); -} -nf = file.toString (); -}this.root = new jalview.datamodel.SequenceNode (); -var realroot = null; -var c = this.root; -var d = -1; -var cp = 0; -var Error = null; -var nodename = null; -var commentString2 = null; -var DefDistance = 0.001; -var DefBootstrap = -1; -var distance = DefDistance; -var bootstrap = DefBootstrap; -var ascending = false; -var majorsyms = jalview.jsdev.RegExp.newRegex (["[(\\['),;]"]); -var nextcp = 0; -var ncp = cp; -var parsednodename = false; -while (majorsyms.searchFrom (nf, cp) && (Error == null)) { -var fcp = majorsyms.matchedFrom (); -var schar; -switch (schar = nf.charAt (fcp)) { -case '(': -if (ascending) { -Error = this.ErrorStringrange (Error, "Unexpected '('", 7, fcp, nf); -continue; -};d++; -if (c.right () == null) { -c.setRight ( new jalview.datamodel.SequenceNode (null, c, null, DefDistance, DefBootstrap, false)); -c = c.right (); -} else { -if (c.left () != null) { -var tmpn = new jalview.datamodel.SequenceNode (null, c, null, 0, 0, true); -tmpn.SetChildren (c.left (), c.right ()); -c.setRight (tmpn); -}c.setLeft ( new jalview.datamodel.SequenceNode (null, c, null, DefDistance, DefBootstrap, false)); -c = c.left (); -}if (realroot == null) { -realroot = c; -}nodename = null; -distance = DefDistance; -bootstrap = DefBootstrap; -cp = fcp + 1; -break; -case '\'': -var qnodename = jalview.jsdev.RegExp.newRegex (["'([^']|'')+'"]); -if (qnodename.searchFrom (nf, fcp)) { -var nl = qnodename.stringMatched ().length; -nodename = String.instantialize (qnodename.stringMatched ().substring (1, nl - 1)); -var xpandquotes = jalview.jsdev.RegExp.perlCode ("s/''/'/"); -var widernodename = xpandquotes.replaceAll (nodename); -nodename = widernodename; -nextcp = fcp + nl + 1; -parsednodename = true; -} else { -Error = this.ErrorStringrange (Error, "Unterminated quotes for nodename", 7, fcp, nf); -}break; -default: -if (schar == ';') { -if (d != -1) { -Error = this.ErrorStringrange (Error, "Wayward semicolon (depth=" + d + ")", 7, fcp, nf); -}}if (schar == '[') { -var comment = jalview.jsdev.RegExp.newRegex (["]"]); -if (comment.searchFrom (nf, fcp)) { -nextcp = comment.matchedFrom () + 1; -this.warningMessage = "Tree file contained comments which may confuse input algorithm."; -break; -} else { -Error = this.ErrorStringrange (Error, "Unterminated comment", 3, fcp, nf); -};}var fstring = nf.substring (ncp, fcp); -while (fstring.indexOf (']') > -1) { -var cstart = fstring.indexOf ('['); -var cend = fstring.indexOf (']'); -commentString2 = fstring.substring (cstart + 1, cend); -fstring = fstring.substring (0, cstart) + fstring.substring (cend + 1); -} -var uqnodename = jalview.jsdev.RegExp.newRegex (["\\b([^' :;\\](),]+)"]); -var nbootstrap = jalview.jsdev.RegExp.newRegex (["\\s*([0-9+]+)\\s*:"]); -var ndist = jalview.jsdev.RegExp.newRegex ([":([-0-9Ee.+]+)"]); -if (!parsednodename && uqnodename.search (fstring) && ((uqnodename.matchedFromI (1) == 0) || (fstring.charAt (uqnodename.matchedFromI (1) - 1) != ':'))) { -if (nodename == null) { -if (this.ReplaceUnderscores) { -nodename = uqnodename.stringMatchedI (1).$replace ('_', ' '); -} else { -nodename = uqnodename.stringMatchedI (1); -}} else { -Error = this.ErrorStringrange (Error, "File has broken algorithm - overwritten nodename", 10, fcp, nf); -}}if (nbootstrap.search (fstring)) { -if (nbootstrap.stringMatchedI (1).equals (uqnodename.stringMatchedI (1))) { -nodename = null; -}if (nodename == null || nodename.length == 0 || nbootstrap.matchedFromI (1) > (uqnodename.matchedFromI (1) + uqnodename.stringMatched ().length)) { -try { -bootstrap = ( new Integer (nbootstrap.stringMatchedI (1))).intValue (); -this.$HasBootstrap = true; -} catch (e) { -if (Clazz.exceptionOf (e, Exception)) { -Error = this.ErrorStringrange (Error, "Can't parse bootstrap value", 4, ncp + nbootstrap.matchedFrom (), nf); -} else { -throw e; -} -} -}}var nodehasdistance = false; -if (ndist.search (fstring)) { -try { -distance = ( new Float (ndist.stringMatchedI (1))).floatValue (); -this.$HasDistances = true; -nodehasdistance = true; -} catch (e) { -if (Clazz.exceptionOf (e, Exception)) { -Error = this.ErrorStringrange (Error, "Can't parse node distance value", 7, ncp + ndist.matchedFrom (), nf); -} else { -throw e; -} -} -}if (ascending) { -c.setName (nodename); -c.dist = (this.$HasDistances) ? distance : DefDistance; -c.setBootstrap ((this.$HasBootstrap) ? bootstrap : DefBootstrap); -if (c === realroot) { -this.RootHasDistance = nodehasdistance; -}this.parseNHXNodeProps (c, commentString2); -commentString2 = null; -} else { -var newnode = new jalview.datamodel.SequenceNode (null, c, nodename, (this.$HasDistances) ? distance : DefDistance, (this.$HasBootstrap) ? bootstrap : DefBootstrap, false); -this.parseNHXNodeProps (c, commentString2); -commentString2 = null; -if (c.right () == null) { -c.setRight (newnode); -} else { -if (c.left () == null) { -c.setLeft (newnode); -} else { -var newdummy = new jalview.datamodel.SequenceNode (null, c, null, (this.$HasDistances ? 0 : DefDistance), 0, true); -newdummy.SetChildren (c.left (), newnode); -c.setLeft (newdummy); -}}}if (ascending) { -c = c.AscendTree (); -if ((d > -1) && (c == null)) { -Error = this.ErrorStringrange (Error, "File broke algorithm: Lost place in tree (is there an extra ')' ?)", 7, fcp, nf); -}}if (nf.charAt (fcp) == ')') { -d--; -ascending = true; -} else { -if (nf.charAt (fcp) == ',') { -if (ascending) { -ascending = false; -} else { -if ((c.left () != null) && (!c.left ().isLeaf ())) { -c = c.left (); -}}}}nodename = null; -distance = DefDistance; -bootstrap = DefBootstrap; -commentString2 = null; -parsednodename = false; -} -if (nextcp == 0) { -ncp = cp = fcp + 1; -} else { -cp = nextcp; -nextcp = 0; -}} -if (Error != null) { -throw ( new java.io.IOException (jalview.util.MessageManager.formatMessage ("exception.newfile", Clazz.newArray (-1, [Error.toString ()])))); -}if (this.root == null) { -throw ( new java.io.IOException (jalview.util.MessageManager.formatMessage ("exception.newfile", Clazz.newArray (-1, [jalview.util.MessageManager.getString ("label.no_tree_read_in")])))); -}this.root = this.root.right ().detach (); -if (!this.RootHasDistance) { -this.root.dist = (this.$HasDistances) ? 0 : DefDistance; -}}); -Clazz.defineMethod (c$, "parseNHXNodeProps", - function (c, commentString) { -if (commentString != null && commentString.startsWith ("&&NHX")) { -var st = new java.util.StringTokenizer (commentString.substring (5), ":"); -while (st.hasMoreTokens ()) { -var tok = st.nextToken (); -var colpos = tok.indexOf ("="); -if (colpos > -1) { -var code = tok.substring (0, colpos); -var value = tok.substring (colpos + 1); -try { -if (code.toLowerCase ().equals ("b")) { -var v = -1; -var iv = new Float (value); -v = iv.intValue (); -c.setBootstrap (v); -this.$HasBootstrap = true; -}} catch (e) { -if (Clazz.exceptionOf (e, Exception)) { -System.err.println ("Couldn't parse code '" + code + "' = '" + value + "'"); -e.printStackTrace (System.err); -} else { -throw e; -} -} -}} -}}, "jalview.datamodel.SequenceNode,~S"); -Clazz.defineMethod (c$, "getTree", -function () { -return this.root; -}); -Clazz.defineMethod (c$, "print", -function () { -{ -var tf = new StringBuffer (); -this.print (tf, this.root); -return (tf.append (";").toString ()); -}}); -Clazz.defineMethod (c$, "print", -function (withbootstraps) { -{ -var boots = this.$HasBootstrap; -this.$HasBootstrap = withbootstraps; -var rv = this.print (); -this.$HasBootstrap = boots; -return rv; -}}, "~B"); -Clazz.defineMethod (c$, "print", -function (withbootstraps, withdists) { -{ -var dists = this.$HasDistances; -this.$HasDistances = withdists; -var rv = this.print (withbootstraps); -this.$HasDistances = dists; -return rv; -}}, "~B,~B"); -Clazz.defineMethod (c$, "print", -function (withbootstraps, withdists, printRootInfo) { -{ -var rootinfo = printRootInfo; -this.printRootInfo = printRootInfo; -var rv = this.print (withbootstraps, withdists); -this.printRootInfo = rootinfo; -return rv; -}}, "~B,~B,~B"); -Clazz.defineMethod (c$, "getQuoteChar", -function () { -return this.QuoteChar; -}); -Clazz.defineMethod (c$, "setQuoteChar", -function (c) { -var old = this.QuoteChar; -this.QuoteChar = c; -return old; -}, "~S"); -Clazz.defineMethod (c$, "nodeName", - function (name) { -if (this.NodeSafeName[0].search (name)) { -return this.QuoteChar + this.NodeSafeName[1].replaceAll (name) + this.QuoteChar; -} else { -return this.NodeSafeName[2].replaceAll (name); -}}, "~S"); -Clazz.defineMethod (c$, "printNodeField", - function (c) { -return ((c.getName () == null) ? "" : this.nodeName (c.getName ())) + ((this.$HasBootstrap) ? ((c.getBootstrap () > -1) ? ((c.getName () != null ? " " : "") + c.getBootstrap ()) : "") : "") + ((this.$HasDistances) ? (":" + c.dist) : ""); -}, "jalview.datamodel.SequenceNode"); -Clazz.defineMethod (c$, "printRootField", - function (root) { -return (this.printRootInfo) ? (((root.getName () == null) ? "" : this.nodeName (root.getName ())) + ((this.$HasBootstrap) ? ((root.getBootstrap () > -1) ? ((root.getName () != null ? " " : "") + +root.getBootstrap ()) : "") : "") + ((this.RootHasDistance) ? (":" + root.dist) : "")) : ""; -}, "jalview.datamodel.SequenceNode"); -Clazz.defineMethod (c$, "print", -function (tf, root) { -if (root != null) { -if (root.isLeaf () && this.printRootInfo) { -tf.append (this.printRootField (root)); -} else { -if (root.isDummy ()) { -this._print (tf, root.right ()); -this._print (tf, root.left ()); -} else { -tf.append ("("); -this._print (tf, root.right ()); -if (root.left () != null) { -tf.append (","); -}this._print (tf, root.left ()); -tf.append (")" + this.printRootField (root)); -}}}}, "StringBuffer,jalview.datamodel.SequenceNode"); -Clazz.defineMethod (c$, "_print", -function (tf, c) { -if (c != null) { -if (c.isLeaf ()) { -tf.append (this.printNodeField (c)); -} else { -if (c.isDummy ()) { -this._print (tf, c.left ()); -if (c.left () != null) { -tf.append (","); -}this._print (tf, c.right ()); -} else { -tf.append ("("); -this._print (tf, c.right ()); -if (c.left () != null) { -tf.append (","); -}this._print (tf, c.left ()); -tf.append (")" + this.printNodeField (c)); -}}}}, "StringBuffer,jalview.datamodel.SequenceNode"); -c$.main = Clazz.defineMethod (c$, "main", -function (args) { -try { -if (args == null || args.length != 1) { -System.err.println ("Takes one argument - file name of a newick tree file."); -System.exit (0); -}var fn = new java.io.File (args[0]); -var newickfile = new StringBuffer (); -var treefile = new java.io.BufferedReader ( new java.io.FileReader (fn)); -var l; -while ((l = treefile.readLine ()) != null) { -newickfile.append (l); -} -treefile.close (); -System.out.println ("Read file :\n"); -var trf = new jalview.io.NewickFile (args[0], "File"); -trf.parse (); -System.out.println ("Original file :\n"); -var nonl = jalview.jsdev.RegExp.newRegex (["\n+", ""]); -System.out.println (nonl.replaceAll (newickfile.toString ()) + "\n"); -System.out.println ("Parsed file.\n"); -System.out.println ("Default output type for original input.\n"); -System.out.println (trf.print ()); -System.out.println ("Without bootstraps.\n"); -System.out.println (trf.print (false)); -System.out.println ("Without distances.\n"); -System.out.println (trf.print (true, false)); -System.out.println ("Without bootstraps but with distanecs.\n"); -System.out.println (trf.print (false, true)); -System.out.println ("Without bootstraps or distanecs.\n"); -System.out.println (trf.print (false, false)); -System.out.println ("With bootstraps and with distances.\n"); -System.out.println (trf.print (true, true)); -} catch (e) { -if (Clazz.exceptionOf (e, java.io.IOException)) { -System.err.println ("Exception\n" + e); -e.printStackTrace (); -} else { -throw e; -} -} -}, "~A"); -}); +Clazz.declarePackage ("jalview.io"); +Clazz.load (["jalview.io.FileParse", "jalview.jsdev.RegExp"], "jalview.io.NewickFile", ["jalview.datamodel.SequenceNode", "jalview.util.MessageManager", "java.io.BufferedReader", "$.IOException", "java.lang.Float", "$.StringBuffer", "java.util.StringTokenizer"], function () { +c$ = Clazz.decorateAsClass (function () { +this.root = null; +this.$HasBootstrap = false; +this.$HasDistances = false; +this.RootHasDistance = false; +this.ReplaceUnderscores = false; +this.printRootInfo = true; +this.NodeSafeName = null; +this.QuoteChar = '\''; +Clazz.instantialize (this, arguments); +}, jalview.io, "NewickFile", jalview.io.FileParse); +Clazz.prepareFields (c$, function () { +this.NodeSafeName = Clazz.newArray (-1, [jalview.jsdev.RegExp.perlCode ("m/[\\[,:'()]/"), jalview.jsdev.RegExp.perlCode ("s/'/''/"), jalview.jsdev.RegExp.perlCode ("s/\\/w/_/")]); +}); +Clazz.makeConstructor (c$, +function (inStr) { +Clazz.superConstructor (this, jalview.io.NewickFile, [inStr, "Paste"]); +}, "~S"); +Clazz.makeConstructor (c$, +function (newtree) { +Clazz.superConstructor (this, jalview.io.NewickFile, []); +this.root = newtree; +}, "jalview.datamodel.SequenceNode"); +Clazz.makeConstructor (c$, +function (newtree, bootstrap) { +Clazz.superConstructor (this, jalview.io.NewickFile, []); +this.$HasBootstrap = bootstrap; +this.root = newtree; +}, "jalview.datamodel.SequenceNode,~B"); +Clazz.makeConstructor (c$, +function (newtree, bootstrap, distances) { +Clazz.superConstructor (this, jalview.io.NewickFile, []); +this.root = newtree; +this.$HasBootstrap = bootstrap; +this.$HasDistances = distances; +}, "jalview.datamodel.SequenceNode,~B,~B"); +Clazz.makeConstructor (c$, +function (newtree, bootstrap, distances, rootdistance) { +Clazz.superConstructor (this, jalview.io.NewickFile, []); +this.root = newtree; +this.$HasBootstrap = bootstrap; +this.$HasDistances = distances; +this.RootHasDistance = rootdistance; +}, "jalview.datamodel.SequenceNode,~B,~B,~B"); +Clazz.defineMethod (c$, "ErrorStringrange", + function (Error, Er, r, p, s) { +return ((Error == null) ? "" : Error) + Er + " at position " + p + " ( " + s.substring (((p - r) < 0) ? 0 : (p - r), ((p + r) > s.length) ? s.length : (p + r)) + " )\n"; +}, "~S,~S,~N,~N,~S"); +Clazz.defineMethod (c$, "HasBootstrap", +function () { +return this.$HasBootstrap; +}); +Clazz.defineMethod (c$, "HasDistances", +function () { +return this.$HasDistances; +}); +Clazz.defineMethod (c$, "HasRootDistance", +function () { +return this.RootHasDistance; +}); +Clazz.defineMethod (c$, "parse", +function () { +var nf; +{ +var file = new StringBuffer (); +while ((nf = this.nextLine ()) != null) { +file.append (nf); +} +nf = file.toString (); +}this.root = new jalview.datamodel.SequenceNode (); +var realroot = null; +var c = this.root; +var d = -1; +var cp = 0; +var Error = null; +var nodename = null; +var commentString2 = null; +var DefDistance = 0.001; +var DefBootstrap = -1; +var distance = DefDistance; +var bootstrap = DefBootstrap; +var ascending = false; +var majorsyms = jalview.jsdev.RegExp.newRegex (["[(\\['),;]"]); +var nextcp = 0; +var ncp = cp; +var parsednodename = false; +while (majorsyms.searchFrom (nf, cp) && (Error == null)) { +var fcp = majorsyms.matchedFrom (); +var schar; +switch (schar = nf.charAt (fcp)) { +case '(': +if (ascending) { +Error = this.ErrorStringrange (Error, "Unexpected '('", 7, fcp, nf); +continue; +};d++; +if (c.right () == null) { +c.setRight ( new jalview.datamodel.SequenceNode (null, c, null, DefDistance, DefBootstrap, false)); +c = c.right (); +} else { +if (c.left () != null) { +var tmpn = new jalview.datamodel.SequenceNode (null, c, null, 0, 0, true); +tmpn.SetChildren (c.left (), c.right ()); +c.setRight (tmpn); +}c.setLeft ( new jalview.datamodel.SequenceNode (null, c, null, DefDistance, DefBootstrap, false)); +c = c.left (); +}if (realroot == null) { +realroot = c; +}nodename = null; +distance = DefDistance; +bootstrap = DefBootstrap; +cp = fcp + 1; +break; +case '\'': +var qnodename = jalview.jsdev.RegExp.newRegex (["'([^']|'')+'"]); +if (qnodename.searchFrom (nf, fcp)) { +var nl = qnodename.stringMatched ().length; +nodename = String.instantialize (qnodename.stringMatched ().substring (1, nl - 1)); +var xpandquotes = jalview.jsdev.RegExp.perlCode ("s/''/'/"); +var widernodename = xpandquotes.replaceAll (nodename); +nodename = widernodename; +nextcp = fcp + nl + 1; +parsednodename = true; +} else { +Error = this.ErrorStringrange (Error, "Unterminated quotes for nodename", 7, fcp, nf); +}break; +default: +if (schar == ';') { +if (d != -1) { +Error = this.ErrorStringrange (Error, "Wayward semicolon (depth=" + d + ")", 7, fcp, nf); +}}if (schar == '[') { +var comment = jalview.jsdev.RegExp.newRegex (["]"]); +if (comment.searchFrom (nf, fcp)) { +nextcp = comment.matchedFrom () + 1; +this.warningMessage = "Tree file contained comments which may confuse input algorithm."; +break; +} else { +Error = this.ErrorStringrange (Error, "Unterminated comment", 3, fcp, nf); +};}var fstring = nf.substring (ncp, fcp); +while (fstring.indexOf (']') > -1) { +var cstart = fstring.indexOf ('['); +var cend = fstring.indexOf (']'); +commentString2 = fstring.substring (cstart + 1, cend); +fstring = fstring.substring (0, cstart) + fstring.substring (cend + 1); +} +var uqnodename = jalview.jsdev.RegExp.newRegex (["\\b([^' :;\\](),]+)"]); +var nbootstrap = jalview.jsdev.RegExp.newRegex (["\\s*([0-9+]+)\\s*:"]); +var ndist = jalview.jsdev.RegExp.newRegex ([":([-0-9Ee.+]+)"]); +if (!parsednodename && uqnodename.search (fstring) && ((uqnodename.matchedFromI (1) == 0) || (fstring.charAt (uqnodename.matchedFromI (1) - 1) != ':'))) { +if (nodename == null) { +if (this.ReplaceUnderscores) { +nodename = uqnodename.stringMatchedI (1).$replace ('_', ' '); +} else { +nodename = uqnodename.stringMatchedI (1); +}} else { +Error = this.ErrorStringrange (Error, "File has broken algorithm - overwritten nodename", 10, fcp, nf); +}}if (nbootstrap.search (fstring)) { +if (nbootstrap.stringMatchedI (1).equals (uqnodename.stringMatchedI (1))) { +nodename = null; +}if (nodename == null || nodename.length == 0 || nbootstrap.matchedFromI (1) > (uqnodename.matchedFromI (1) + uqnodename.stringMatched ().length)) { +try { +bootstrap = ( new Integer (nbootstrap.stringMatchedI (1))).intValue (); +this.$HasBootstrap = true; +} catch (e) { +if (Clazz.exceptionOf (e, Exception)) { +Error = this.ErrorStringrange (Error, "Can't parse bootstrap value", 4, ncp + nbootstrap.matchedFrom (), nf); +} else { +throw e; +} +} +}}var nodehasdistance = false; +if (ndist.search (fstring)) { +try { +distance = ( new Float (ndist.stringMatchedI (1))).floatValue (); +this.$HasDistances = true; +nodehasdistance = true; +} catch (e) { +if (Clazz.exceptionOf (e, Exception)) { +Error = this.ErrorStringrange (Error, "Can't parse node distance value", 7, ncp + ndist.matchedFrom (), nf); +} else { +throw e; +} +} +}if (ascending) { +c.setName (nodename); +c.dist = (this.$HasDistances) ? distance : DefDistance; +c.setBootstrap ((this.$HasBootstrap) ? bootstrap : DefBootstrap); +if (c === realroot) { +this.RootHasDistance = nodehasdistance; +}this.parseNHXNodeProps (c, commentString2); +commentString2 = null; +} else { +var newnode = new jalview.datamodel.SequenceNode (null, c, nodename, (this.$HasDistances) ? distance : DefDistance, (this.$HasBootstrap) ? bootstrap : DefBootstrap, false); +this.parseNHXNodeProps (c, commentString2); +commentString2 = null; +if (c.right () == null) { +c.setRight (newnode); +} else { +if (c.left () == null) { +c.setLeft (newnode); +} else { +var newdummy = new jalview.datamodel.SequenceNode (null, c, null, (this.$HasDistances ? 0 : DefDistance), 0, true); +newdummy.SetChildren (c.left (), newnode); +c.setLeft (newdummy); +}}}if (ascending) { +c = c.AscendTree (); +if ((d > -1) && (c == null)) { +Error = this.ErrorStringrange (Error, "File broke algorithm: Lost place in tree (is there an extra ')' ?)", 7, fcp, nf); +}}if (nf.charAt (fcp) == ')') { +d--; +ascending = true; +} else { +if (nf.charAt (fcp) == ',') { +if (ascending) { +ascending = false; +} else { +if ((c.left () != null) && (!c.left ().isLeaf ())) { +c = c.left (); +}}}}nodename = null; +distance = DefDistance; +bootstrap = DefBootstrap; +commentString2 = null; +parsednodename = false; +} +if (nextcp == 0) { +ncp = cp = fcp + 1; +} else { +cp = nextcp; +nextcp = 0; +}} +if (Error != null) { +throw ( new java.io.IOException (jalview.util.MessageManager.formatMessage ("exception.newfile", Clazz.newArray (-1, [Error.toString ()])))); +}if (this.root == null) { +throw ( new java.io.IOException (jalview.util.MessageManager.formatMessage ("exception.newfile", Clazz.newArray (-1, [jalview.util.MessageManager.getString ("label.no_tree_read_in")])))); +}this.root = this.root.right ().detach (); +if (!this.RootHasDistance) { +this.root.dist = (this.$HasDistances) ? 0 : DefDistance; +}}); +Clazz.defineMethod (c$, "parseNHXNodeProps", + function (c, commentString) { +if (commentString != null && commentString.startsWith ("&&NHX")) { +var st = new java.util.StringTokenizer (commentString.substring (5), ":"); +while (st.hasMoreTokens ()) { +var tok = st.nextToken (); +var colpos = tok.indexOf ("="); +if (colpos > -1) { +var code = tok.substring (0, colpos); +var value = tok.substring (colpos + 1); +try { +if (code.toLowerCase ().equals ("b")) { +var v = -1; +var iv = new Float (value); +v = iv.intValue (); +c.setBootstrap (v); +this.$HasBootstrap = true; +}} catch (e) { +if (Clazz.exceptionOf (e, Exception)) { +System.err.println ("Couldn't parse code '" + code + "' = '" + value + "'"); +e.printStackTrace (System.err); +} else { +throw e; +} +} +}} +}}, "jalview.datamodel.SequenceNode,~S"); +Clazz.defineMethod (c$, "getTree", +function () { +return this.root; +}); +Clazz.defineMethod (c$, "print", +function () { +{ +var tf = new StringBuffer (); +this.print (tf, this.root); +return (tf.append (";").toString ()); +}}); +Clazz.defineMethod (c$, "print", +function (withbootstraps) { +{ +var boots = this.$HasBootstrap; +this.$HasBootstrap = withbootstraps; +var rv = this.print (); +this.$HasBootstrap = boots; +return rv; +}}, "~B"); +Clazz.defineMethod (c$, "print", +function (withbootstraps, withdists) { +{ +var dists = this.$HasDistances; +this.$HasDistances = withdists; +var rv = this.print (withbootstraps); +this.$HasDistances = dists; +return rv; +}}, "~B,~B"); +Clazz.defineMethod (c$, "print", +function (withbootstraps, withdists, printRootInfo) { +{ +var rootinfo = printRootInfo; +this.printRootInfo = printRootInfo; +var rv = this.print (withbootstraps, withdists); +this.printRootInfo = rootinfo; +return rv; +}}, "~B,~B,~B"); +Clazz.defineMethod (c$, "getQuoteChar", +function () { +return this.QuoteChar; +}); +Clazz.defineMethod (c$, "setQuoteChar", +function (c) { +var old = this.QuoteChar; +this.QuoteChar = c; +return old; +}, "~S"); +Clazz.defineMethod (c$, "nodeName", + function (name) { +if (this.NodeSafeName[0].search (name)) { +return this.QuoteChar + this.NodeSafeName[1].replaceAll (name) + this.QuoteChar; +} else { +return this.NodeSafeName[2].replaceAll (name); +}}, "~S"); +Clazz.defineMethod (c$, "printNodeField", + function (c) { +return ((c.getName () == null) ? "" : this.nodeName (c.getName ())) + ((this.$HasBootstrap) ? ((c.getBootstrap () > -1) ? ((c.getName () != null ? " " : "") + c.getBootstrap ()) : "") : "") + ((this.$HasDistances) ? (":" + c.dist) : ""); +}, "jalview.datamodel.SequenceNode"); +Clazz.defineMethod (c$, "printRootField", + function (root) { +return (this.printRootInfo) ? (((root.getName () == null) ? "" : this.nodeName (root.getName ())) + ((this.$HasBootstrap) ? ((root.getBootstrap () > -1) ? ((root.getName () != null ? " " : "") + +root.getBootstrap ()) : "") : "") + ((this.RootHasDistance) ? (":" + root.dist) : "")) : ""; +}, "jalview.datamodel.SequenceNode"); +Clazz.defineMethod (c$, "print", +function (tf, root) { +if (root != null) { +if (root.isLeaf () && this.printRootInfo) { +tf.append (this.printRootField (root)); +} else { +if (root.isDummy ()) { +this._print (tf, root.right ()); +this._print (tf, root.left ()); +} else { +tf.append ("("); +this._print (tf, root.right ()); +if (root.left () != null) { +tf.append (","); +}this._print (tf, root.left ()); +tf.append (")" + this.printRootField (root)); +}}}}, "StringBuffer,jalview.datamodel.SequenceNode"); +Clazz.defineMethod (c$, "_print", +function (tf, c) { +if (c != null) { +if (c.isLeaf ()) { +tf.append (this.printNodeField (c)); +} else { +if (c.isDummy ()) { +this._print (tf, c.left ()); +if (c.left () != null) { +tf.append (","); +}this._print (tf, c.right ()); +} else { +tf.append ("("); +this._print (tf, c.right ()); +if (c.left () != null) { +tf.append (","); +}this._print (tf, c.left ()); +tf.append (")" + this.printNodeField (c)); +}}}}, "StringBuffer,jalview.datamodel.SequenceNode"); +c$.main = Clazz.defineMethod (c$, "main", +function (args) { +try { +if (args == null || args.length != 1) { +System.err.println ("Takes one argument - file name of a newick tree file."); +System.exit (0); +}var fn = new java.io.File (args[0]); +var newickfile = new StringBuffer (); +var treefile = new java.io.BufferedReader ( new java.io.FileReader (fn)); +var l; +while ((l = treefile.readLine ()) != null) { +newickfile.append (l); +} +treefile.close (); +System.out.println ("Read file :\n"); +var trf = new jalview.io.NewickFile (args[0], "File"); +trf.parse (); +System.out.println ("Original file :\n"); +var nonl = jalview.jsdev.RegExp.newRegex (["\n+", ""]); +System.out.println (nonl.replaceAll (newickfile.toString ()) + "\n"); +System.out.println ("Parsed file.\n"); +System.out.println ("Default output type for original input.\n"); +System.out.println (trf.print ()); +System.out.println ("Without bootstraps.\n"); +System.out.println (trf.print (false)); +System.out.println ("Without distances.\n"); +System.out.println (trf.print (true, false)); +System.out.println ("Without bootstraps but with distanecs.\n"); +System.out.println (trf.print (false, true)); +System.out.println ("Without bootstraps or distanecs.\n"); +System.out.println (trf.print (false, false)); +System.out.println ("With bootstraps and with distances.\n"); +System.out.println (trf.print (true, true)); +} catch (e) { +if (Clazz.exceptionOf (e, java.io.IOException)) { +System.err.println ("Exception\n" + e); +e.printStackTrace (); +} else { +throw e; +} +} +}, "~A"); +});