Begin separation of GUI and tree calculation logic origin/spikes/koen
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Fri, 29 Sep 2017 15:56:49 +0000 (16:56 +0100)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Fri, 29 Sep 2017 15:56:49 +0000 (16:56 +0100)
src/jalview/ext/archaeopteryx/AlignmentToTreeViewerI.java [new file with mode: 0644]
src/jalview/ext/archaeopteryx/ArchaeopteryxInit.java [new file with mode: 0644]
src/jalview/ext/archaeopteryx/TreeViewerBindingI.java [new file with mode: 0644]
src/jalview/gui/AlignFrame.java
src/jalview/gui/CalculationChooser.java
src/jalview/gui/TreePanel.java

diff --git a/src/jalview/ext/archaeopteryx/AlignmentToTreeViewerI.java b/src/jalview/ext/archaeopteryx/AlignmentToTreeViewerI.java
new file mode 100644 (file)
index 0000000..85ee750
--- /dev/null
@@ -0,0 +1,7 @@
+package jalview.ext.archaeopteryx;
+
+
+interface AlignmentToTreeViewerI
+{
+
+}
diff --git a/src/jalview/ext/archaeopteryx/ArchaeopteryxInit.java b/src/jalview/ext/archaeopteryx/ArchaeopteryxInit.java
new file mode 100644 (file)
index 0000000..5089112
--- /dev/null
@@ -0,0 +1,109 @@
+package jalview.ext.archaeopteryx;
+
+import jalview.analysis.TreeModel;
+import jalview.io.NewickFile;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.forester.archaeopteryx.Archaeopteryx;
+
+public class ArchaeopteryxInit
+{
+  private String filePath = "/tmp/jalviewtree.nwk";
+
+  private TreeModel tree;
+
+  private NewickFile newickTree;
+
+  public ArchaeopteryxInit(TreeModel jalviewTreeModel)
+  {
+    this.tree = jalviewTreeModel;
+    this.newickTree = treeToNewick(tree);
+  }
+
+  public ArchaeopteryxInit(NewickFile newickTreeModel)
+  {
+    this.newickTree = newickTreeModel;
+  }
+
+  public void startArchaeopteryx()
+  {
+    String newickOutput = newickTree.print(newickTree.hasBootstrap(),
+            newickTree.hasDistances(), newickTree.hasRootDistance());
+
+    File newickFile = new File(filePath);
+    PrintWriter writer;
+
+    try
+    {
+      writer = new PrintWriter(newickFile);
+      writer.println(newickOutput);
+
+      // System.out.println(writer.checkError());
+      writer.close();
+
+      String[] commandLineArgs = { "-open", newickFile.getCanonicalPath() };
+      Archaeopteryx.main(commandLineArgs);
+
+    } catch (FileNotFoundException e)
+    {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
+    } catch (IOException e)
+    {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
+    }
+
+
+  }
+
+
+  public String getFilePath()
+  {
+    return filePath;
+  }
+
+  public void setFilePath(String newFilePath)
+  {
+    this.filePath = newFilePath;
+  }
+
+  public TreeModel getTree()
+  {
+    return tree;
+  }
+
+  public void setTree(TreeModel newTree)
+  {
+    this.tree = newTree;
+  }
+
+  public NewickFile getNewickTree()
+  {
+    return newickTree;
+  }
+
+  public void setNewickTree(NewickFile newNewickTree)
+  {
+    this.newickTree = newNewickTree;
+  }
+
+  public static NewickFile treeToNewick(TreeModel tree)
+  {
+    NewickFile newickTree = new NewickFile(tree.getTopNode(),
+            tree.hasBootstrap(), tree.hasDistances(),
+            tree.hasRootDistance());
+      /*     System.out.println(newickTree.print(tree.hasBootstrap(),
+             tree.hasDistances(), tree.hasRootDistance()));
+      
+           System.out.println(newickTree.print(newickTree.hasBootstrap(),
+             newickTree.hasDistances(), newickTree.hasRootDistance()));*/
+
+    return newickTree;
+  }
+
+}
\ No newline at end of file
diff --git a/src/jalview/ext/archaeopteryx/TreeViewerBindingI.java b/src/jalview/ext/archaeopteryx/TreeViewerBindingI.java
new file mode 100644 (file)
index 0000000..4bb0ff2
--- /dev/null
@@ -0,0 +1,6 @@
+package jalview.ext.archaeopteryx;
+
+interface TreeViewerBindingI
+{
+
+}
index 13b715e..6f0bd11 100644 (file)
@@ -3553,6 +3553,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     viewport.followSelection = listenToViewSelections.isSelected();
   }
 
