JAL-2844 entirely X coord based partitioning
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Wed, 29 Nov 2017 17:32:12 +0000 (17:32 +0000)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Wed, 29 Nov 2017 17:37:43 +0000 (17:37 +0000)
src/jalview/ext/archaeopteryx/AptxInit.java
src/jalview/ext/archaeopteryx/JalviewBinding.java

index 9f2817e..805cc6c 100644 (file)
@@ -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
index 2bacfd5..1649b62 100644 (file)
@@ -66,6 +66,10 @@ public final class JalviewBinding
 
   private Map<PhylogenyNode, SequenceI> 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<PhylogenyNode> foundNodes = getNodesAboveThreshold(threshold,
-                longestBranch, tree.getRoot());
+                tree.getRoot());
 
       }
     }
@@ -266,7 +285,7 @@ public final class JalviewBinding
   }
 
   public List<PhylogenyNode> getNodesAboveThreshold(double threshold,
-          double treeLength, PhylogenyNode node)
+          PhylogenyNode node)
   {
 
     List<PhylogenyNode> 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<PhylogenyNode> colourNodesAboveThreshold(
           List<PhylogenyNode> 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<PhylogenyNode> descendantNodes = childNode
                 .getAllExternalDescendants();
-        List<SequenceI> descendantSeqs = new ArrayList<>();
+        List<SequenceI> 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;
   }