JAL-2805 Jalview sequence binding interface expanded
[jalview.git] / src / jalview / ext / archaeopteryx / ArchaeopteryxInit.java
index 9b654f0..bd7de87 100644 (file)
@@ -13,51 +13,59 @@ import org.forester.archaeopteryx.MainFrame;
 import org.forester.phylogeny.Phylogeny;
 import org.forester.phylogeny.PhylogenyNode;
 
+/**
+ * Static class for creating Archaeopteryx tree viewer instances from calculated
+ * trees and letting them be bound to Jalview.
+ * 
+ * @author kjvanderheide
+ *
+ */
 public final class ArchaeopteryxInit
 {
   /**
-   * This method should generally not be used as it does not bind the tree to
+   * Test method, should generally not be used as it does not bind the tree to
    * its alignment
    * 
    * @param aptxTrees
    * @return
    */
-  public static MainFrame createUnboundInstance(Phylogeny aptxTree)
+  public static MainFrame createUnboundInstance(final Phylogeny aptxTree)
   {
     Phylogeny[] aptxTrees = { aptxTree };
-    return createBoundAptxFrame(aptxTrees, null);
+    return createAptxFrame(aptxTrees);
   }
 
-  public static MainFrame createInstance(Phylogeny[] aptxTrees,
-          AlignmentViewport jalviewAlignmentView)
-  {
-    return createBoundAptxFrame(aptxTrees, jalviewAlignmentView);
-
-  }
-
-  public static MainFrame createInstance(Phylogeny aptxTree,
-          AlignmentViewport jalviewAlignmentView)
-  {
-    Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in
-    // several trees simultaneously
-    return createBoundAptxFrame(aptxTrees, jalviewAlignmentView);
-
-  }
+  // public static MainFrame createInstance(final Phylogeny[] aptxTrees,
+  // AlignmentViewport jalviewAlignmentView)
+  // {
+  // return createAptxFrameInJalview(aptxTrees);
+  //
+  // }
+  //
+  // public static MainFrame createInstance(final Phylogeny aptxTree,
+  // final AlignmentViewport jalviewAlignmentView)
+  // {
+  // Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in
+  // // several trees simultaneously
+  // return createAptxFrameInJalview(aptxTrees);
+  //
+  // }
 
   public static MainFrame createInstance(
-          TreeBuilder calculatedTree) // very dense method, to be split up
+          final TreeBuilder calculatedTree) // very dense method, to be split up
   {
-    ArchaeopteryxTreeConverter aptxTreeBuilder = new ArchaeopteryxTreeConverter(
+    ExternalTreeBuilderI<Phylogeny, PhylogenyNode> aptxTreeBuilder = new ArchaeopteryxTreeBuilder(
             calculatedTree);
 
-    Phylogeny aptxTree = aptxTreeBuilder.buildAptxTree();
+    Phylogeny aptxTree = aptxTreeBuilder.buildTree();
     Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in
                                           // several trees simultaneously
 
-    MainFrame aptxApp = createBoundAptxFrame(aptxTrees,
-            calculatedTree.getAvport());
+    MainFrame aptxApp = createAptxFrame(aptxTrees);
+            
     bindNodesToJalviewSequences(aptxApp, calculatedTree.getAvport(),
-            aptxTreeBuilder.getAlignmentBoundNodes());
+            aptxTreeBuilder.getAlignmentBoundNodes(),
+            aptxTreeBuilder.getNodesBoundAlignment());
     return bindFrameToJalview(aptxApp);
 
   }
@@ -65,25 +73,26 @@ public final class ArchaeopteryxInit
 
 
 
-  private static MainFrame createBoundAptxFrame(Phylogeny[] aptxTrees,
-          AlignmentViewport jalviewAlignmentView)
+  public static MainFrame createAptxFrame(
+          final Phylogeny[] aptxTrees)
   {
     MainFrame aptxApp = Archaeopteryx.createApplication(aptxTrees,
             "_aptx_jalview_configuration_file", null);
-
     return aptxApp;
   }
 
-  private static void bindNodesToJalviewSequences(MainFrame aptxApp,
-          AlignmentViewport jalviewAlignViewport,
-          Map<SequenceI, PhylogenyNode> alignMappedToNodes)
+  public static JalviewTreeViewerBindingI<?> bindNodesToJalviewSequences(
+          final MainFrame aptxApp,
+          final AlignmentViewport jalviewAlignViewport,
+          final Map<SequenceI, PhylogenyNode> alignMappedToNodes,
+          final Map<PhylogenyNode, SequenceI> nodesMappedToAlign)
   {
-    new JalviewAptxBinding(aptxApp, jalviewAlignViewport,
-            alignMappedToNodes);
+    return new JalviewAptxBinding(aptxApp, jalviewAlignViewport,
+            alignMappedToNodes, nodesMappedToAlign);
   }
 
 
-  private static MainFrame bindFrameToJalview(MainFrame aptxApp)
+  public static MainFrame bindFrameToJalview(final MainFrame aptxApp)
   {
     int width = 400;
     int height = 550;