JAL-2799 rearranged AptxInit code
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Fri, 24 Nov 2017 19:29:23 +0000 (19:29 +0000)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Fri, 24 Nov 2017 19:29:23 +0000 (19:29 +0000)
src/jalview/ext/archaeopteryx/AptxInit.java
src/jalview/gui/CalculationChooser.java
test/jalview/ext/archaeopteryx/AptxJalviewSequenceTreeTest.java
test/jalview/ext/archaeopteryx/AptxPhylogenyTreeTest.java

index 7dbddad..5a9fb12 100644 (file)
@@ -57,35 +57,9 @@ public final class AptxInit
   private final static NHXParser.TAXONOMY_EXTRACTION TAXONOMY_EXTRACTION = APTX_CONFIG
           .getTaxonomyExtraction();
 
-  /**
-   * Test method, should generally not be used as it does not bind the tree to
-   * its alignment
-   * 
-   * @param aptxTrees
-   * @return
-   */
-  public static MainFrame createUnboundInstance(final Phylogeny aptxTree)
-  {
-    return createAptxFrame(aptxTree);
-  }
 
-  // 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(
+
+  public static MainFrame createInstanceFromCalculation(
           final TreeBuilder calculatedTree) // very dense method, to be split up
   {
     ExternalTreeBuilderI<Phylogeny, PhylogenyNode> aptxTreeBuilder = new AptxTreeBuilder(
@@ -93,14 +67,10 @@ public final class AptxInit
 
     Phylogeny aptxTree = aptxTreeBuilder.buildTree();
 
-    MainFrame aptxApp = createAptxFrame(aptxTree);
+    MainFrame aptxApp = createAptxFrame(aptxTree,
+            calculatedTree.getAvport(), null);
             
-    bindNodesToJalviewSequences(aptxApp, calculatedTree.getAvport(),
-            aptxTreeBuilder.getAlignmentBoundNodes(),
-            aptxTreeBuilder.getNodesBoundAlignment());
-
-    return bindFrameToJalview(aptxApp);
-
+    return aptxApp;
   }
 
   /**
@@ -153,22 +123,13 @@ public final class AptxInit
     for (int i = 0; i < phylogenies.length; i++)
       {
       Phylogeny tree = phylogenies[i];
+
       if (nhx_or_nexus && INTERNAL_NUMBERS_AS_CONFIDENCE)
       {
         PhylogenyMethods.transferInternalNodeNamesToConfidence(tree, "");
       }
 
-      MainFrame aptxApp = Archaeopteryx.createApplication(tree, APTX_CONFIG,
-              treeTitle);
-      LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
-              viewport.getAlignment().getSequencesArray(), tree);
-
-      bindAptxNodes.associateLeavesToSequences();
-      bindNodesToJalviewSequences(aptxApp, viewport,
-              bindAptxNodes.getAlignmentWithNodes(),
-              bindAptxNodes.getNodesWithAlignment());
-      bindFrameToJalview(aptxApp);
-      aptxFrames[i] = aptxApp;
+      aptxFrames[i] = createAptxFrame(tree, viewport, treeTitle);
     }
 
     return aptxFrames;
@@ -190,17 +151,7 @@ public final class AptxInit
     for (int i = 0; i < trees.length; i++)
     {
       Phylogeny tree = trees[i];
-      MainFrame aptxApp = Archaeopteryx.createApplication(tree, APTX_CONFIG,
-              treeTitle);
-      LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
-              viewport.getAlignment().getSequencesArray(), tree);
-
-      bindAptxNodes.associateLeavesToSequences();
-      bindNodesToJalviewSequences(aptxApp, viewport,
-              bindAptxNodes.getAlignmentWithNodes(),
-              bindAptxNodes.getNodesWithAlignment());
-      bindFrameToJalview(aptxApp);
-      aptxFrames[i] = aptxApp;
+      aptxFrames[i] = createAptxFrame(tree, viewport, treeTitle);
     }
 
     return aptxFrames;
@@ -210,11 +161,21 @@ public final class AptxInit
 
 
 
+
   public static MainFrame createAptxFrame(
-          final Phylogeny aptxTree)
+          final Phylogeny aptxTree,
+          final AlignmentViewport jalviewAlignport, String treeTitle)
   {
     MainFrame aptxApp = Archaeopteryx.createApplication(aptxTree,
-            APTX_CONFIG, null);
+            APTX_CONFIG, treeTitle);
+    LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
+            jalviewAlignport.getAlignment().getSequencesArray(), aptxTree);
+
+    bindAptxNodes.associateLeavesToSequences();
+    bindNodesToJalviewSequences(aptxApp, jalviewAlignport,
+            bindAptxNodes.getAlignmentWithNodes(),
+            bindAptxNodes.getNodesWithAlignment());
+    bindFrameToJalview(aptxApp);
     return aptxApp;
   }
 
index 30a9b3d..f092e40 100644 (file)
@@ -497,7 +497,7 @@ public class CalculationChooser extends JPanel
             substitutionMatrix, params);
     TreeBuilder calculatedTree = treeCalculator.makeTree(af.getViewport());
 
-    AptxInit.createInstance(calculatedTree);
+    AptxInit.createInstanceFromCalculation(calculatedTree);
 
     TreeModel tree = new TreeModel(calculatedTree);
     openTreePanel(tree, treeAlgo, substitutionMatrix);
index e7324eb..d340209 100644 (file)
@@ -60,7 +60,7 @@ public class AptxJalviewSequenceTreeTest extends TreeViewTest
   @BeforeClass(dependsOnMethods = { "setUpTree" })
   public void createTreeView()
   {
-    treeView = AptxInit.createInstance(jalviewTree);
+    treeView = AptxInit.createInstanceFromCalculation(jalviewTree);
     aptx = (MainFrame) treeView; // still pretty ugly
 
     treePanel = aptx.getMainPanel().getCurrentTreePanel();
index 9d62eb1..8975d83 100644 (file)
@@ -3,6 +3,9 @@ package jalview.ext.archaeopteryx;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 
+import jalview.gui.Desktop;
+
+import org.forester.archaeopteryx.Archaeopteryx;
 import org.forester.archaeopteryx.MainFrame;
 import org.forester.archaeopteryx.TreePanel;
 import org.forester.phylogeny.Phylogeny;
@@ -61,10 +64,13 @@ public class AptxPhylogenyTreeTest extends TreeViewTest
   @BeforeClass(dependsOnMethods = { "setUpJalview", "setUpTree" })
   public void createTreeView()
   {
-    treeView = AptxInit.createUnboundInstance(inputTree);
+    treeView = Archaeopteryx.createApplication(inputTree);
     aptx = (MainFrame) treeView; // pretty ugly
     treePanel = aptx.getMainPanel().getCurrentTreePanel();
     tree = treePanel.getPhylogeny();
+
+    Desktop.addInternalFrame(aptx, "Archaeopteryx", 500, 500);
+
   }