JAL-2844 added grouping to alignment panel based on partition
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Wed, 29 Nov 2017 12:01:17 +0000 (12:01 +0000)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Wed, 29 Nov 2017 12:01:17 +0000 (12:01 +0000)
forester
src/jalview/ext/archaeopteryx/JalviewBinding.java
src/jalview/gui/AlignViewport.java

index b8121ed..9c3a223 160000 (submodule)
--- a/forester
+++ b/forester
@@ -1 +1 @@
-Subproject commit b8121ed04b4ec52eeb0361dd7417717a4c455d25
+Subproject commit 9c3a223ef0fd72affdb9f4e40845d1e3ebe52f90
index 66c348f..e339d15 100644 (file)
@@ -1,15 +1,22 @@
 package jalview.ext.archaeopteryx;
 
+import jalview.analysis.Conservation;
+import jalview.api.AlignViewportI;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.ext.treeviewer.ExternalTreeViewerBindingI;
+import jalview.gui.AlignViewport;
 import jalview.gui.Desktop;
 import jalview.gui.JvOptionPane;
 import jalview.gui.PaintRefresher;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemeProperty;
+import jalview.schemes.UserColourScheme;
 import jalview.structure.SelectionSource;
 import jalview.structure.StructureSelectionManager;
+import jalview.util.MappingUtils;
 import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
 
@@ -166,9 +173,11 @@ public final class JalviewBinding
         }
         else
         {
+
           partitionTree(e.getX());
       }
         PaintRefresher.Refresh(treeView, parentAvport.getSequenceSetId());
+        treeView.repaint();
       }
     });
 
@@ -216,7 +225,7 @@ public final class JalviewBinding
         }
 
       }
-      treeView.repaint();
+
 
     }
 
@@ -239,19 +248,14 @@ public final class JalviewBinding
         int panelHeight = treeView.getHeight();
         g.drawLine(x, 0, x, panelHeight);
 
-        // double relativeTreeWidth = treeDepth / viewWidth;
+        // double relativeTreeWidth = longestBranch / viewWidth;
 
         float rootX = tree.getRoot().getXcoord();
+
         double threshold = ((double) x - rootX) / longestBranch;
         List<PhylogenyNode> foundNodes = getNodesAboveThreshold(threshold,
                 longestBranch, tree.getRoot());
 
-
-
-
-
-
-
       }
     }
 
@@ -264,19 +268,41 @@ public final class JalviewBinding
 
     List<PhylogenyNode> nodesAboveThreshold = new ArrayList<>();
 
-    // could also use PhylogenyMethods.getAllDescendants
+    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, treeLength,
             node);
     return nodesAboveThreshold;
 
   }
 
+  /**
+   * Partially refactored from TreeCanvas colourGroups (can be made nicer).
+   * 
+   * @param nodeList
+   * @param threshold
+   * @param treeLength
+   * @param node
+   * @return
+   */
   private List<PhylogenyNode> colourNodesAboveThreshold(
           List<PhylogenyNode> nodeList, double threshold,
           double treeLength, PhylogenyNode node)
   {
+    // could also use PhylogenyMethods.getAllDescendants
     for (PhylogenyNode childNode : node.getDescendants())
     {
+      childNode.getBranchData()
+              .setBranchColor(new BranchColor(Color.black));
       double nodeCutoff = childNode.calculateDistanceToRoot() / treeLength;
 
       if (nodeCutoff > threshold)
@@ -287,6 +313,7 @@ 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<>();
@@ -295,13 +322,67 @@ public final class JalviewBinding
           descendantSeqs.add(nodesBoundToSequences.get(descNode));
         }
 
+
         SequenceGroup sg = new SequenceGroup(descendantSeqs, null, null,
                 true, true, false, 0,
                 parentAvport.getAlignment().getWidth() - 1);
+
+        ColourSchemeI cs = null;
+        if (parentAvport.getGlobalColourScheme() != null)
+        {
+          if (parentAvport.getGlobalColourScheme() instanceof UserColourScheme)
+          {
+            cs = new UserColourScheme(
+                    ((UserColourScheme) parentAvport.getGlobalColourScheme())
+                            .getColours());
+
+          }
+          else
+          {
+            cs = ColourSchemeProperty.getColourScheme(sg, ColourSchemeProperty
+                    .getColourName(parentAvport.getGlobalColourScheme()));
+          }
+        }
+        sg.setColourScheme(cs);
+        sg.getGroupColourScheme().setThreshold(
+                parentAvport.getResidueShading().getThreshold(),
+                parentAvport.isIgnoreGapsConsensus());
+        // sg.recalcConservation();
+        sg.setName("Tree Group:" + sg.hashCode());
         sg.setIdColour(randomColor);
 
-      }
+        if (parentAvport.getGlobalColourScheme() != null
+                && parentAvport.getResidueShading().conservationApplied())
+        {
+          Conservation c = new Conservation("Group", sg.getSequences(null),
+                  sg.getStartRes(), sg.getEndRes());
+          c.calculate();
+          c.verdict(false, parentAvport.getConsPercGaps());
+          sg.cs.setConservation(c);
+        }
+
+        parentAvport.getAlignment().addGroup(new SequenceGroup(sg));
+        // TODO can we push all of the below into AlignViewportI?
+        final AlignViewportI codingComplement = parentAvport
+                .getCodingComplement();
+        if (codingComplement != null)
+        {
+          SequenceGroup mappedGroup = MappingUtils.mapSequenceGroup(sg,
+                  parentAvport,
+                  codingComplement);
+          if (mappedGroup.getSequences().size() > 0)
+          {
+            codingComplement.getAlignment().addGroup(mappedGroup);
+            for (SequenceI seq : mappedGroup.getSequences())
+            {
+              codingComplement.setSequenceColour(seq,
+                      randomColor.brighter());
+            }
+          }
+        }
 
