Merge branch 'kjvdh/features/PhylogenyViewer_tabbedsupport' into merge/2_11_2/kjvdh...
[jalview.git] / src / jalview / gui / CalculationChooser.java
index f7e5413..c43d59b 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.bin.Cache;
 import jalview.datamodel.SequenceGroup;
+import jalview.ext.archaeopteryx.AptxInit;
 import jalview.util.MessageManager;
 
 import java.awt.BorderLayout;
@@ -424,7 +427,6 @@ public class CalculationChooser extends JPanel
     Object curSel = comboBox.getSelectedItem();
     toolTips.clear();
     DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
-
     /*
      * select the score models applicable to the alignment type
      */
@@ -514,34 +516,54 @@ 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
     {
-      openTreePanel(modelName, params);
+      createTree(substitutionMatrix, params);
+
+
+
+
+
+
     }
 
     // closeFrame();
   }
 
-  /**
-   * Open a new Tree panel on the desktop
-   * 
-   * @param modelName
-   * @param params
-   */
-  protected void openTreePanel(String modelName, SimilarityParamsI params)
+  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()
+            ? TreeBuilder.NEIGHBOUR_JOINING
+            : TreeBuilder.AVERAGE_DISTANCE;
+
+    return treeAlgorithm;
+
+  }
+
+  protected void checkEnoughSequences(AlignViewport viewport)
   {
-    /*
-     * gui validation shouldn't allow insufficient sequences here, but leave
-     * this check in in case this method gets exposed programmatically in future
-     */
-    AlignViewport viewport = af.getViewport();
     SequenceGroup sg = viewport.getSelectionGroup();
     if (sg != null && sg.getSize() < MIN_TREE_SELECTION)
     {
@@ -553,11 +575,25 @@ public class CalculationChooser extends JPanel
               JvOptionPane.WARNING_MESSAGE);
       return;
     }
+  }
 
-    String treeType = neighbourJoining.isSelected()
-            ? TreeBuilder.NEIGHBOUR_JOINING
-            : TreeBuilder.AVERAGE_DISTANCE;
-    af.newTreePanel(treeType, modelName, params);
+  /**
+   * Open a new Tree panel on the desktop
+   * 
+   * @param tree
+   * @param params
+   * @param treeAlgo
+   */
+  protected void openTreePanel(TreeModel tree, String treeAlgo,
+          String substitutionMatrix)
+  {
+    /*
+     * gui validation shouldn't allow insufficient sequences here, but leave
+     * this check in in case this method gets exposed programmatically in future
+     */
+    checkEnoughSequences(af.getViewport());
+
+    af.newTreePanel(tree, treeAlgo, substitutionMatrix);
   }
 
   /**