JAL-4386 annotate internal nodes either side of partition with the set of labels...
authorJim Procter <jprocter@dundee.ac.uk>
Fri, 28 Jun 2024 16:03:51 +0000 (17:03 +0100)
committerJim Procter <jprocter@dundee.ac.uk>
Fri, 28 Jun 2024 16:03:51 +0000 (17:03 +0100)
src/jalview/gui/TreeCanvas.java

index 993d563..05c33c6 100755 (executable)
@@ -40,6 +40,7 @@ import java.util.ArrayList;
 import java.util.BitSet;
 import java.util.HashMap;
 import java.util.Hashtable;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -1073,9 +1074,10 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
       setColor(groups.get(i), col.brighter());
 
       Vector<BinaryNode> l = tree.findLeaves(groups.get(i));
+      gatherLabelsTo(groups.get(i),l);
       if (!tp.isColumnWise())
       {
-        createSeqGroupFor(aps, l, col);
+        createSeqGroupFor(aps, l, col);        
       }
       else
       {
@@ -1118,6 +1120,29 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
     }
   }
 
+  private void gatherLabelsTo(BinaryNode binaryNode, Vector<BinaryNode> l)
+  {
+    LinkedHashSet<String> labelsForNode = new LinkedHashSet<String>();
+    for (BinaryNode leaf:l)
+    {
+      if (leaf.hasLabel())
+      {
+        labelsForNode.add(leaf.getLabel());
+      }
+    }
+    StringBuilder sb = new StringBuilder();
+    boolean first=true;
+    for (String label:labelsForNode)
+    {
+      if (!first) {
+        sb.append(" | ");
+      }
+      first=false;
+      sb.append(label);
+    }
+    binaryNode.setLabel(sb.toString());
+  }
+
   private int parseColumnNode(BinaryNode bn) throws NumberFormatException
   {
     return Integer.parseInt(