package jalview.ext.archaeopteryx;
-import jalview.analysis.TreeModel;
-import jalview.io.NewickFile;
+import jalview.analysis.TreeBuilder;
+import jalview.gui.Desktop;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.PrintWriter;
+import java.awt.Dimension;
import org.forester.archaeopteryx.Archaeopteryx;
+import org.forester.archaeopteryx.MainFrame;
+import org.forester.phylogeny.Phylogeny;
-public class ArchaeopteryxInit
+public final class ArchaeopteryxInit
{
- private String filePath = "/tmp/jalviewtree.nwk";
-
- private TreeModel tree;
-
- private NewickFile newickTree;
-
- public ArchaeopteryxInit(TreeModel jalviewTreeModel)
+ public static MainFrame createInstance(Phylogeny[] aptxTrees)
{
- this.tree = jalviewTreeModel;
- this.newickTree = treeToNewick(tree);
- }
+ return createBoundAptxFrame(aptxTrees);
- public ArchaeopteryxInit(NewickFile newickTreeModel)
- {
- this.newickTree = newickTreeModel;
}
- public void startArchaeopteryx()
+ public static MainFrame createInstance(Phylogeny aptxTree)
{
- String newickOutput = newickTree.print(newickTree.hasBootstrap(),
- newickTree.hasDistances(), newickTree.hasRootDistance());
-
- File newickFile = new File(filePath);
- PrintWriter writer;
+ Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in
+ // several trees simultaneously
+ return createBoundAptxFrame(aptxTrees);
- 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 static MainFrame createInstance(
+ TreeBuilder calculatedTree)
+ {
+ ArchaeopteryxTreeBuilder aptxTreeBuilder = new ArchaeopteryxTreeBuilder();
+ Phylogeny aptxTree = aptxTreeBuilder.buildAptxTree(calculatedTree);
+ Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in
+ // several trees simultaneously
+ return createBoundAptxFrame(aptxTrees);
}
- public String getFilePath()
+ private static MainFrame createBoundAptxFrame(Phylogeny[] aptxTrees)
{
- return filePath;
+ MainFrame aptxApp = Archaeopteryx.createApplication(aptxTrees,
+ "_aptx_jalview_configuration_file", null);
+ return bindFrameToJalview(aptxApp);
}
- public void setFilePath(String newFilePath)
- {
- this.filePath = newFilePath;
- }
- public TreeModel getTree()
- {
- return tree;
- }
- public void setTree(TreeModel newTree)
+ private static MainFrame bindFrameToJalview(MainFrame aptxApp)
{
- this.tree = newTree;
- }
+ int width = 400;
+ int height = 550;
+ aptxApp.setMinimumSize(new Dimension(width, height));
- public NewickFile getNewickTree()
- {
- return newickTree;
- }
+ Desktop.addInternalFrame(aptxApp, "Archaeopteryx Tree View", true,
+ width, height, true, true);
- public void setNewickTree(NewickFile newNewickTree)
- {
- this.newickTree = newNewickTree;
- }
+ return aptxApp;
- 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
+
+}