*/\r
package jalview.analysis;\r
\r
-import jalview.datamodel.*;\r
-\r
-import jalview.io.NewickFile;\r
-\r
-import jalview.schemes.ResidueProperties;\r
+import java.util.*;\r
\r
+import jalview.datamodel.*;\r
+import jalview.io.*;\r
+import jalview.schemes.*;\r
import jalview.util.*;\r
\r
-import java.util.*;\r
-\r
\r
/**\r
* DOCUMENT ME!\r
Object leaves = null;\r
int start;\r
int end;\r
+ boolean hasDistances = true; // normal case for jalview trees\r
+ boolean hasBootstrap = false; // normal case for jalview trees\r
+\r
+ private boolean hasRootDistance = true;\r
\r
/**\r
* Creates a new NJTree object.\r
public NJTree(SequenceI[] seqs, NewickFile treefile)\r
{\r
top = treefile.getTree();\r
+\r
+ hasDistances = treefile.HasDistances();\r
+ hasBootstrap = treefile.HasBootstrap();\r
+ hasRootDistance = treefile.HasRootDistance();\r
+\r
maxheight = findHeight(top);\r
\r
SequenceIdMatcher algnIds = new SequenceIdMatcher(seqs);\r
public void findNewNJDistances(SequenceNode tmpi, SequenceNode tmpj,\r
float dist)\r
{\r
- \r
+\r
tmpi.dist = ((dist + ri) - rj) / 2;\r
tmpj.dist = (dist - tmpi.dist);\r
\r
{\r
return top;\r
}\r
+ /**\r
+ *\r
+ * @return true if tree has real distances\r
+ */\r
+ public boolean isHasDistances() {\r
+ return hasDistances;\r
+ }\r
+\r
+ /**\r
+ *\r
+ * @return true if tree has real bootstrap values\r
+ */\r
+ public boolean isHasBootstrap() {\r
+ return hasBootstrap;\r
+ }\r
+\r
+ public boolean isHasRootDistance()\r
+ {\r
+ return hasRootDistance;\r
+ }\r
+\r
}\r
\r
\r
-/*
-* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+/*\r
+* Jalview - A Sequence Alignment Editor and Viewer\r
+* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+*\r
+* This program is free software; you can redistribute it and/or\r
+* modify it under the terms of the GNU General Public License\r
+* as published by the Free Software Foundation; either version 2\r
+* of the License, or (at your option) any later version.\r
+*\r
+* This program is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with this program; if not, write to the Free Software\r
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
*/\r
\r
// NewickFile.java\r
return HasDistances;\r
}\r
\r
+ public boolean HasRootDistance()\r
+ {\r
+ return RootHasDistance;\r
+ }\r
/**\r
* DOCUMENT ME!\r
*\r
String Error = null;\r
String nodename = null;\r
\r
- float DefDistance = (float) 0.00001; // @param Default distance for a node - very very small\r
+ float DefDistance = (float) 0.001; // @param Default distance for a node - very very small\r
int DefBootstrap = 0; // @param Default bootstrap for a node\r
\r
float distance = DefDistance;\r
com.stevesoft.pat.Regex nbootstrap = new com.stevesoft.pat.Regex(\r
"\\S+([0-9+]+)\\S*:");\r
com.stevesoft.pat.Regex ndist = new com.stevesoft.pat.Regex(\r
- ":([-0-9.+]+)");\r
+ ":([-0-9Ee.+]+)");\r
\r
if (uqnodename.search(fstring) &&\r
((uqnodename.matchedFrom(1) == 0) ||\r
{\r
// Write node info here\r
c.setName(nodename);\r
- c.dist = (HasDistances) ? distance : 0;\r
- c.setBootstrap((HasBootstrap) ? bootstrap : 0);\r
-\r
+ // Trees without distances still need a render distance\r
+ c.dist = (HasDistances) ? distance : DefDistance;\r
+ // be consistent for internal bootstrap defaults too\r
+ c.setBootstrap((HasBootstrap) ? bootstrap : DefBootstrap);\r
if (c == realroot)\r
{\r
- RootHasDistance = nodehasdistance; // JBPNote This is really UGLY!!!\r
+ RootHasDistance = nodehasdistance; // JBPNote This is really UGLY!!! Ensure root node gets its given distance\r
}\r
}\r
else\r
else\r
{\r
// Insert a dummy node for polytomy\r
+ // dummy nodes have distances\r
SequenceNode newdummy = new SequenceNode(null, c,\r
- null, 0, 0, true);\r
+ null, (HasDistances ? 0 : DefDistance), 0, true);\r
newdummy.SetChildren(c.left(), newnode);\r
c.setLeft(newdummy);\r
}\r
\r
if (!RootHasDistance)\r
{\r
- root.dist = 0;\r
+ root.dist = (HasDistances) ? 0 : DefDistance;\r
}\r
}\r
\r
}\r
\r
/**\r
- * DOCUMENT ME!\r
+ * Generate a newick format tree according to internal flags\r
+ * for bootstraps, distances and root distances.\r
*\r
- * @return DOCUMENT ME!\r
+ * @return new hampshire tree in a single line\r
*/\r
public String print()\r
{\r
}\r
\r
/**\r
- * DOCUMENT ME!\r
*\r
- * @param withbootstraps DOCUMENT ME!\r
*\r
- * @return DOCUMENT ME!\r
+ * Generate a newick format tree according to internal flags\r
+ * for distances and root distances and user specificied writing of\r
+ * bootstraps.\r
+ * @param withbootstraps controls if bootstrap values are explicitly written.\r
+ *\r
+ * @return new hampshire tree in a single line\r
*/\r
public String print(boolean withbootstraps)\r
{\r
}\r
\r
/**\r
- * DOCUMENT ME!\r
*\r
- * @param withbootstraps DOCUMENT ME!\r
- * @param withdists DOCUMENT ME!\r
+ * Generate newick format tree according to internal flags\r
+ * for writing root node distances.\r
*\r
- * @return DOCUMENT ME!\r
+ * @param withbootstraps explicitly write bootstrap values\r
+ * @param withdists explicitly write distances\r
+ *\r
+ * @return new hampshire tree in a single line\r
*/\r
public String print(boolean withbootstraps, boolean withdists)\r
{\r
}\r
\r
/**\r
- * DOCUMENT ME!\r
+ * Generate newick format tree according to user specified flags\r
*\r
- * @param withbootstraps DOCUMENT ME!\r
- * @param withdists DOCUMENT ME!\r
- * @param printRootInfo DOCUMENT ME!\r
+ * @param withbootstraps explicitly write bootstrap values\r
+ * @param withdists explicitly write distances\r
+ * @param printRootInfo explicitly write root distance\r
*\r
- * @return DOCUMENT ME!\r
+ * @return new hampshire tree in a single line\r
*/\r
public String print(boolean withbootstraps, boolean withdists,\r
boolean printRootInfo)\r
{\r
if (c.isDummy())\r
{\r
- _print(tf, (SequenceNode) c.right());\r
_print(tf, (SequenceNode) c.left());\r
+ if (c.left() != null)\r
+ {\r
+ tf.append(",");\r
+ }\r
+ _print(tf, (SequenceNode) c.right());\r
}\r
else\r
{\r
{\r
try\r
{\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
+ }\r
+\r
File fn = new File(args[0]);\r
\r
StringBuffer newickfile = new StringBuffer();\r