Blank interfaces added
[jalview.git] / src / jalview / ext / archaeopteryx / ArchaeopteryxInit.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.ext.archaeopteryx;
22
23 import jalview.analysis.TreeModel;
24 import jalview.io.NewickFile;
25
26 import java.io.File;
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
29 import java.io.PrintWriter;
30
31 import org.forester.archaeopteryx.Archaeopteryx;
32
33 public class ArchaeopteryxInit
34 {
35   private String filePath = "/tmp/jalviewtree.nwk";
36
37   private TreeModel tree;
38
39   private NewickFile newickTree;
40
41   public ArchaeopteryxInit(TreeModel jalviewTreeModel)
42   {
43     this.tree = jalviewTreeModel;
44     this.newickTree = treeToNewick(tree);
45   }
46
47   public ArchaeopteryxInit(NewickFile newickTreeModel)
48   {
49     this.newickTree = newickTreeModel;
50   }
51
52   public void startArchaeopteryx()
53   {
54     String newickOutput = newickTree.print(newickTree.hasBootstrap(),
55             newickTree.hasDistances(), newickTree.hasRootDistance());
56
57     File newickFile = new File(filePath);
58     PrintWriter writer;
59
60     try
61     {
62       writer = new PrintWriter(newickFile);
63       writer.println(newickOutput);
64
65       writer.close();
66
67       String[] commandLineArgs = { "-open", newickFile.getCanonicalPath() };
68       Archaeopteryx.main(commandLineArgs);
69
70     } catch (FileNotFoundException e)
71     {
72       // TODO Auto-generated catch block
73       e.printStackTrace();
74     } catch (IOException e)
75     {
76       // TODO Auto-generated catch block
77       e.printStackTrace();
78     }
79
80
81   }
82
83
84   public String getFilePath()
85   {
86     return filePath;
87   }
88
89   public void setFilePath(String newFilePath)
90   {
91     this.filePath = newFilePath;
92   }
93
94   public TreeModel getTree()
95   {
96     return tree;
97   }
98
99   public void setTree(TreeModel newTree)
100   {
101     this.tree = newTree;
102   }
103
104   public NewickFile getNewickTree()
105   {
106     return newickTree;
107   }
108
109   public void setNewickTree(NewickFile newNewickTree)
110   {
111     this.newickTree = newNewickTree;
112   }
113
114   public static NewickFile treeToNewick(TreeModel tree)
115   {
116     NewickFile newickTree = new NewickFile(tree.getTopNode(),
117             tree.hasBootstrap(), tree.hasDistances(),
118             tree.hasRootDistance());
119
120     return newickTree;
121   }
122
123 }