+
   /**
    * Constructs a tree panel and adds it to the desktop
    * 
index a9f3966..f2d65e5 100644 (file)
@@ -103,7 +103,7 @@ public class CalculationChooser extends JPanel
 
   final ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer();
 
-  List<String> tips = new ArrayList<String>();
+  List<String> tips = new ArrayList<>();
 
   /**
    * Constructor
@@ -370,7 +370,7 @@ public class CalculationChooser extends JPanel
    */
   protected JComboBox<String> buildModelOptionsList()
   {
-    final JComboBox<String> scoreModelsCombo = new JComboBox<String>();
+    final JComboBox<String> scoreModelsCombo = new JComboBox<>();
     scoreModelsCombo.setRenderer(renderer);
 
     /*
@@ -413,7 +413,7 @@ public class CalculationChooser extends JPanel
   {
     Object curSel = comboBox.getSelectedItem();
     toolTips.clear();
-    DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();
+    DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
 
     /*
      * now we can actually add entries to the combobox,
@@ -469,25 +469,29 @@ public class CalculationChooser extends JPanel
     }
     else
     {
+      calculateTree();
       openTreePanel(modelName, params);
     }
 
     // closeFrame();
   }
 
-  /**
-   * Open a new Tree panel on the desktop
-   * 
-   * @param modelName
-   * @param params
-   */
-  protected void openTreePanel(String modelName, SimilarityParamsI params)
+  protected void calculateTree()
+  {
+
+  }
+  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)
     {
@@ -499,10 +503,22 @@ public class CalculationChooser extends JPanel
               JvOptionPane.WARNING_MESSAGE);
       return;
     }
+  }
+
+  /**
+   * Open a new Tree panel on the desktop
+   * 
+   */
+  protected void openTreePanel(String modelName, SimilarityParamsI params)
+  {
+    /*
+     * 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());
+
+    String treeType = determineTreeAlgo();
 
-    String treeType = neighbourJoining.isSelected()
-            ? TreeBuilder.NEIGHBOUR_JOINING
-            : TreeBuilder.AVERAGE_DISTANCE;
     af.newTreePanel(treeType, modelName, params);
   }
 
@@ -576,6 +592,7 @@ public class CalculationChooser extends JPanel
      */
     boolean matchGap = doPCA ? false : treeMatchGaps;
 
+
     return new SimilarityParams(includeGapGap, matchGap, includeGapResidue,
             matchOnShortestLength);
   }
index 3af174a..a4521cc 100755 (executable)
@@ -41,7 +41,7 @@ import jalview.datamodel.NodeTransformI;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.SequenceNode;
-import jalview.ext.archaeopteryx.Testo;
+import jalview.ext.archaeopteryx.ArchaeopteryxInit;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
 import jalview.io.NewickFile;
@@ -56,9 +56,7 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.image.BufferedImage;
 import java.beans.PropertyChangeEvent;
-import java.io.File;
 import java.io.FileOutputStream;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -279,6 +277,10 @@ public class TreePanel extends GTreePanel
         {
           originalSeqData.setVisible(false);
         }
+
+        ArchaeopteryxInit archae = new ArchaeopteryxInit(newtree);
+        archae.startArchaeopteryx();
+
       }
       else
       {
@@ -289,6 +291,10 @@ public class TreePanel extends GTreePanel
                 : new AverageDistanceTree(av, sm, similarityParams);
         tree = new TreeModel(njtree);
         showDistances(true);
+
+        ArchaeopteryxInit archae = new ArchaeopteryxInit(tree);
+        archae.startArchaeopteryx();
+
       }
 
       tree.reCount(tree.getTopNode());
@@ -296,18 +302,6 @@ public class TreePanel extends GTreePanel
       treeCanvas.setTree(tree);
       treeCanvas.repaint();
 
-      Testo test = new Testo();
-      NewickFile newickTree = test.treeToNewick(tree);
-      File newickAsFile = test.newickToArchaeopteryx(newickTree);
-      try
-      {
-        String[] archaeCommandlineArgs = {
-            "-open", newickAsFile.getCanonicalPath() };
-        test.startArchaeopteryx(archaeCommandlineArgs);
-      } catch (IOException e)
-      {
-        e.printStackTrace();
-      }
       av.setCurrentTree(tree);
       if (av.getSortByTree())
       {