Begin separation of GUI and tree calculation logic
[jalview.git] / src / jalview / ext / archaeopteryx / ArchaeopteryxInit.java
1 package jalview.ext.archaeopteryx;
2
3 import jalview.analysis.TreeModel;
4 import jalview.io.NewickFile;
5
6 import java.io.File;
7 import java.io.FileNotFoundException;
8 import java.io.IOException;
9 import java.io.PrintWriter;
10
11 import org.forester.archaeopteryx.Archaeopteryx;
12
13 public class ArchaeopteryxInit
14 {
15   private String filePath = "/tmp/jalviewtree.nwk";
16
17   private TreeModel tree;
18
19   private NewickFile newickTree;
20
21   public ArchaeopteryxInit(TreeModel jalviewTreeModel)
22   {
23     this.tree = jalviewTreeModel;
24     this.newickTree = treeToNewick(tree);
25   }
26
27   public ArchaeopteryxInit(NewickFile newickTreeModel)
28   {
29     this.newickTree = newickTreeModel;
30   }
31
32   public void startArchaeopteryx()
33   {
34     String newickOutput = newickTree.print(newickTree.hasBootstrap(),
35             newickTree.hasDistances(), newickTree.hasRootDistance());
36
37     File newickFile = new File(filePath);
38     PrintWriter writer;
39
40     try
41     {
42       writer = new PrintWriter(newickFile);
43       writer.println(newickOutput);
44
45       // System.out.println(writer.checkError());
46       writer.close();
47
48       String[] commandLineArgs = { "-open", newickFile.getCanonicalPath() };
49       Archaeopteryx.main(commandLineArgs);
50
51     } catch (FileNotFoundException e)
52     {
53       // TODO Auto-generated catch block
54       e.printStackTrace();
55     } catch (IOException e)
56     {
57       // TODO Auto-generated catch block
58       e.printStackTrace();
59     }
60
61
62   }
63
64
65   public String getFilePath()
66   {
67     return filePath;
68   }
69
70   public void setFilePath(String newFilePath)
71   {
72     this.filePath = newFilePath;
73   }
74
75   public TreeModel getTree()
76   {
77     return tree;
78   }
79
80   public void setTree(TreeModel newTree)
81   {
82     this.tree = newTree;
83   }
84
85   public NewickFile getNewickTree()
86   {
87     return newickTree;
88   }
89
90   public void setNewickTree(NewickFile newNewickTree)
91   {
92     this.newickTree = newNewickTree;
93   }
94
95   public static NewickFile treeToNewick(TreeModel tree)
96   {
97     NewickFile newickTree = new NewickFile(tree.getTopNode(),
98             tree.hasBootstrap(), tree.hasDistances(),
99             tree.hasRootDistance());
100       /*     System.out.println(newickTree.print(tree.hasBootstrap(),
101              tree.hasDistances(), tree.hasRootDistance()));
102       
103            System.out.println(newickTree.print(newickTree.hasBootstrap(),
104              newickTree.hasDistances(), newickTree.hasRootDistance()));*/
105
106     return newickTree;
107   }
108
109 }