From: James Procter Date: Thu, 23 Feb 2023 12:06:43 +0000 (+0000) Subject: JAL-4134 - refactor tree calculation code to work with binaryNode base type. X-Git-Tag: Release_2_11_3_0~15^2^2~35 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=fe68da05540c32386ec63bd3beeadf8b9d624a16;p=jalview.git JAL-4134 - refactor tree calculation code to work with binaryNode base type. --- diff --git a/src/jalview/analysis/AverageDistanceTree.java b/src/jalview/analysis/AverageDistanceTree.java index c726627..760962e 100644 --- a/src/jalview/analysis/AverageDistanceTree.java +++ b/src/jalview/analysis/AverageDistanceTree.java @@ -22,7 +22,7 @@ package jalview.analysis; import jalview.api.analysis.ScoreModelI; import jalview.api.analysis.SimilarityParamsI; -import jalview.datamodel.SequenceNode; +import jalview.datamodel.BinaryNode; import jalview.viewmodel.AlignmentViewport; /** @@ -113,25 +113,25 @@ public class AverageDistanceTree extends TreeBuilder * {@inheritDoc} */ @Override - protected void findNewDistances(SequenceNode nodei, SequenceNode nodej, + protected void findNewDistances(BinaryNode nodei, BinaryNode nodej, double dist) { double ih = 0; double jh = 0; - SequenceNode sni = nodei; - SequenceNode snj = nodej; + BinaryNode sni = nodei; + BinaryNode snj = nodej; while (sni != null) { ih = ih + sni.dist; - sni = (SequenceNode) sni.left(); + sni = (BinaryNode) sni.left(); } while (snj != null) { jh = jh + snj.dist; - snj = (SequenceNode) snj.left(); + snj = (BinaryNode) snj.left(); } nodei.dist = ((dist / 2) - ih); diff --git a/src/jalview/analysis/NJTree.java b/src/jalview/analysis/NJTree.java index 522c2b1..9a39ac0 100644 --- a/src/jalview/analysis/NJTree.java +++ b/src/jalview/analysis/NJTree.java @@ -22,7 +22,7 @@ package jalview.analysis; import jalview.api.analysis.ScoreModelI; import jalview.api.analysis.SimilarityParamsI; -import jalview.datamodel.SequenceNode; +import jalview.datamodel.BinaryNode; import jalview.viewmodel.AlignmentViewport; /** @@ -81,7 +81,7 @@ public class NJTree extends TreeBuilder * {@inheritDoc} */ @Override - protected void findNewDistances(SequenceNode nodei, SequenceNode nodej, + protected void findNewDistances(BinaryNode nodei, BinaryNode nodej, double dist) { nodei.dist = ((dist + ri) - rj) / 2; diff --git a/src/jalview/analysis/TreeBuilder.java b/src/jalview/analysis/TreeBuilder.java index 0601dd9..78dc37f 100644 --- a/src/jalview/analysis/TreeBuilder.java +++ b/src/jalview/analysis/TreeBuilder.java @@ -23,6 +23,7 @@ package jalview.analysis; import jalview.api.analysis.ScoreModelI; import jalview.api.analysis.SimilarityParamsI; import jalview.datamodel.AlignmentView; +import jalview.datamodel.BinaryNode; import jalview.datamodel.CigarArray; import jalview.datamodel.SeqCigar; import jalview.datamodel.SequenceI; @@ -61,9 +62,9 @@ public abstract class TreeBuilder protected double rj; - SequenceNode maxdist; + BinaryNode maxdist; - SequenceNode top; + BinaryNode top; double maxDistValue; @@ -121,7 +122,7 @@ public abstract class TreeBuilder * * @return DOCUMENT ME! */ - double findHeight(SequenceNode nd) + double findHeight(BinaryNode nd) { if (nd == null) { @@ -130,7 +131,7 @@ public abstract class TreeBuilder if ((nd.left() == null) && (nd.right() == null)) { - nd.height = ((SequenceNode) nd.parent()).height + nd.dist; + nd.height = ((BinaryNode) nd.parent()).height + nd.dist; if (nd.height > maxheight) { @@ -145,7 +146,7 @@ public abstract class TreeBuilder { if (nd.parent() != null) { - nd.height = ((SequenceNode) nd.parent()).height + nd.dist; + nd.height = ((BinaryNode) nd.parent()).height + nd.dist; } else { @@ -153,8 +154,8 @@ public abstract class TreeBuilder nd.height = (float) 0.0; } - maxheight = findHeight((SequenceNode) (nd.left())); - maxheight = findHeight((SequenceNode) (nd.right())); + maxheight = findHeight((BinaryNode) (nd.left())); + maxheight = findHeight((BinaryNode) (nd.right())); } return maxheight; @@ -166,7 +167,7 @@ public abstract class TreeBuilder * @param nd * DOCUMENT ME! */ - void reCount(SequenceNode nd) + void reCount(BinaryNode nd) { ycount = 0; // _lycount = 0; @@ -180,7 +181,7 @@ public abstract class TreeBuilder * @param nd * DOCUMENT ME! */ - void _reCount(SequenceNode nd) + void _reCount(BinaryNode nd) { // if (_lycount<_lylimit) // { @@ -196,11 +197,11 @@ public abstract class TreeBuilder if ((nd.left() != null) && (nd.right() != null)) { - _reCount((SequenceNode) nd.left()); - _reCount((SequenceNode) nd.right()); + _reCount(nd.left()); + _reCount((BinaryNode) nd.right()); - SequenceNode l = (SequenceNode) nd.left(); - SequenceNode r = (SequenceNode) nd.right(); + BinaryNode l = nd.left(); + BinaryNode r = nd.right(); nd.count = l.count + r.count; nd.ycount = (l.ycount + r.ycount) / 2; @@ -218,7 +219,7 @@ public abstract class TreeBuilder * * @return DOCUMENT ME! */ - public SequenceNode getTopNode() + public BinaryNode getTopNode() { return top; } @@ -310,7 +311,7 @@ public abstract class TreeBuilder * * @param nd */ - void findMaxDist(SequenceNode nd) + void findMaxDist(BinaryNode nd) { if (nd == null) { @@ -329,8 +330,8 @@ public abstract class TreeBuilder } else { - findMaxDist((SequenceNode) nd.left()); - findMaxDist((SequenceNode) nd.right()); + findMaxDist((BinaryNode) nd.left()); + findMaxDist((BinaryNode) nd.right()); } } @@ -417,8 +418,8 @@ public abstract class TreeBuilder sn.setLeft((node.elementAt(i))); sn.setRight((node.elementAt(j))); - SequenceNode tmpi = (node.elementAt(i)); - SequenceNode tmpj = (node.elementAt(j)); + BinaryNode tmpi = (node.elementAt(i)); + BinaryNode tmpj = (node.elementAt(j)); findNewDistances(tmpi, tmpj, dist); @@ -440,8 +441,8 @@ public abstract class TreeBuilder * Computes and stores new distances for nodei and nodej, given the previous * distance between them */ - protected abstract void findNewDistances(SequenceNode nodei, - SequenceNode nodej, double previousDistance); + protected abstract void findNewDistances(BinaryNode nodei, + BinaryNode nodej, double previousDistance); /** * Calculates and saves the distance between the combination of cluster(i) and diff --git a/src/jalview/analysis/TreeModel.java b/src/jalview/analysis/TreeModel.java index 4d5e4b2..703702a 100644 --- a/src/jalview/analysis/TreeModel.java +++ b/src/jalview/analysis/TreeModel.java @@ -95,7 +95,7 @@ public class TreeModel */ public TreeModel(TreeBuilder tree) { - this(tree.getSequences(), tree.getTopNode(), tree.hasDistances(), + this(tree.getSequences(), (SequenceNode) tree.getTopNode(), tree.hasDistances(), tree.hasBootstrap(), tree.hasRootDistance()); seqData = tree.getOriginalData(); } @@ -345,7 +345,7 @@ public class TreeModel * @param nd * SequenceNode */ - void printNode(SequenceNode nd) + void printNode(BinaryNode nd) { if (nd == null) { @@ -361,8 +361,8 @@ public class TreeModel else { System.out.println("Dist " + nd.dist); - printNode((SequenceNode) nd.left()); - printNode((SequenceNode) nd.right()); + printNode((BinaryNode) nd.left()); + printNode((BinaryNode) nd.right()); } } @@ -422,7 +422,7 @@ public class TreeModel * * @return DOCUMENT ME! */ - public double findHeight(SequenceNode nd) + public double findHeight(BinaryNode nd) { if (nd == null) { @@ -431,7 +431,7 @@ public class TreeModel if ((nd.left() == null) && (nd.right() == null)) { - nd.height = ((SequenceNode) nd.parent()).height + nd.dist; + nd.height = ((BinaryNode) nd.parent()).height + nd.dist; if (nd.height > maxheight) { @@ -446,7 +446,7 @@ public class TreeModel { if (nd.parent() != null) { - nd.height = ((SequenceNode) nd.parent()).height + nd.dist; + nd.height = ((BinaryNode) nd.parent()).height + nd.dist; } else { @@ -454,8 +454,8 @@ public class TreeModel nd.height = (float) 0.0; } - maxheight = findHeight((SequenceNode) (nd.left())); - maxheight = findHeight((SequenceNode) (nd.right())); + maxheight = findHeight((BinaryNode) (nd.left())); + maxheight = findHeight((BinaryNode) (nd.right())); } return maxheight; @@ -467,7 +467,7 @@ public class TreeModel * @param nd * DOCUMENT ME! */ - void printN(SequenceNode nd) + void printN(BinaryNode nd) { if (nd == null) { @@ -476,8 +476,8 @@ public class TreeModel if ((nd.left() != null) && (nd.right() != null)) { - printN((SequenceNode) nd.left()); - printN((SequenceNode) nd.right()); + printN((BinaryNode) nd.left()); + printN((BinaryNode) nd.right()); } else { @@ -494,7 +494,7 @@ public class TreeModel * @param nd * DOCUMENT ME! */ - public void reCount(SequenceNode nd) + public void reCount(BinaryNode nd) { ycount = 0; // _lycount = 0; @@ -510,7 +510,7 @@ public class TreeModel * @param nd * DOCUMENT ME! */ - void _reCount(SequenceNode nd) + void _reCount(BinaryNode nd) { // if (_lycount<_lylimit) // { @@ -526,11 +526,11 @@ public class TreeModel if ((nd.left() != null) && (nd.right() != null)) { - _reCount((SequenceNode) nd.left()); - _reCount((SequenceNode) nd.right()); + _reCount((BinaryNode) nd.left()); + _reCount((BinaryNode) nd.right()); - SequenceNode l = (SequenceNode) nd.left(); - SequenceNode r = (SequenceNode) nd.right(); + BinaryNode l = (BinaryNode) nd.left(); + BinaryNode r = (BinaryNode) nd.right(); nd.count = l.count + r.count; nd.ycount = (l.ycount + r.ycount) / 2; @@ -549,14 +549,14 @@ public class TreeModel * @param nd * DOCUMENT ME! */ - public void swapNodes(SequenceNode nd) + public void swapNodes(BinaryNode nd) { if (nd == null) { return; } - SequenceNode tmp = (SequenceNode) nd.left(); + BinaryNode tmp = (BinaryNode) nd.left(); nd.setLeft(nd.right()); nd.setRight(tmp); @@ -570,7 +570,7 @@ public class TreeModel * @param dir * DOCUMENT ME! */ - void changeDirection(SequenceNode nd, SequenceNode dir) + void changeDirection(BinaryNode nd, BinaryNode dir) { if (nd == null) { @@ -579,9 +579,9 @@ public class TreeModel if (nd.parent() != top) { - changeDirection((SequenceNode) nd.parent(), nd); + changeDirection((BinaryNode) nd.parent(), nd); - SequenceNode tmp = (SequenceNode) nd.parent(); + BinaryNode tmp = (BinaryNode) nd.parent(); if (dir == nd.left()) { diff --git a/src/jalview/appletgui/TreeCanvas.java b/src/jalview/appletgui/TreeCanvas.java index 2e5f938..1355916 100755 --- a/src/jalview/appletgui/TreeCanvas.java +++ b/src/jalview/appletgui/TreeCanvas.java @@ -23,6 +23,7 @@ package jalview.appletgui; import jalview.analysis.Conservation; import jalview.analysis.TreeModel; import jalview.api.AlignViewportI; +import jalview.datamodel.BinaryNode; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; @@ -263,9 +264,9 @@ public class TreeCanvas extends Panel } int ystart = (int) (node.left() == null ? 0 - : (((SequenceNode) node.left()).ycount * chunk)) + offy; + : (((BinaryNode) node.left()).ycount * chunk)) + offy; int yend = (int) (node.right() == null ? 0 - : (((SequenceNode) node.right()).ycount * chunk)) + offy; + : (((BinaryNode) node.right()).ycount * chunk)) + offy; Rectangle pos = new Rectangle(xend - 2, ypos - 2, 5, 5); nodeHash.put(node, pos); @@ -338,20 +339,20 @@ public class TreeCanvas extends Panel int width = getSize().width; int height = getSize().height; - SequenceNode top = tree.getTopNode(); + BinaryNode top = tree.getTopNode(); double wscale = (float) (width * .8 - offx * 2) / tree.getMaxHeight(); if (top.count == 0) { - top.count = ((SequenceNode) top.left()).count - + ((SequenceNode) top.right()).count; + top.count = ((BinaryNode) top.left()).count + + ((BinaryNode) top.right()).count; } float chunk = (float) (height - offy) / top.count; pickNode(pickBox, top, chunk, wscale, width, offx, offy); } - public void pickNode(Rectangle pickBox, SequenceNode node, float chunk, + public void pickNode(Rectangle pickBox, BinaryNode node, float chunk, double scale, int width, int offx, int offy) { if (node == null) @@ -384,14 +385,14 @@ public class TreeCanvas extends Panel } else { - pickNode(pickBox, (SequenceNode) node.left(), chunk, scale, width, + pickNode(pickBox, (BinaryNode) node.left(), chunk, scale, width, offx, offy); - pickNode(pickBox, (SequenceNode) node.right(), chunk, scale, width, + pickNode(pickBox, (BinaryNode) node.right(), chunk, scale, width, offx, offy); } } - public void setColor(SequenceNode node, Color c) + public void setColor(BinaryNode node, Color c) { if (node == null) { @@ -410,8 +411,8 @@ public class TreeCanvas extends Panel else { node.color = c; - setColor((SequenceNode) node.left(), c); - setColor((SequenceNode) node.right(), c); + setColor((BinaryNode) node.left(), c); + setColor((BinaryNode) node.right(), c); } } @@ -469,12 +470,12 @@ public class TreeCanvas extends Panel double wscale = (width - labelLength - offx * 2) / tree.getMaxHeight(); - SequenceNode top = tree.getTopNode(); + BinaryNode top = tree.getTopNode(); if (top.count == 0) { - top.count = ((SequenceNode) top.left()).count - + ((SequenceNode) top.right()).count; + top.count = ((BinaryNode) top.left()).count + + ((BinaryNode) top.right()).count; } float chunk = (float) (height - offy) / top.count; diff --git a/src/jalview/datamodel/BinaryNode.java b/src/jalview/datamodel/BinaryNode.java index c0ff0e4..6d392d4 100755 --- a/src/jalview/datamodel/BinaryNode.java +++ b/src/jalview/datamodel/BinaryNode.java @@ -20,6 +20,8 @@ */ package jalview.datamodel; +import java.awt.Color; + /** * DOCUMENT ME! * @@ -41,6 +43,24 @@ public class BinaryNode /** DOCUMENT ME!! */ public int bootstrap; + /** DOCUMENT ME!! */ + public double dist; + + /** DOCUMENT ME!! */ + public int count; + + /** DOCUMENT ME!! */ + public double height; + + /** DOCUMENT ME!! */ + public float ycount; + + /** DOCUMENT ME!! */ + public Color color = Color.black; + + /** DOCUMENT ME!! */ + public boolean dummy = false; + /** * Creates a new BinaryNode object. */ @@ -300,4 +320,20 @@ public class BinaryNode { return bootstrap; } + + /** + * ascends the tree but doesn't stop until a non-dummy node is discovered. + * + */ + public BinaryNode AscendTree() + { + BinaryNode c = this; + + do + { + c = c.parent(); + } while ((c != null) && c.dummy); + + return c; + } } diff --git a/src/jalview/datamodel/SequenceNode.java b/src/jalview/datamodel/SequenceNode.java index 0a694c2..30179f5 100755 --- a/src/jalview/datamodel/SequenceNode.java +++ b/src/jalview/datamodel/SequenceNode.java @@ -20,8 +20,6 @@ */ package jalview.datamodel; -import java.awt.Color; - /** * DOCUMENT ME! * @@ -30,24 +28,6 @@ import java.awt.Color; */ public class SequenceNode extends BinaryNode { - /** DOCUMENT ME!! */ - public double dist; - - /** DOCUMENT ME!! */ - public int count; - - /** DOCUMENT ME!! */ - public double height; - - /** DOCUMENT ME!! */ - public float ycount; - - /** DOCUMENT ME!! */ - public Color color = Color.black; - - /** DOCUMENT ME!! */ - public boolean dummy = false; - private boolean placeholder = false; /** @@ -70,7 +50,7 @@ public class SequenceNode extends BinaryNode * @param name * DOCUMENT ME! */ - public SequenceNode(Object val, SequenceNode parent, double dist, + public SequenceNode(Object val, BinaryNode parent, double dist, String name) { super(val, parent, name); @@ -93,7 +73,7 @@ public class SequenceNode extends BinaryNode * @param dummy * DOCUMENT ME! */ - public SequenceNode(Object val, SequenceNode parent, String name, + public SequenceNode(Object val, BinaryNode parent, String name, double dist, int bootstrap, boolean dummy) { super(val, parent, name); @@ -148,23 +128,6 @@ public class SequenceNode extends BinaryNode } /** - * ascends the tree but doesn't stop until a non-dummy node is discovered. - * This will probably break if the tree is a mixture of BinaryNodes and - * SequenceNodes. - */ - public SequenceNode AscendTree() - { - SequenceNode c = this; - - do - { - c = (SequenceNode) c.parent(); - } while ((c != null) && c.dummy); - - return c; - } - - /** * test if this node has a name that might be a label rather than a bootstrap * value * diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 6f143db..a5f1ab9 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -50,6 +50,7 @@ import javax.swing.ToolTipManager; import jalview.analysis.Conservation; import jalview.analysis.TreeModel; import jalview.api.AlignViewportI; +import jalview.datamodel.BinaryNode; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; @@ -332,9 +333,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } int ystart = (node.left() == null ? 0 - : (int) (((SequenceNode) node.left()).ycount * chunk)) + offy; + : (int) (((BinaryNode) node.left()).ycount * chunk)) + offy; int yend = (node.right() == null ? 0 - : (int) (((SequenceNode) node.right()).ycount * chunk)) + : (int) (((BinaryNode) node.right()).ycount * chunk)) + offy; Rectangle pos = new Rectangle(xend - 2, ypos - 2, 5, 5); @@ -415,14 +416,14 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, int width = getWidth(); int height = getHeight(); - SequenceNode top = tree.getTopNode(); + BinaryNode top = tree.getTopNode(); double wscale = ((width * .8) - (offx * 2)) / tree.getMaxHeight(); if (top.count == 0) { - top.count = ((SequenceNode) top.left()).count - + ((SequenceNode) top.right()).count; + top.count = ((BinaryNode) top.left()).count + + ((BinaryNode) top.right()).count; } float chunk = (float) (height - (offy)) / top.count; @@ -448,7 +449,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * @param offy * DOCUMENT ME! */ - public void pickNode(Rectangle pickBox, SequenceNode node, float chunk, + public void pickNode(Rectangle pickBox, BinaryNode node, float chunk, double wscale, int width, int offx, int offy) { if (node == null) @@ -481,9 +482,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } else { - pickNode(pickBox, (SequenceNode) node.left(), chunk, wscale, width, + pickNode(pickBox, (BinaryNode) node.left(), chunk, wscale, width, offx, offy); - pickNode(pickBox, (SequenceNode) node.right(), chunk, wscale, width, + pickNode(pickBox, (BinaryNode) node.right(), chunk, wscale, width, offx, offy); } } @@ -496,7 +497,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * @param c * DOCUMENT ME! */ - public void setColor(SequenceNode node, Color c) + public void setColor(BinaryNode node, Color c) { if (node == null) { @@ -516,8 +517,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } } } - setColor((SequenceNode) node.left(), c); - setColor((SequenceNode) node.right(), c); + setColor((BinaryNode) node.left(), c); + setColor((BinaryNode) node.right(), c); } /** @@ -713,12 +714,12 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, double wscale = (width - labelLength - (offx * 2)) / tree.getMaxHeight(); - SequenceNode top = tree.getTopNode(); + BinaryNode top = tree.getTopNode(); if (top.count == 0) { - top.count = ((SequenceNode) top.left()).count - + ((SequenceNode) top.right()).count; + top.count = ((BinaryNode) top.left()).count + + ((BinaryNode) top.right()).count; } float chunk = (float) (height - (offy)) / top.count; diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java index 76e1884..9a4f2c4 100755 --- a/src/jalview/gui/TreePanel.java +++ b/src/jalview/gui/TreePanel.java @@ -721,7 +721,7 @@ public class TreePanel extends GTreePanel && !((SequenceNode) node).isDummy()) { String newname = null; - SequenceI sq = (SequenceI) ((SequenceNode) node).element(); + SequenceI sq = (SequenceI) ((BinaryNode) node).element(); if (sq != null) { // search dbrefs, features and annotation @@ -763,7 +763,7 @@ public class TreePanel extends GTreePanel { // String oldname = ((SequenceNode) node).getName(); // TODO : save oldname in the undo object for this modification. - ((SequenceNode) node).setName(newname); + ((BinaryNode) node).setName(newname); } } } diff --git a/src/jalview/io/NewickFile.java b/src/jalview/io/NewickFile.java index 027390a..879b7d4 100755 --- a/src/jalview/io/NewickFile.java +++ b/src/jalview/io/NewickFile.java @@ -28,6 +28,7 @@ package jalview.io; import java.util.Locale; +import jalview.datamodel.BinaryNode; import jalview.datamodel.SequenceNode; import jalview.util.MessageManager; @@ -275,8 +276,8 @@ public class NewickFile extends FileParse root = new SequenceNode(); - SequenceNode realroot = null; - SequenceNode c = root; + BinaryNode realroot = null; + BinaryNode c = root; int d = -1; int cp = 0; @@ -323,21 +324,21 @@ public class NewickFile extends FileParse { c.setRight(new SequenceNode(null, c, null, DefDistance, DefBootstrap, false)); - c = (SequenceNode) c.right(); + c = (BinaryNode) c.right(); } else { if (c.left() != null) { // Dummy node for polytomy - keeps c.left free for new node - SequenceNode tmpn = new SequenceNode(null, c, null, 0, 0, true); + BinaryNode tmpn = new SequenceNode(null, c, null, 0, 0, true); tmpn.SetChildren(c.left(), c.right()); c.setRight(tmpn); } c.setLeft(new SequenceNode(null, c, null, DefDistance, DefBootstrap, false)); - c = (SequenceNode) c.left(); + c = (BinaryNode) c.left(); } if (realroot == null) @@ -518,7 +519,7 @@ public class NewickFile extends FileParse else { // Find a place to put the leaf - SequenceNode newnode = new SequenceNode(null, c, nodename, + BinaryNode newnode = new SequenceNode(null, c, nodename, (HasDistances) ? distance : DefDistance, (HasBootstrap) ? bootstrap : DefBootstrap, false); parseNHXNodeProps(c, commentString2); @@ -538,7 +539,7 @@ public class NewickFile extends FileParse { // Insert a dummy node for polytomy // dummy nodes have distances - SequenceNode newdummy = new SequenceNode(null, c, null, + BinaryNode newdummy = new SequenceNode(null, c, null, (HasDistances ? 0 : DefDistance), 0, true); newdummy.SetChildren(c.left(), newnode); c.setLeft(newdummy); @@ -577,7 +578,7 @@ public class NewickFile extends FileParse // Just advance focus, if we need to if ((c.left() != null) && (!c.left().isLeaf())) { - c = (SequenceNode) c.left(); + c = (BinaryNode) c.left(); } } } @@ -631,7 +632,7 @@ public class NewickFile extends FileParse * @param commentString * @param commentString2 */ - private void parseNHXNodeProps(SequenceNode c, String commentString) + private void parseNHXNodeProps(BinaryNode c, String commentString) { // TODO: store raw comment on the sequenceNode so it can be recovered when // tree is output @@ -832,7 +833,7 @@ public class NewickFile extends FileParse * * @return DOCUMENT ME! */ - private String printNodeField(SequenceNode c) + private String printNodeField(BinaryNode c) { return ((c.getName() == null) ? "" : nodeName(c.getName())) + ((HasBootstrap) ? ((c.getBootstrap() > -1) @@ -849,7 +850,7 @@ public class NewickFile extends FileParse * * @return DOCUMENT ME! */ - private String printRootField(SequenceNode root) + private String printRootField(BinaryNode root) { return (printRootInfo) ? (((root.getName() == null) ? "" : nodeName(root.getName())) diff --git a/src/jalview/io/vamsas/Tree.java b/src/jalview/io/vamsas/Tree.java index e8f6f6b..260894d 100644 --- a/src/jalview/io/vamsas/Tree.java +++ b/src/jalview/io/vamsas/Tree.java @@ -394,7 +394,7 @@ public class Tree extends DatastoreItem { if (!((jalview.datamodel.SequenceNode) tnode).isPlaceholder()) { - Object assocseq = ((jalview.datamodel.SequenceNode) tnode) + Object assocseq = ((BinaryNode) tnode) .element(); if (assocseq instanceof SequenceI) { diff --git a/test/jalview/io/NewickFileTests.java b/test/jalview/io/NewickFileTests.java index beedb11..02c5ccd 100644 --- a/test/jalview/io/NewickFileTests.java +++ b/test/jalview/io/NewickFileTests.java @@ -24,6 +24,7 @@ import static org.testng.ConversionUtils.wrapDataProvider; import jalview.analysis.SequenceIdMatcher; import jalview.analysis.TreeModel; +import jalview.datamodel.BinaryNode; import jalview.datamodel.SequenceI; import jalview.datamodel.SequenceNode; import jalview.gui.JvOptionPane; @@ -119,7 +120,7 @@ public class NewickFileTests stage + "Newick file is invalid ('" + nf_regen.getWarningMessage() + "')", nf_regen.isValid()); - SequenceNode tree_regen = nf.getTree(); + BinaryNode tree_regen = nf.getTree(); AssertJUnit.assertTrue(stage + "Null Tree", tree_regen != null); stage = "Compare original and generated tree" + treename;