From: kjvdheide Date: Wed, 29 Nov 2017 17:32:12 +0000 (+0000) Subject: JAL-2844 entirely X coord based partitioning X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=de0c463592a20857cbb40b3262cde84fd90b3b14;p=jalview.git JAL-2844 entirely X coord based partitioning --- diff --git a/src/jalview/ext/archaeopteryx/AptxInit.java b/src/jalview/ext/archaeopteryx/AptxInit.java index 9f2817e..805cc6c 100644 --- a/src/jalview/ext/archaeopteryx/AptxInit.java +++ b/src/jalview/ext/archaeopteryx/AptxInit.java @@ -184,7 +184,7 @@ public final class AptxInit } /** - * Refactored from Forester's UrlTreeReader + * Refactored from Forester's UrlTreeReader, this can be more efficient * * @param databaseIndex * @param viewport diff --git a/src/jalview/ext/archaeopteryx/JalviewBinding.java b/src/jalview/ext/archaeopteryx/JalviewBinding.java index 2bacfd5..1649b62 100644 --- a/src/jalview/ext/archaeopteryx/JalviewBinding.java +++ b/src/jalview/ext/archaeopteryx/JalviewBinding.java @@ -66,6 +66,10 @@ public final class JalviewBinding private Map nodesBoundToSequences; + private float rootX; + + private float furthestNodeX; + /** * * @param archaeopteryx @@ -224,11 +228,21 @@ public final class JalviewBinding if (matchingNode != null) { treeView.getFoundNodes0().add(matchingNode.getId()); + + + if (!matchingNode.getBranchData().isHasBranchColor()) + { + Color foundNodesColour = treeView.getTreeColorSet() + .getFoundColor0(); + matchingNode.getBranchData() + .setBranchColor(new BranchColor(foundNodesColour)); + + } + } } - treeView.repaint(); } @@ -244,20 +258,25 @@ public final class JalviewBinding if (!tree.isEmpty()) { - double longestBranch = tree.calculateHeight(true); - if (longestBranch != 0) + // should be calculated on each partition as the tree can theoretically + // change in the meantime + PhylogenyNode furthestNode = PhylogenyMethods + .calculateNodeWithMaxDistanceToRoot(tree); + furthestNodeX = furthestNode.getXcoord(); + rootX = tree.getRoot().getXcoord(); + + if (furthestNodeX != rootX && x < furthestNodeX) // don't bother if 0 + // distance tree or + // clicked x lies outside + // of tree { - - // double relativeTreeWidth = longestBranch / viewWidth; - // MOVE Graphics g = treeView.getGraphics(); int panelHeight = treeView.getHeight(); g.drawLine(x, 0, x, panelHeight); - float rootX = tree.getRoot().getXcoord(); - double threshold = ((double) x - rootX) / longestBranch; + float threshold = (x - rootX) / (furthestNodeX - rootX); List foundNodes = getNodesAboveThreshold(threshold, - longestBranch, tree.getRoot()); + tree.getRoot()); } } @@ -266,7 +285,7 @@ public final class JalviewBinding } public List getNodesAboveThreshold(double threshold, - double treeLength, PhylogenyNode node) + PhylogenyNode node) { List nodesAboveThreshold = new ArrayList<>(); @@ -282,7 +301,7 @@ public final class JalviewBinding } - colourNodesAboveThreshold(nodesAboveThreshold, threshold, treeLength, + colourNodesAboveThreshold(nodesAboveThreshold, threshold, node); return nodesAboveThreshold; @@ -299,14 +318,15 @@ public final class JalviewBinding */ private List colourNodesAboveThreshold( List nodeList, double threshold, - double treeLength, PhylogenyNode node) + PhylogenyNode node) { // could also use PhylogenyMethods.getAllDescendants for (PhylogenyNode childNode : node.getDescendants()) { childNode.getBranchData() .setBranchColor(new BranchColor(Color.black)); - double nodeCutoff = childNode.calculateDistanceToRoot() / treeLength; + float nodeCutoff = (childNode.getXcoord() - rootX) + / (furthestNodeX - rootX); if (nodeCutoff > threshold) { @@ -316,16 +336,14 @@ public final class JalviewBinding (int) (Math.random() * 255), (int) (Math.random() * 255)); TreePanelUtil.colorizeSubtree(childNode, new BranchColor(randomColor)); - List descendantNodes = childNode .getAllExternalDescendants(); - List descendantSeqs = new ArrayList<>(); + List descendantSeqs = new ArrayList<>(); // .forEach instead? for (PhylogenyNode descNode : descendantNodes) { descendantSeqs.add(nodesBoundToSequences.get(descNode)); } - SequenceGroup sg = new SequenceGroup(descendantSeqs, null, null, true, true, false, 0, parentAvport.getAlignment().getWidth() - 1); @@ -338,7 +356,6 @@ public final class JalviewBinding cs = new UserColourScheme( ((UserColourScheme) parentAvport.getGlobalColourScheme()) .getColours()); - } else { @@ -386,13 +403,14 @@ public final class JalviewBinding } + else { - colourNodesAboveThreshold(nodeList, threshold, treeLength, + colourNodesAboveThreshold(nodeList, threshold, childNode); } - } + // GROSS ((AlignViewport) parentAvport).getAlignPanel().updateAnnotation(); @@ -403,7 +421,6 @@ public final class JalviewBinding ((AlignViewport) codingComplement).getAlignPanel().updateAnnotation(); } - return nodeList; }