Merge branch 'kjvdh/features/PhylogenyViewer' of
[jalview.git] / src / jalview / gui / CalculationChooser.java
index f2d65e5..30a9b3d 100644 (file)
 package jalview.gui;
 
 import jalview.analysis.TreeBuilder;
+import jalview.analysis.TreeCalculator;
+import jalview.analysis.TreeModel;
 import jalview.analysis.scoremodels.ScoreModels;
 import jalview.analysis.scoremodels.SimilarityParams;
 import jalview.api.analysis.ScoreModelI;
 import jalview.api.analysis.SimilarityParamsI;
 import jalview.datamodel.SequenceGroup;
+import jalview.ext.archaeopteryx.AptxInit;
 import jalview.util.MessageManager;
 
 import java.awt.BorderLayout;
@@ -105,6 +108,11 @@ public class CalculationChooser extends JPanel
 
   List<String> tips = new ArrayList<>();
 
+  /*
+   * the most recently opened PCA results panel
+   */
+  private PCAPanel pcaPanel;
+
   /**
    * Constructor
    * 
@@ -460,26 +468,42 @@ public class CalculationChooser extends JPanel
   protected void calculate_actionPerformed()
   {
     boolean doPCA = pca.isSelected();
-    String modelName = modelNames.getSelectedItem().toString();
+    String substitutionMatrix = modelNames.getSelectedItem().toString();
     SimilarityParamsI params = getSimilarityParameters(doPCA);
 
     if (doPCA)
     {
-      openPcaPanel(modelName, params);
+      openPcaPanel(substitutionMatrix, params);
     }
     else
     {
-      calculateTree();
-      openTreePanel(modelName, params);
+      createTree(substitutionMatrix, params);
+
+
+
+
+
+
     }
 
     // closeFrame();
   }
 
-  protected void calculateTree()
+  protected void createTree(String substitutionMatrix,
+          SimilarityParamsI params)
   {
+    String treeAlgo = determineTreeAlgo();
+    TreeCalculator treeCalculator = new TreeCalculator(treeAlgo,
+            substitutionMatrix, params);
+    TreeBuilder calculatedTree = treeCalculator.makeTree(af.getViewport());
 
+    AptxInit.createInstance(calculatedTree);
+
+    TreeModel tree = new TreeModel(calculatedTree);
+    openTreePanel(tree, treeAlgo, substitutionMatrix);
   }
+
+
   protected String determineTreeAlgo() // to be modified & expanded
   {
     String treeAlgorithm = neighbourJoining.isSelected()
@@ -508,8 +532,12 @@ public class CalculationChooser extends JPanel
   /**
    * Open a new Tree panel on the desktop
    * 
+   * @param tree
+   * @param params
+   * @param treeAlgo
    */
-  protected void openTreePanel(String modelName, SimilarityParamsI params)
+  protected void openTreePanel(TreeModel tree, String treeAlgo,
+          String substitutionMatrix)
   {
     /*
      * gui validation shouldn't allow insufficient sequences here, but leave
@@ -517,9 +545,7 @@ public class CalculationChooser extends JPanel
      */
     checkEnoughSequences(af.getViewport());
 
-    String treeType = determineTreeAlgo();
-
-    af.newTreePanel(treeType, modelName, params);
+    af.newTreePanel(tree, treeAlgo, substitutionMatrix);
   }
 
   /**
@@ -550,7 +576,7 @@ public class CalculationChooser extends JPanel
               JvOptionPane.WARNING_MESSAGE);
       return;
     }
-    new PCAPanel(af.alignPanel, modelName, params);
+    pcaPanel = new PCAPanel(af.alignPanel, modelName, params);
   }
 
   /**
@@ -592,7 +618,6 @@ public class CalculationChooser extends JPanel
      */
     boolean matchGap = doPCA ? false : treeMatchGaps;
 
-
     return new SimilarityParams(includeGapGap, matchGap, includeGapResidue,
             matchOnShortestLength);
   }
@@ -609,4 +634,9 @@ public class CalculationChooser extends JPanel
     {
     }
   }
+
+  public PCAPanel getPcaPanel()
+  {
+    return pcaPanel;
+  }
 }