JAL-1632 TreeChooser renamed CalculationChooser, text improved, i18n
[jalview.git] / src / jalview / gui / CalculationChooser.java
similarity index 76%
rename from src/jalview/gui/TreeChooser.java
rename to src/jalview/gui/CalculationChooser.java
index fa1195c..faaf86b 100644 (file)
@@ -20,8 +20,7 @@
  */
 package jalview.gui;
 
-import jalview.analysis.NJTree;
-import jalview.analysis.scoremodels.PIDModel;
+import jalview.analysis.TreeBuilder;
 import jalview.analysis.scoremodels.ScoreModels;
 import jalview.analysis.scoremodels.SimilarityParams;
 import jalview.api.analysis.ScoreModelI;
@@ -48,10 +47,18 @@ import javax.swing.JPanel;
 import javax.swing.JRadioButton;
 
 /**
- * A dialog to allow a user to select and action Tree calculation options
+ * A dialog where a user can choose and action Tree or PCA calculation options
  */
-public class TreeChooser extends JPanel
+public class CalculationChooser extends JPanel
 {
+  /*
+   * flag for whether gap matches residue in the PID calculation for a Tree
+   * - true gives Jalview 2.10.1 behaviour
+   * - set to false (using Groovy) for a more correct tree
+   * (JAL-374)
+   */
+  private static boolean treeMatchGaps = true;
+
   private static final Font VERDANA_11PT = new Font("Verdana", 0, 11);
 
   AlignFrame af;
@@ -83,7 +90,7 @@ public class TreeChooser extends JPanel
    * 
    * @param af
    */
-  public TreeChooser(AlignFrame alignFrame)
+  public CalculationChooser(AlignFrame alignFrame)
   {
     this.af = alignFrame;
     init();
@@ -216,11 +223,11 @@ public class TreeChooser extends JPanel
     }
     this.add(actionPanel);
 
-    int width = 380;
+    int width = 350;
     int height = includeParams ? 400 : 220;
     Desktop.addInternalFrame(frame,
-            MessageManager.getString("label.choose_tree"), width, height,
-            false);
+            MessageManager.getString("label.choose_calculation"), width,
+            height, false);
 
     frame.setLayer(JLayeredPane.PALETTE_LAYER);
   }
@@ -233,39 +240,61 @@ public class TreeChooser extends JPanel
     boolean doPCA = pca.isSelected();
     ScoreModelI sm = ScoreModels.getInstance().forName(
             modelNames.getSelectedItem().toString());
-    SimilarityParamsI params = getSimilarityParameters(doPCA, sm);
+    SimilarityParamsI params = getSimilarityParameters(doPCA);
 
     if (doPCA)
     {
-      AlignViewport viewport = af.getViewport();
-      if (((viewport.getSelectionGroup() != null)
-              && (viewport.getSelectionGroup().getSize() < 4) && (viewport
-              .getSelectionGroup().getSize() > 0))
-              || (viewport.getAlignment().getHeight() < 4))
-      {
-        JvOptionPane
-                .showInternalMessageDialog(
-                        this,
-                        MessageManager
-                                .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
-                        MessageManager
-                                .getString("label.sequence_selection_insufficient"),
-                        JvOptionPane.WARNING_MESSAGE);
-        return;
-      }
-      new PCAPanel(af.alignPanel, sm, params);
+      openPcaPanel(sm, params);
     }
     else
     {
-      String treeType = neighbourJoining.isSelected() ? NJTree.NEIGHBOUR_JOINING
-              : NJTree.AVERAGE_DISTANCE;
-      af.newTreePanel(treeType, sm, params);
+      openTreePanel(sm, params);
     }
 
     // closeFrame();
   }
 
   /**
+   * Open a new Tree panel on the desktop
+   * 
+   * @param sm
+   * @param params
+   */
+  protected void openTreePanel(ScoreModelI sm, SimilarityParamsI params)
+  {
+    String treeType = neighbourJoining.isSelected() ? TreeBuilder.NEIGHBOUR_JOINING
+            : TreeBuilder.AVERAGE_DISTANCE;
+    af.newTreePanel(treeType, sm, params);
+  }
+
+  /**
+   * Open a new PCA panel on the desktop
+   * 
+   * @param sm
+   * @param params
+   */
+  protected void openPcaPanel(ScoreModelI sm, SimilarityParamsI params)
+  {
+    AlignViewport viewport = af.getViewport();
+    if (((viewport.getSelectionGroup() != null)
+            && (viewport.getSelectionGroup().getSize() < 4) && (viewport
+            .getSelectionGroup().getSize() > 0))
+            || (viewport.getAlignment().getHeight() < 4))
+    {
+      JvOptionPane
+              .showInternalMessageDialog(
+                      this,
+                      MessageManager
+                              .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
+                      MessageManager
+                              .getString("label.sequence_selection_insufficient"),
+                      JvOptionPane.WARNING_MESSAGE);
+      return;
+    }
+    new PCAPanel(af.alignPanel, sm, params);
+  }
+
+  /**
    * 
    */
   protected void closeFrame()
@@ -283,32 +312,27 @@ public class TreeChooser extends JPanel
    * calculation
    * 
    * @param doPCA
-   * @param sm
    * @return
    */
-  protected SimilarityParamsI getSimilarityParameters(boolean doPCA,
-          ScoreModelI sm)
+  protected SimilarityParamsI getSimilarityParameters(boolean doPCA)
   {
     // commented out: parameter choices read from gui widgets
     // SimilarityParamsI params = new SimilarityParams(
     // includeGappedColumns.isSelected(), matchGaps.isSelected(),
     // includeGaps.isSelected(), shorterSequence.isSelected());
 
-    /*
-     * for now we want
-     * includeGappedColumns = true
-     * includeGaps = true
-     * matchOnShortestSequence = false
-     * matchGaps = true except false for PCA by PID (to match SeqSpace)
-     */
     boolean includeGapGap = true;
     boolean includeGapResidue = true;
     boolean matchOnShortestLength = false;
-    boolean matchGap = true;
-    if (doPCA && (sm instanceof PIDModel))
-    {
-      matchGap = false;
-    }
+
+    /*
+     * 'matchGaps' flag is only used in the PID calculation
+     * - set to false for PCA so that PCA using PID reproduces SeqSpace PCA
+     * - set to true for Tree to reproduce Jalview 2.10.1 calculation
+     * - set to false for Tree for a more correct calculation (JAL-374)
+     */
+    boolean matchGap = doPCA ? false : treeMatchGaps;
+
     return new SimilarityParams(includeGapGap, matchGap, includeGapResidue, matchOnShortestLength);
   }