+
+      }
       else
       {
       colourNodesAboveThreshold(nodeList, threshold, treeLength,
@@ -309,6 +390,17 @@ public final class JalviewBinding
       }
 
     }
+    // GROSS
+    ((AlignViewport) parentAvport).getAlignPanel().updateAnnotation();
+
+    final AlignViewportI codingComplement = parentAvport
+            .getCodingComplement();
+    if (codingComplement != null)
+    {
+      ((AlignViewport) codingComplement).getAlignPanel().updateAnnotation();
+    }
+
+
     return nodeList;
   }
 
@@ -461,9 +553,9 @@ public final class JalviewBinding
   // for (AlignmentPanel ap : PaintRefresher
   // .getAssociatedPanels(parentAvport.getSequenceSetId()))
   // {
-  // commands.add(sortAlignmentIn(ap.av.getAlignPanel()));
+  // commands.add(sortAlignmentIn(ap.parentAvport.getAlignPanel()));
   // }
-  // av.getAlignPanel().alignFrame.addHistoryItem(new CommandI()
+  // parentAvport.getAlignPanel().alignFrame.addHistoryItem(new CommandI()
   // {
   //
   // @Override
@@ -498,7 +590,7 @@ public final class JalviewBinding
   // }
   // });
   // for (AlignmentPanel ap : PaintRefresher
-  // .getAssociatedPanels(av.getSequenceSetId()))
+  // .getAssociatedPanels(parentAvport.getSequenceSetId()))
   // {
   // // ensure all the alignFrames refresh their GI after adding an undo item
   // ap.alignFrame.updateEditMenuBar();
index 4d09084..c696765 100644 (file)
@@ -22,7 +22,6 @@ package jalview.gui;
 
 import jalview.analysis.AlignmentUtils;
 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
-import jalview.analysis.TreeModel;
 import jalview.api.AlignViewportI;
 import jalview.api.AlignmentViewPanel;
 import jalview.api.FeatureColourI;
@@ -36,7 +35,6 @@ import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.HiddenColumns;
-import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SearchResults;
 import jalview.datamodel.SearchResultsI;
 import jalview.datamodel.SequenceGroup;
@@ -58,10 +56,8 @@ import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.FontMetrics;
 import java.awt.Rectangle;
-import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.List;
-import java.util.Vector;
 
 import javax.swing.JInternalFrame;
 
@@ -545,7 +541,6 @@ public class AlignViewport extends AlignmentViewport
    * return the alignPanel containing the given viewport. Use this to get the
    * components currently handling the given viewport.
    * 
-   * @param av
    * @return null or an alignPanel guaranteed to have non-null alignFrame
    *         reference
    */
@@ -604,7 +599,7 @@ public class AlignViewport extends AlignmentViewport
     return validCharWidth;
   }
 
-  private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<String, AutoCalcSetting>();
+  private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<>();
 
   public AutoCalcSetting getCalcIdSettingsFor(String calcId)
   {