From 251060eb361feb3286f32cbd70d6ec559c03598d Mon Sep 17 00:00:00 2001 From: jprocter Date: Wed, 30 Mar 2005 13:49:20 +0000 Subject: [PATCH] Fixed a sensible default leaf distance (for files where only a few, or no distances are specified). --- src/jalview/io/NewickFile.java | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/jalview/io/NewickFile.java b/src/jalview/io/NewickFile.java index d0af8a7..c3fd9374 100755 --- a/src/jalview/io/NewickFile.java +++ b/src/jalview/io/NewickFile.java @@ -63,15 +63,24 @@ public class NewickFile extends FileParse root = new SequenceNode(); SequenceNode realroot = null; SequenceNode c = root; + int d = -1; int cp = 0; int flen = nf.length(); + String Error = null; String nodename = null; - float distance=-99999; - int bootstrap=-99999; + + float DefDistance = (float) 0.00001; // @param Default distance for a node - very very small + int DefBootstrap = 0; // @param Default bootstrap for a node + + float distance=DefDistance; + int bootstrap=DefBootstrap; + boolean ascending = false; // flag indicating that we are leaving the current node + com.stevesoft.pat.Regex majorsyms = new com.stevesoft.pat.Regex("[(\\['),;]"); + while (majorsyms.searchFrom(nf, cp) && Error==null) { int fcp = majorsyms.matchedFrom(); switch (nf.charAt(fcp)) { @@ -103,7 +112,7 @@ public class NewickFile extends FileParse d++; if (c.right() == null) { - c.setRight(new SequenceNode(null, c, 0, null)); + c.setRight(new SequenceNode(null, c, null, DefDistance, DefBootstrap, false)); c = (SequenceNode) c.right(); } else @@ -115,15 +124,15 @@ public class NewickFile extends FileParse tmpn.SetChildren(c.left(), c.right()); c.setRight(tmpn); } - c.setLeft(new SequenceNode(null, c, 0, null)); + c.setLeft(new SequenceNode(null, c, null, DefDistance, DefBootstrap, false)); c = (SequenceNode) c.left(); } if (realroot==null) { realroot = c; } nodename = null; - distance = -99999; - bootstrap = -99999; + distance = DefDistance; + bootstrap = DefBootstrap; cp = fcp + 1; break; @@ -229,11 +238,12 @@ public class NewickFile extends FileParse else { // Find a place to put the leaf - SequenceNode newnode = new SequenceNode(null, c, - (HasDistances) ? distance : 0, - nodename); - - newnode.setBootstrap(HasBootstrap ? bootstrap : 0); + SequenceNode newnode = + new SequenceNode(null, c, + nodename, + (HasDistances) ? distance : DefDistance, + (HasBootstrap) ? bootstrap : DefBootstrap, + false); if (c.right() == null) { @@ -283,8 +293,8 @@ public class NewickFile extends FileParse } // Reset new node properties to obvious fakes nodename = null; - distance = -99999; - bootstrap = -99999; + distance = DefDistance; + bootstrap = DefBootstrap; cp=fcp+1; } @@ -298,6 +308,7 @@ public class NewickFile extends FileParse if (!RootHasDistance) { root.dist = 0; } + } public NewickFile(SequenceNode newtree) { -- 1.7.10.2