Copyright test
[jalview.git] / src / jalview / ext / archaeopteryx / ArchaeopteryxInit.java
1 /*******************************************************************************
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $(date) 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       // System.out.println(writer.checkError());
66       writer.close();
67
68       String[] commandLineArgs = { "-open", newickFile.getCanonicalPath() };
69       Archaeopteryx.main(commandLineArgs);
70
71     } catch (FileNotFoundException e)
72     {
73       // TODO Auto-generated catch block
74       e.printStackTrace();
75     } catch (IOException e)
76     {
77       // TODO Auto-generated catch block
78       e.printStackTrace();
79     }
80
81
82   }
83
84
85   public String getFilePath()
86   {
87     return filePath;
88   }
89
90   public void setFilePath(String newFilePath)
91   {
92     this.filePath = newFilePath;
93   }
94
95   public TreeModel getTree()
96   {
97     return tree;
98   }
99
100   public void setTree(TreeModel newTree)
101   {
102     this.tree = newTree;
103   }
104
105   public NewickFile getNewickTree()
106   {
107     return newickTree;
108   }
109
110   public void setNewickTree(NewickFile newNewickTree)
111   {
112     this.newickTree = newNewickTree;
113   }
114
115   public static NewickFile treeToNewick(TreeModel tree)
116   {
117     NewickFile newickTree = new NewickFile(tree.getTopNode(),
118             tree.hasBootstrap(), tree.hasDistances(),
119             tree.hasRootDistance());
120       /*     System.out.println(newickTree.print(tree.hasBootstrap(),
121              tree.hasDistances(), tree.hasRootDistance()));
122       
123            System.out.println(newickTree.print(newickTree.hasBootstrap(),
124              newickTree.hasDistances(), newickTree.hasRootDistance()));*/
125
126     return newickTree;
127   }
128
129 }