+ if (!tree.isEmpty())
+ {
+ // should be calculated on each partition as the tree can theoretically
+ // change in the meantime
+ TreeNodeI furthestNode = tree.getFurthestNode();
+ furthestNodeX = furthestNode.getXcoord();
+ rootX = tree.getRoot().getXcoord();
+
+ // don't bother if 0 distance tree or clicked x lies outside of tree
+ if (furthestNodeX != rootX && !(x > furthestNodeX))
+ {
+ float threshold = (x - rootX) / (furthestNodeX - rootX);
+ List<TreeNodeI> foundNodes = getNodesAboveThreshold(
+ threshold,
+ tree.getRoot());
+
+ }
+ }
+
+
+ }
+
+ public List<TreeNodeI> getNodesAboveThreshold(double threshold,
+ TreeNodeI node)
+ {
+
+ List<TreeNodeI> nodesAboveThreshold = new ArrayList<>();
+
+ parentAvport.setSelectionGroup(null);
+ parentAvport.getAlignment().deleteAllGroups();
+ parentAvport.clearSequenceColours();
+ if (parentAvport.getCodingComplement() != null)
+ {
+ parentAvport.getCodingComplement().setSelectionGroup(null);
+ parentAvport.getCodingComplement().getAlignment().deleteAllGroups();
+ parentAvport.getCodingComplement().clearSequenceColours();
+ }
+
+
+ colourNodesAboveThreshold(nodesAboveThreshold, threshold,
+ node);
+ return nodesAboveThreshold;
+
+ }
+
+ /**
+ * Partially refactored from TreeCanvas colourGroups (can be made nicer).
+ *
+ * @param nodeList
+ * @param threshold
+ * @param treeLength
+ * @param node
+ * @return
+ */
+ private List<TreeNodeI> colourNodesAboveThreshold(
+ List<TreeNodeI> nodeList, double threshold,
+ TreeNodeI node)
+ {
+
+ for (TreeNodeI childNode : node.getDirectChildren())
+ {
+ childNode.setBranchColor(Color.black);
+ float nodeCutoff = (childNode.getXcoord() - rootX)
+ / (furthestNodeX - rootX);
+
+ if (nodeCutoff > threshold)
+ {
+ nodeList.add(childNode);
+
+ Color randomColour = new Color((int) (Math.random() * 255),
+ (int) (Math.random() * 255), (int) (Math.random() * 255));
+ childNode.setBranchColor(randomColour);
+
+ List<SequenceI> groupSeqs = new ArrayList<>();
+ SequenceI seq = nodesBoundToSequences.get(childNode);
+ if (seq != null)
+ {
+ groupSeqs.add(seq);
+ parentAvport.setSequenceColour(seq, randomColour);
+ }
+
+ List<TreeNodeI> descendantNodes = childNode
+ .getAllDescendants();
+ // .forEach instead?
+ for (TreeNodeI descNode : descendantNodes)
+ {
+ seq = nodesBoundToSequences.get(descNode);
+ if (seq != null)
+ {
+ groupSeqs.add(seq);
+ parentAvport.setSequenceColour(seq, randomColour);
+ }
+
+ descNode.setBranchColor(randomColour);
+ }
+
+ if (groupSeqs != null)
+ {
+ nrTreeGroups++;
+ groupThresholdSequences(groupSeqs, randomColour);
+ }}
+
+ else
+ {
+ colourNodesAboveThreshold(nodeList, threshold, childNode);
+ }
+ }
+
+
+ for (AlignmentPanel associatedPanel : associatedPanels) {
+
+ associatedPanel.updateAnnotation();
+
+ final AlignViewportI codingComplement = associatedPanel.getAlignViewport()
+ .getCodingComplement();
+ if (codingComplement != null)
+ {
+ // GROSS
+ ((AlignViewport) codingComplement).getAlignPanel()
+ .updateAnnotation();
+ }
+ }
+
+
+ return nodeList;
+ }
+
+ public void groupThresholdSequences(List<SequenceI> groupedSeqs,
+ Color groupColour)