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