JAL-2844 first go at partitioning, based on actual tree width
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Tue, 28 Nov 2017 17:31:28 +0000 (17:31 +0000)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Tue, 28 Nov 2017 17:31:28 +0000 (17:31 +0000)
src/jalview/ext/archaeopteryx/AptxInit.java
src/jalview/ext/archaeopteryx/JalviewBinding.java

index 81bf4fb..732e85a 100644 (file)
@@ -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,
index 95c07ef..e382364 100644 (file)
@@ -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<PhylogenyNode> foundNodes = getNodesAboveThreshold(threshold,
+                longestBranch, tree.getRoot());
+        for (PhylogenyNode foundNode : foundNodes)
+        {
+          System.out.println(foundNode);
+        }
+
+        // groupNodes(threshold, tree.getRoot(), longestBranch);
+
+
+
 
       }
     }
 
 
   }
-  
+
+  public List<PhylogenyNode> getNodesAboveThreshold(double threshold,
+          double treeLength, PhylogenyNode node)
+  {
+
+    List<PhylogenyNode> nodesAboveThreshold = new ArrayList<>();
+
+    iterateNodesAboveThreshold(nodesAboveThreshold, threshold, treeLength,
+            node);
+    return nodesAboveThreshold;
+
+  }
+
+  private List<PhylogenyNode> iterateNodesAboveThreshold(
+          List<PhylogenyNode> 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<PhylogenyNode> groupNodes(float threshold, PhylogenyNode root,
+  // double treeHeight)
+  // {
+  // List<PhylogenyNode> groups = new ArrayList<>();
+  // _groupNodes(groups, root, threshold, treeHeight);
+  // System.out.println(groups);
+  // return groups;
+  // }
+  //
+  // protected void _groupNodes(List<PhylogenyNode> 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