JAL-2795 simplified instance creation from calculation
[jalview.git] / src / jalview / gui / CalculationChooser.java
index 8b4c212..bae4986 100644 (file)
@@ -28,7 +28,7 @@ import jalview.analysis.scoremodels.SimilarityParams;
 import jalview.api.analysis.ScoreModelI;
 import jalview.api.analysis.SimilarityParamsI;
 import jalview.datamodel.SequenceGroup;
-import jalview.ext.archaeopteryx.ArchaeopteryxInit;
+import jalview.ext.archaeopteryx.AptxInit;
 import jalview.util.MessageManager;
 
 import java.awt.BorderLayout;
@@ -46,6 +46,7 @@ import java.awt.event.FocusListener;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.beans.PropertyVetoException;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -464,6 +465,8 @@ public class CalculationChooser extends JPanel
 
   /**
    * Open and calculate the selected tree or PCA on 'OK'
+   * 
+   * @throws IOException
    */
   protected void calculate_actionPerformed()
   {
@@ -477,16 +480,17 @@ public class CalculationChooser extends JPanel
     }
     else
     {
+      try
+      {
+        createTree(substitutionMatrix, params);
+      } catch (IOException e)
+      {
+        // TODO Auto-generated catch block
+        e.printStackTrace();
+      }
+
 
-      String treeAlgo = determineTreeAlgo();
-      TreeCalculator treeCalculator = new TreeCalculator(treeAlgo,
-              substitutionMatrix, params);
-      TreeBuilder calculatedTree = treeCalculator
-              .makeTree(af.getViewport());
-      TreeModel tree = new TreeModel(calculatedTree);
 
-      openTreePanel(tree, treeAlgo, substitutionMatrix);
-      ArchaeopteryxInit.createInstance(calculatedTree);
 
 
 
@@ -495,7 +499,25 @@ public class CalculationChooser extends JPanel
     // closeFrame();
   }
 
-
+  protected void createTree(String substitutionMatrix,
+          SimilarityParamsI params) throws IOException
+  {
+    String treeAlgo = determineTreeAlgo();
+    TreeCalculator treeCalculator = new TreeCalculator(treeAlgo,
+            substitutionMatrix, params);
+    TreeBuilder calculatedTree = treeCalculator.makeTree(af.getViewport());
+
+    // AptxInit.createInstanceFromCalculation(calculatedTree);
+
+    TreeModel tree = new TreeModel(calculatedTree);
+    jalview.io.NewickFile newick = new jalview.io.NewickFile(
+            tree.getTopNode());
+    String output = newick.print(tree.hasBootstrap(), tree.hasDistances(),
+            tree.hasRootDistance());
+    AptxInit.createInstanceFromNhx(af.getTitle(), output, 
+            af.getViewport());
+    // openTreePanel(tree, treeAlgo, substitutionMatrix);
+  }
 
 
   protected String determineTreeAlgo() // to be modified & expanded