JAL-2874 added filtering when a subtree is selected
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Tue, 12 Dec 2017 18:03:37 +0000 (18:03 +0000)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Tue, 12 Dec 2017 18:03:45 +0000 (18:03 +0000)
src/jalview/ext/archaeopteryx/AptxInit.java
src/jalview/ext/archaeopteryx/JalviewBinding.java
src/jalview/ext/archaeopteryx/LoadedTreeSequenceAssociation.java

index 6fcc37c..9d248d0 100644 (file)
@@ -496,7 +496,7 @@ public final class AptxInit
     MainFrame aptxApp = Archaeopteryx.createApplication(aptxTree,
             APTX_CONFIG, treeTitle);
 
-    adaptAptxGui(aptxApp);
+
     LoadedTreeSequenceAssociation bindAptxNodes = new LoadedTreeSequenceAssociation(
             jalviewAlignport.getAlignment().getSequencesArray(), aptxTree);
     bindAptxNodes.associateLeavesToSequences();
@@ -506,6 +506,7 @@ public final class AptxInit
             bindAptxNodes.getNodesWithAlignment());
     bindTreeViewFrameToJalview(aptxApp);
 
+    adaptAptxGui(aptxApp);
     return aptxApp;
   }
 
@@ -593,9 +594,21 @@ public final class AptxInit
       {
         menu.addSeparator();
         JMenuItem sortByTree = new JMenuItem("Sort alignment by tree");
+        JMenuItem refreshJalview = new JMenuItem(
+                "Filter alignment to show only currently visible sequences");
+
+        refreshJalview.setFont(menu.getFont());
+
         menu.add(sortByTree);
+        menu.add(refreshJalview);
+
+        sortByTree.setFont(menu.getFont());
         sortByTree.setVisible(false); // don't show unless it's actually
-                                      // possible
+        // possible
+
+        refreshJalview.addActionListener(activeAptx.get(aptxFrame));
+
+
       }
 
     }
index 6969821..11aab2b 100644 (file)
@@ -177,7 +177,28 @@ public final class JalviewBinding
   @Override
   public void actionPerformed(ActionEvent e)
   {
-    // aptxFrame.actionPerformed(e);
+    if (treeView.isCurrentTreeIsSubtree())
+    {
+    LoadedTreeSequenceAssociation bindAptxNodes = new LoadedTreeSequenceAssociation(
+            parentAvport.getAlignment().getSequencesArray(),
+            treeView.getPhylogeny());
+    bindAptxNodes.associateLeavesToSequences();
+    sequencesBoundToNodes = bindAptxNodes.getAlignmentWithNodes();
+    nodesBoundToSequences = bindAptxNodes.getNodesWithAlignment();
+    AptxInit.bindNodesToJalviewSequences(aptxFrame, parentAvport,
+            sequencesBoundToNodes, nodesBoundToSequences);
+
+
+    for (SequenceI seq : parentAvport.getAlignment().getSequencesArray())
+    {
+      if (!sequencesBoundToNodes.containsKey(seq))
+      {
+        parentAvport.hideSequence(new SequenceI[] { seq });
+      }
+      }
+    }
+
+
 
   }
 
@@ -192,6 +213,8 @@ public final class JalviewBinding
        */
       public void run()
       {
+
+
         final PhylogenyNode node = treeView.findNode(e.getX(), e.getY());
         if (node != null)
         {
@@ -203,11 +226,12 @@ public final class JalviewBinding
 
           }
           showNodeSelectionOnAlign(node);
+
         }
         else
         {
-
           partitionTree(e.getX());
+
       }
         PaintRefresher.Refresh(treeView, parentAvport.getSequenceSetId());
         treeView.repaint();
@@ -296,6 +320,7 @@ public final class JalviewBinding
       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))
       {
index 86f27d1..0c83036 100644 (file)
@@ -16,13 +16,13 @@ import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
 public class LoadedTreeSequenceAssociation
         implements ExternalLoadedTreeAssociationI
 {
-  SequenceI[] alignSequences;
+  private SequenceI[] alignSequences;
 
-  Phylogeny tree;
+  private Phylogeny tree;
 
-  Map<SequenceI, PhylogenyNode> alignmentWithNodes;
+  private Map<SequenceI, PhylogenyNode> alignmentWithNodes;
 
-  Map<PhylogenyNode, SequenceI> nodesWithAlignment;
+  private Map<PhylogenyNode, SequenceI> nodesWithAlignment;
 
   public LoadedTreeSequenceAssociation(SequenceI[] alignmentSequences,
           Phylogeny aptxTree)