From: gmungoc Date: Thu, 1 Sep 2016 12:47:02 +0000 (+0100) Subject: JAL-1421 add generics to NJTree, refactor recursive search X-Git-Tag: Release_2_10_0~54 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=9b9b058f82be7403a76d41fe17016b8b44b12db7;p=jalview.git JAL-1421 add generics to NJTree, refactor recursive search --- diff --git a/src/jalview/analysis/NJTree.java b/src/jalview/analysis/NJTree.java index 4489783..96b45c1 100644 --- a/src/jalview/analysis/NJTree.java +++ b/src/jalview/analysis/NJTree.java @@ -44,7 +44,7 @@ import java.util.Vector; */ public class NJTree { - Vector cluster; + Vector cluster; SequenceI[] sequence; @@ -68,7 +68,7 @@ public class NJTree float rj; - Vector groups = new Vector(); + Vector groups = new Vector(); SequenceNode maxdist; @@ -80,7 +80,7 @@ public class NJTree int ycount; - Vector node; + Vector node; String type; @@ -88,8 +88,6 @@ public class NJTree Object found = null; - Object leaves = null; - boolean hasDistances = true; // normal case for jalview trees boolean hasBootstrap = false; // normal case for jalview trees @@ -151,8 +149,7 @@ public class NJTree SequenceIdMatcher algnIds = new SequenceIdMatcher(seqs); - Vector leaves = new Vector(); - findLeaves(top, leaves); + Vector leaves = findLeaves(top); int i = 0; int namesleft = seqs.length; @@ -160,11 +157,11 @@ public class NJTree SequenceNode j; SequenceI nam; String realnam; - Vector one2many = new Vector(); + Vector one2many = new Vector(); int countOne2Many = 0; while (i < leaves.size()) { - j = (SequenceNode) leaves.elementAt(i++); + j = leaves.elementAt(i++); realnam = j.getName(); nam = null; @@ -221,7 +218,7 @@ public class NJTree String pwtype, ScoreModelI sm, int start, int end) { this.sequence = sequence; - this.node = new Vector(); + this.node = new Vector(); this.type = type; this.pwtype = pwtype; if (seqData != null) @@ -282,6 +279,7 @@ public class NJTree * * @return Newick File with all tree data available */ + @Override public String toString() { jalview.io.NewickFile fout = new jalview.io.NewickFile(getTopNode()); @@ -299,8 +297,7 @@ public class NJTree */ public void UpdatePlaceHolders(List list) { - Vector leaves = new Vector(); - findLeaves(top, leaves); + Vector leaves = findLeaves(top); int sz = leaves.size(); SequenceIdMatcher seqmatcher = null; @@ -308,7 +305,7 @@ public class NJTree while (i < sz) { - SequenceNode leaf = (SequenceNode) leaves.elementAt(i++); + SequenceNode leaf = leaves.elementAt(i++); if (list.contains(leaf.element())) { @@ -369,12 +366,12 @@ public class NJTree { @Override - public void transform(BinaryNode node) + public void transform(BinaryNode nd) { - Object el = node.element(); + Object el = nd.element(); if (el != null && el instanceof SequenceI) { - node.setName(((SequenceI) el).getName()); + nd.setName(((SequenceI) el).getName()); } } }); @@ -428,7 +425,7 @@ public class NJTree } joinClusters(one, two); - top = (SequenceNode) (node.elementAt(one)); + top = (node.elementAt(one)); reCount(top); findHeight(top); @@ -449,19 +446,19 @@ public class NJTree { float dist = distance[i][j]; - int noi = ((Cluster) cluster.elementAt(i)).value.length; - int noj = ((Cluster) cluster.elementAt(j)).value.length; + int noi = cluster.elementAt(i).value.length; + int noj = cluster.elementAt(j).value.length; int[] value = new int[noi + noj]; for (int ii = 0; ii < noi; ii++) { - value[ii] = ((Cluster) cluster.elementAt(i)).value[ii]; + value[ii] = cluster.elementAt(i).value[ii]; } for (int ii = noi; ii < (noi + noj); ii++) { - value[ii] = ((Cluster) cluster.elementAt(j)).value[ii - noi]; + value[ii] = cluster.elementAt(j).value[ii - noi]; } Cluster c = new Cluster(value); @@ -480,11 +477,11 @@ public class NJTree SequenceNode sn = new SequenceNode(); - sn.setLeft((SequenceNode) (node.elementAt(i))); - sn.setRight((SequenceNode) (node.elementAt(j))); + sn.setLeft((node.elementAt(i))); + sn.setRight((node.elementAt(j))); - SequenceNode tmpi = (SequenceNode) (node.elementAt(i)); - SequenceNode tmpj = (SequenceNode) (node.elementAt(j)); + SequenceNode tmpi = (node.elementAt(i)); + SequenceNode tmpj = (node.elementAt(j)); if (type.equals("NJ")) { @@ -576,8 +573,8 @@ public class NJTree */ public void findClusterDistance(int i, int j) { - int noi = ((Cluster) cluster.elementAt(i)).value.length; - int noj = ((Cluster) cluster.elementAt(j)).value.length; + int noi = cluster.elementAt(i).value.length; + int noj = cluster.elementAt(j).value.length; // New distances from cluster to others float[] newdist = new float[noseqs]; @@ -733,7 +730,7 @@ public class NJTree public float[][] findDistances(ScoreModelI _pwmatrix) { - float[][] distance = new float[noseqs][noseqs]; + float[][] dist = new float[noseqs][noseqs]; if (_pwmatrix == null) { // Resolve substitution model @@ -743,8 +740,8 @@ public class NJTree _pwmatrix = ResidueProperties.getScoreMatrix("BLOSUM62"); } } - distance = _pwmatrix.findDistances(seqData); - return distance; + dist = _pwmatrix.findDistances(seqData); + return dist; } @@ -753,7 +750,7 @@ public class NJTree */ public void makeLeaves() { - cluster = new Vector(); + cluster = new Vector(); for (int i = 0; i < noseqs; i++) { @@ -772,26 +769,42 @@ public class NJTree } /** + * Search for leaf nodes below (or at) the given node + * + * @param nd + * root node to search from + * + * @return + */ + public Vector findLeaves(SequenceNode nd) + { + Vector leaves = new Vector(); + findLeaves(nd, leaves); + return leaves; + } + + /** * Search for leaf nodes. * - * @param node + * @param nd * root node to search from * @param leaves * Vector of leaves to add leaf node objects too. * * @return Vector of leaf nodes on binary tree */ - public Vector findLeaves(SequenceNode node, Vector leaves) + Vector findLeaves(SequenceNode nd, + Vector leaves) { - if (node == null) + if (nd == null) { return leaves; } - if ((node.left() == null) && (node.right() == null)) // Interior node + if ((nd.left() == null) && (nd.right() == null)) // Interior node // detection { - leaves.addElement(node); + leaves.addElement(nd); return leaves; } @@ -801,8 +814,8 @@ public class NJTree * TODO: Identify internal nodes... if (node.isSequenceLabel()) { * leaves.addElement(node); } */ - findLeaves((SequenceNode) node.left(), leaves); - findLeaves((SequenceNode) node.right(), leaves); + findLeaves((SequenceNode) nd.left(), leaves); + findLeaves((SequenceNode) nd.right(), leaves); } return leaves; @@ -811,16 +824,16 @@ public class NJTree /** * Find the leaf node with a particular ycount * - * @param node + * @param nd * initial point on tree to search from * @param count * value to search for * * @return null or the node with ycound=count */ - public Object findLeaf(SequenceNode node, int count) + public Object findLeaf(SequenceNode nd, int count) { - found = _findLeaf(node, count); + found = _findLeaf(nd, count); return found; } @@ -828,23 +841,23 @@ public class NJTree /* * #see findLeaf(SequenceNode node, count) */ - public Object _findLeaf(SequenceNode node, int count) + public Object _findLeaf(SequenceNode nd, int count) { - if (node == null) + if (nd == null) { return null; } - if (node.ycount == count) + if (nd.ycount == count) { - found = node.element(); + found = nd.element(); return found; } else { - _findLeaf((SequenceNode) node.left(), count); - _findLeaf((SequenceNode) node.right(), count); + _findLeaf((SequenceNode) nd.left(), count); + _findLeaf((SequenceNode) nd.right(), count); } return found; @@ -853,58 +866,58 @@ public class NJTree /** * printNode is mainly for debugging purposes. * - * @param node + * @param nd * SequenceNode */ - public void printNode(SequenceNode node) + public void printNode(SequenceNode nd) { - if (node == null) + if (nd == null) { return; } - if ((node.left() == null) && (node.right() == null)) + if ((nd.left() == null) && (nd.right() == null)) { System.out - .println("Leaf = " + ((SequenceI) node.element()).getName()); - System.out.println("Dist " + node.dist); - System.out.println("Boot " + node.getBootstrap()); + .println("Leaf = " + ((SequenceI) nd.element()).getName()); + System.out.println("Dist " + nd.dist); + System.out.println("Boot " + nd.getBootstrap()); } else { - System.out.println("Dist " + node.dist); - printNode((SequenceNode) node.left()); - printNode((SequenceNode) node.right()); + System.out.println("Dist " + nd.dist); + printNode((SequenceNode) nd.left()); + printNode((SequenceNode) nd.right()); } } /** * DOCUMENT ME! * - * @param node + * @param nd * DOCUMENT ME! */ - public void findMaxDist(SequenceNode node) + public void findMaxDist(SequenceNode nd) { - if (node == null) + if (nd == null) { return; } - if ((node.left() == null) && (node.right() == null)) + if ((nd.left() == null) && (nd.right() == null)) { - float dist = node.dist; + float dist = nd.dist; if (dist > maxDistValue) { - maxdist = node; + maxdist = nd; maxDistValue = dist; } } else { - findMaxDist((SequenceNode) node.left()); - findMaxDist((SequenceNode) node.right()); + findMaxDist((SequenceNode) nd.left()); + findMaxDist((SequenceNode) nd.right()); } } @@ -913,7 +926,7 @@ public class NJTree * * @return DOCUMENT ME! */ - public Vector getGroups() + public Vector getGroups() { return groups; } @@ -931,51 +944,51 @@ public class NJTree /** * DOCUMENT ME! * - * @param node + * @param nd * DOCUMENT ME! * @param threshold * DOCUMENT ME! */ - public void groupNodes(SequenceNode node, float threshold) + public void groupNodes(SequenceNode nd, float threshold) { - if (node == null) + if (nd == null) { return; } - if ((node.height / maxheight) > threshold) + if ((nd.height / maxheight) > threshold) { - groups.addElement(node); + groups.addElement(nd); } else { - groupNodes((SequenceNode) node.left(), threshold); - groupNodes((SequenceNode) node.right(), threshold); + groupNodes((SequenceNode) nd.left(), threshold); + groupNodes((SequenceNode) nd.right(), threshold); } } /** * DOCUMENT ME! * - * @param node + * @param nd * DOCUMENT ME! * * @return DOCUMENT ME! */ - public float findHeight(SequenceNode node) + public float findHeight(SequenceNode nd) { - if (node == null) + if (nd == null) { return maxheight; } - if ((node.left() == null) && (node.right() == null)) + if ((nd.left() == null) && (nd.right() == null)) { - node.height = ((SequenceNode) node.parent()).height + node.dist; + nd.height = ((SequenceNode) nd.parent()).height + nd.dist; - if (node.height > maxheight) + if (nd.height > maxheight) { - return node.height; + return nd.height; } else { @@ -984,18 +997,18 @@ public class NJTree } else { - if (node.parent() != null) + if (nd.parent() != null) { - node.height = ((SequenceNode) node.parent()).height + node.dist; + nd.height = ((SequenceNode) nd.parent()).height + nd.dist; } else { maxheight = 0; - node.height = (float) 0.0; + nd.height = (float) 0.0; } - maxheight = findHeight((SequenceNode) (node.left())); - maxheight = findHeight((SequenceNode) (node.right())); + maxheight = findHeight((SequenceNode) (nd.left())); + maxheight = findHeight((SequenceNode) (nd.right())); } return maxheight; @@ -1078,43 +1091,43 @@ public class NJTree /** * DOCUMENT ME! * - * @param node + * @param nd * DOCUMENT ME! */ - public void printN(SequenceNode node) + public void printN(SequenceNode nd) { - if (node == null) + if (nd == null) { return; } - if ((node.left() != null) && (node.right() != null)) + if ((nd.left() != null) && (nd.right() != null)) { - printN((SequenceNode) node.left()); - printN((SequenceNode) node.right()); + printN((SequenceNode) nd.left()); + printN((SequenceNode) nd.right()); } else { System.out.println(" name = " - + ((SequenceI) node.element()).getName()); + + ((SequenceI) nd.element()).getName()); } - System.out.println(" dist = " + node.dist + " " + node.count + " " - + node.height); + System.out.println(" dist = " + nd.dist + " " + nd.count + " " + + nd.height); } /** * DOCUMENT ME! * - * @param node + * @param nd * DOCUMENT ME! */ - public void reCount(SequenceNode node) + public void reCount(SequenceNode nd) { ycount = 0; _lycount = 0; // _lylimit = this.node.size(); - _reCount(node); + _reCount(nd); } private long _lycount = 0, _lylimit = 0; @@ -1122,37 +1135,37 @@ public class NJTree /** * DOCUMENT ME! * - * @param node + * @param nd * DOCUMENT ME! */ - public void _reCount(SequenceNode node) + public void _reCount(SequenceNode nd) { // if (_lycount<_lylimit) // { // System.err.println("Warning: depth of _recount greater than number of nodes."); // } - if (node == null) + if (nd == null) { return; } _lycount++; - if ((node.left() != null) && (node.right() != null)) + if ((nd.left() != null) && (nd.right() != null)) { - _reCount((SequenceNode) node.left()); - _reCount((SequenceNode) node.right()); + _reCount((SequenceNode) nd.left()); + _reCount((SequenceNode) nd.right()); - SequenceNode l = (SequenceNode) node.left(); - SequenceNode r = (SequenceNode) node.right(); + SequenceNode l = (SequenceNode) nd.left(); + SequenceNode r = (SequenceNode) nd.right(); - node.count = l.count + r.count; - node.ycount = (l.ycount + r.ycount) / 2; + nd.count = l.count + r.count; + nd.ycount = (l.ycount + r.ycount) / 2; } else { - node.count = 1; - node.ycount = ycount++; + nd.count = 1; + nd.ycount = ycount++; } _lycount--; } @@ -1160,80 +1173,80 @@ public class NJTree /** * DOCUMENT ME! * - * @param node + * @param nd * DOCUMENT ME! */ - public void swapNodes(SequenceNode node) + public void swapNodes(SequenceNode nd) { - if (node == null) + if (nd == null) { return; } - SequenceNode tmp = (SequenceNode) node.left(); + SequenceNode tmp = (SequenceNode) nd.left(); - node.setLeft(node.right()); - node.setRight(tmp); + nd.setLeft(nd.right()); + nd.setRight(tmp); } /** * DOCUMENT ME! * - * @param node + * @param nd * DOCUMENT ME! * @param dir * DOCUMENT ME! */ - public void changeDirection(SequenceNode node, SequenceNode dir) + public void changeDirection(SequenceNode nd, SequenceNode dir) { - if (node == null) + if (nd == null) { return; } - if (node.parent() != top) + if (nd.parent() != top) { - changeDirection((SequenceNode) node.parent(), node); + changeDirection((SequenceNode) nd.parent(), nd); - SequenceNode tmp = (SequenceNode) node.parent(); + SequenceNode tmp = (SequenceNode) nd.parent(); - if (dir == node.left()) + if (dir == nd.left()) { - node.setParent(dir); - node.setLeft(tmp); + nd.setParent(dir); + nd.setLeft(tmp); } - else if (dir == node.right()) + else if (dir == nd.right()) { - node.setParent(dir); - node.setRight(tmp); + nd.setParent(dir); + nd.setRight(tmp); } } else { - if (dir == node.left()) + if (dir == nd.left()) { - node.setParent(node.left()); + nd.setParent(nd.left()); - if (top.left() == node) + if (top.left() == nd) { - node.setRight(top.right()); + nd.setRight(top.right()); } else { - node.setRight(top.left()); + nd.setRight(top.left()); } } else { - node.setParent(node.right()); + nd.setParent(nd.right()); - if (top.left() == node) + if (top.left() == nd) { - node.setLeft(top.right()); + nd.setLeft(top.right()); } else { - node.setLeft(top.left()); + nd.setLeft(top.left()); } } } @@ -1289,8 +1302,9 @@ public class NJTree */ public void applyToNodes(NodeTransformI nodeTransformI) { - for (Enumeration nodes = node.elements(); nodes.hasMoreElements(); nodeTransformI - .transform((BinaryNode) nodes.nextElement())) + for (Enumeration nodes = node.elements(); nodes + .hasMoreElements(); nodeTransformI + .transform(nodes.nextElement())) { ; } diff --git a/src/jalview/appletgui/TreeCanvas.java b/src/jalview/appletgui/TreeCanvas.java index edcd961..c8f526c 100755 --- a/src/jalview/appletgui/TreeCanvas.java +++ b/src/jalview/appletgui/TreeCanvas.java @@ -122,13 +122,13 @@ public class TreeCanvas extends Panel implements MouseListener, tree.findHeight(tree.getTopNode()); // Now have to calculate longest name based on the leaves - Vector leaves = tree.findLeaves(tree.getTopNode(), new Vector()); + Vector leaves = tree.findLeaves(tree.getTopNode()); boolean has_placeholders = false; longestName = ""; for (int i = 0; i < leaves.size(); i++) { - SequenceNode lf = (SequenceNode) leaves.elementAt(i); + SequenceNode lf = leaves.elementAt(i); if (lf.isPlaceholder()) { @@ -525,12 +525,11 @@ public class TreeCanvas extends Panel implements MouseListener, } else { - Vector leaves = new Vector(); - tree.findLeaves(highlightNode, leaves); + Vector leaves = tree.findLeaves(highlightNode); for (int i = 0; i < leaves.size(); i++) { - SequenceI seq = (SequenceI) ((SequenceNode) leaves.elementAt(i)) + SequenceI seq = (SequenceI) leaves.elementAt(i) .element(); treeSelectionChanged(seq); } @@ -630,13 +629,13 @@ public class TreeCanvas extends Panel implements MouseListener, (int) (Math.random() * 255), (int) (Math.random() * 255)); setColor((SequenceNode) tree.getGroups().elementAt(i), col.brighter()); - Vector l = tree.findLeaves( - (SequenceNode) tree.getGroups().elementAt(i), new Vector()); + Vector l = tree.findLeaves((SequenceNode) tree + .getGroups().elementAt(i)); - Vector sequences = new Vector(); + Vector sequences = new Vector(); for (int j = 0; j < l.size(); j++) { - SequenceI s1 = (SequenceI) ((SequenceNode) l.elementAt(j)) + SequenceI s1 = (SequenceI) l.elementAt(j) .element(); if (!sequences.contains(s1)) { diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 08e5116..4f791f1 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -26,6 +26,7 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.io.SequenceAnnotationReport; import jalview.util.MessageManager; +import jalview.util.Platform; import jalview.util.UrlLink; import jalview.viewmodel.AlignmentViewport; @@ -327,7 +328,7 @@ public class IdPanel extends JPanel implements MouseListener, * (where isPopupTrigger() will answer true) * NB isRightMouseButton is also true for Cmd-click on Mac */ - if (SwingUtilities.isRightMouseButton(e)) + if (SwingUtilities.isRightMouseButton(e) && !Platform.isAMac()) { return; } diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 254d032..279d9ad 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -175,13 +175,13 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, tree.findHeight(tree.getTopNode()); // Now have to calculate longest name based on the leaves - Vector leaves = tree.findLeaves(tree.getTopNode(), new Vector()); + Vector leaves = tree.findLeaves(tree.getTopNode()); boolean has_placeholders = false; longestName = ""; for (int i = 0; i < leaves.size(); i++) { - SequenceNode lf = (SequenceNode) leaves.elementAt(i); + SequenceNode lf = leaves.elementAt(i); if (lf.isPlaceholder()) { @@ -748,10 +748,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } /** - * DOCUMENT ME! + * Empty method to satisfy the MouseListener interface * * @param e - * DOCUMENT ME! */ @Override public void mouseReleased(MouseEvent e) @@ -759,10 +758,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } /** - * DOCUMENT ME! + * Empty method to satisfy the MouseListener interface * * @param e - * DOCUMENT ME! */ @Override public void mouseEntered(MouseEvent e) @@ -770,10 +768,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } /** - * DOCUMENT ME! + * Empty method to satisfy the MouseListener interface * * @param e - * DOCUMENT ME! */ @Override public void mouseExited(MouseEvent e) @@ -781,10 +778,11 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } /** - * DOCUMENT ME! + * Handles a mouse click on a tree node (clicks elsewhere are handled in + * mousePressed). Click selects the sub-tree, double-click swaps leaf nodes + * order, right-click opens a dialogue to choose colour for the sub-tree. * * @param e - * DOCUMENT ME! */ @Override public void mouseClicked(MouseEvent evt) @@ -810,12 +808,11 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } else { - Vector leaves = new Vector(); - tree.findLeaves(highlightNode, leaves); + Vector leaves = tree.findLeaves(highlightNode); for (int i = 0; i < leaves.size(); i++) { - SequenceI seq = (SequenceI) ((SequenceNode) leaves.elementAt(i)) + SequenceI seq = (SequenceI) leaves.elementAt(i) .element(); treeSelectionChanged(seq); } @@ -876,10 +873,12 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } /** - * DOCUMENT ME! + * Handles a mouse press on a sequence name or the tree background canvas + * (click on a node is handled in mouseClicked). The action is to create + * groups by partitioning the tree at the mouse position. Colours for the + * groups (and sequence names) are generated randomly. * * @param e - * DOCUMENT ME! */ @Override public void mousePressed(MouseEvent e) @@ -901,8 +900,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, /* * defer right-click handling on Windows to - * mouseClicked; this also matches Cmd-click on Mac - * which should do nothing here + * mouseClicked; note isRightMouseButton + * also matches Cmd-click on Mac which should do + * nothing here */ if (SwingUtilities.isRightMouseButton(e)) { @@ -969,14 +969,14 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, (int) (Math.random() * 255), (int) (Math.random() * 255)); setColor((SequenceNode) tree.getGroups().elementAt(i), col.brighter()); - Vector l = tree.findLeaves( - (SequenceNode) tree.getGroups().elementAt(i), new Vector()); + Vector l = tree.findLeaves((SequenceNode) tree + .getGroups().elementAt(i)); - Vector sequences = new Vector(); + Vector sequences = new Vector(); for (int j = 0; j < l.size(); j++) { - SequenceI s1 = (SequenceI) ((SequenceNode) l.elementAt(j)) + SequenceI s1 = (SequenceI) l.elementAt(j) .element(); if (!sequences.contains(s1)) diff --git a/src/jalview/io/vamsas/Tree.java b/src/jalview/io/vamsas/Tree.java index 0bf4096..a3781a7 100644 --- a/src/jalview/io/vamsas/Tree.java +++ b/src/jalview/io/vamsas/Tree.java @@ -291,8 +291,10 @@ public class Tree extends DatastoreItem } } if (alsq.size() < sequences.length) + { Cache.log .warn("Not recovered all alignment sequences for given set of input sequence CIGARS"); + } return alsq; } @@ -306,15 +308,18 @@ public class Tree extends DatastoreItem public void UpdateSequenceTreeMap(TreePanel tp) { if (tp == null || tree == null) + { return; - Vector leaves = new Vector(); + } + if (tp.getTree() == null) { Cache.log.warn("Not updating SequenceTreeMap for " + tree.getVorbaId()); return; } - tp.getTree().findLeaves(tp.getTree().getTopNode(), leaves); + Vector leaves = tp.getTree().findLeaves( + tp.getTree().getTopNode()); Treenode[] tn = tree.getTreenode(); // todo: select nodes for this // particular tree int sz = tn.length; @@ -371,8 +376,7 @@ public class Tree extends DatastoreItem */ public Treenode[] makeTreeNodes(NJTree ntree, Newick newick) { - Vector leaves = new Vector(); - ntree.findLeaves(ntree.getTopNode(), leaves); + Vector leaves = ntree.findLeaves(ntree.getTopNode()); Vector tnv = new Vector(); Enumeration l = leaves.elements(); Hashtable nodespecs = new Hashtable(); @@ -473,7 +477,9 @@ public class Tree extends DatastoreItem --occurence; } else + { bn = null; + } } return bn; } diff --git a/test/jalview/io/NewickFileTests.java b/test/jalview/io/NewickFileTests.java index f89f58b..4de36f2 100644 --- a/test/jalview/io/NewickFileTests.java +++ b/test/jalview/io/NewickFileTests.java @@ -116,24 +116,23 @@ public class NewickFileTests AssertJUnit.assertTrue(stage + "Null Tree", tree_regen != null); stage = "Compare original and generated tree" + treename; - Vector oseqs, nseqs; - oseqs = new NJTree(new SequenceI[0], nf).findLeaves(nf.getTree(), - new Vector()); + Vector oseqs, nseqs; + oseqs = new NJTree(new SequenceI[0], nf).findLeaves(nf.getTree()); AssertJUnit.assertTrue(stage + "No nodes in original tree.", oseqs.size() > 0); SequenceI[] olsqs = new SequenceI[oseqs.size()]; for (int i = 0, iSize = oseqs.size(); i < iSize; i++) { - olsqs[i] = (SequenceI) ((SequenceNode) oseqs.get(i)).element(); + olsqs[i] = (SequenceI) oseqs.get(i).element(); } - nseqs = new NJTree(new SequenceI[0], nf_regen).findLeaves( - nf_regen.getTree(), new Vector()); + nseqs = new NJTree(new SequenceI[0], nf_regen).findLeaves(nf_regen + .getTree()); AssertJUnit.assertTrue(stage + "No nodes in regerated tree.", nseqs.size() > 0); SequenceI[] nsqs = new SequenceI[nseqs.size()]; for (int i = 0, iSize = nseqs.size(); i < iSize; i++) { - nsqs[i] = (SequenceI) ((SequenceNode) nseqs.get(i)).element(); + nsqs[i] = (SequenceI) nseqs.get(i).element(); } AssertJUnit.assertTrue(stage + " Different number of leaves (original " + olsqs.length