From 3d860d173dda8b7f8e0527c4a19da16aef4c804d Mon Sep 17 00:00:00 2001 From: kjvdheide Date: Tue, 28 Nov 2017 17:31:28 +0000 Subject: [PATCH] JAL-2844 first go at partitioning, based on actual tree width --- src/jalview/ext/archaeopteryx/AptxInit.java | 7 ++ src/jalview/ext/archaeopteryx/JalviewBinding.java | 98 +++++++++++++++++++-- 2 files changed, 98 insertions(+), 7 deletions(-) diff --git a/src/jalview/ext/archaeopteryx/AptxInit.java b/src/jalview/ext/archaeopteryx/AptxInit.java index 81bf4fb..732e85a 100644 --- a/src/jalview/ext/archaeopteryx/AptxInit.java +++ b/src/jalview/ext/archaeopteryx/AptxInit.java @@ -471,6 +471,7 @@ public final class AptxInit { MainFrame aptxApp = Archaeopteryx.createApplication(aptxTree, APTX_CONFIG, treeTitle); + // addPartitioningSlider(aptxApp); LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation( jalviewAlignport.getAlignment().getSequencesArray(), aptxTree); @@ -482,6 +483,12 @@ public final class AptxInit return aptxApp; } + // private static void addPartitioningSlider(MainFrame aptxFrame) + // { + // JSlider slider = new JSlider(); + // + // + // } public static ExternalTreeViewerBindingI bindNodesToJalviewSequences( final MainFrame aptxApp, diff --git a/src/jalview/ext/archaeopteryx/JalviewBinding.java b/src/jalview/ext/archaeopteryx/JalviewBinding.java index 95c07ef..e382364 100644 --- a/src/jalview/ext/archaeopteryx/JalviewBinding.java +++ b/src/jalview/ext/archaeopteryx/JalviewBinding.java @@ -17,6 +17,7 @@ import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.InputEvent; import java.awt.event.MouseEvent; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -98,6 +99,7 @@ public final class JalviewBinding treeView.addMouseListener(this); PaintRefresher.Register(treeView, parentAvport.getSequenceSetId()); + treeTabs.addChangeListener(new ChangeListener() { @@ -162,9 +164,7 @@ public final class JalviewBinding else { partitionTree(e.getX()); - } - PaintRefresher.Refresh(treeView, parentAvport.getSequenceSetId()); } }); @@ -229,22 +229,106 @@ public final class JalviewBinding if (!tree.isEmpty()) { - double treeDepth = tree.calculateHeight(true); - if (treeDepth != 0) + double longestBranch = tree.calculateHeight(true); + if (longestBranch != 0) { Graphics g = treeView.getGraphics(); int panelHeight = treeView.getHeight(); + int viewWidth = treeView.getWidth(); g.drawLine(x, 0, x, panelHeight); - int viewWidth = treeView.getWidth(); - float threshold = (float) x / (float) viewWidth; + // double relativeTreeWidth = treeDepth / viewWidth; + // + // System.out.println(relativeTreeWidth); + + double threshold = x / longestBranch; + System.out.println(threshold); + List foundNodes = getNodesAboveThreshold(threshold, + longestBranch, tree.getRoot()); + for (PhylogenyNode foundNode : foundNodes) + { + System.out.println(foundNode); + } + + // groupNodes(threshold, tree.getRoot(), longestBranch); + + + } } } - + + public List getNodesAboveThreshold(double threshold, + double treeLength, PhylogenyNode node) + { + + List nodesAboveThreshold = new ArrayList<>(); + + iterateNodesAboveThreshold(nodesAboveThreshold, threshold, treeLength, + node); + return nodesAboveThreshold; + + } + + private List iterateNodesAboveThreshold( + List nodeList, double threshold, + double treeLength, PhylogenyNode node) + { + for (PhylogenyNode childNode : node.getDescendants()) + { + double nodeCutoff = childNode.calculateDistanceToRoot() / treeLength; + + if (nodeCutoff > threshold) + { + nodeList.add(node); + } + + else + { + iterateNodesAboveThreshold(nodeList, threshold, treeLength, + childNode); + } + + } + return nodeList; + } + + + + // public List groupNodes(float threshold, PhylogenyNode root, + // double treeHeight) + // { + // List groups = new ArrayList<>(); + // _groupNodes(groups, root, threshold, treeHeight); + // System.out.println(groups); + // return groups; + // } + // + // protected void _groupNodes(List groups, PhylogenyNode nd, + // float threshold, double treeHeight) + // { + // if (nd == null) + // { + // return; + // } + // + // if ((nd.calculateDistanceToRoot() / treeHeight) > threshold) + // { + // groups.add(nd); + // } + // else + // { + // for (PhylogenyNode childNode : nd.getDescendants()) + // { + // _groupNodes(groups, childNode, threshold, treeHeight); + // } + // } + // } + // + /** * may or may not need an extra repaint on the alignment view (check what kira -- 1.7.10.2