Proper copyright dating added
[jalview.git] / src / jalview / ext / archaeopteryx / ArchaeopteryxInit.java
1 /*******************************************************************************
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) 2017 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
22 package jalview.ext.archaeopteryx;
23
24 import jalview.analysis.TreeModel;
25 import jalview.io.NewickFile;
26
27 import java.io.File;
28 import java.io.FileNotFoundException;
29 import java.io.IOException;
30 import java.io.PrintWriter;
31
32 import org.forester.archaeopteryx.Archaeopteryx;
33
34 public class ArchaeopteryxInit
35 {
36   private String filePath = "/tmp/jalviewtree.nwk";
37
38   private TreeModel tree;
39
40   private NewickFile newickTree;
41
42   public ArchaeopteryxInit(TreeModel jalviewTreeModel)
43   {
44     this.tree = jalviewTreeModel;
45     this.newickTree = treeToNewick(tree);
46   }
47
48   public ArchaeopteryxInit(NewickFile newickTreeModel)
49   {
50     this.newickTree = newickTreeModel;
51   }
52
53   public void startArchaeopteryx()
54   {
55     String newickOutput = newickTree.print(newickTree.hasBootstrap(),
56             newickTree.hasDistances(), newickTree.hasRootDistance());
57
58     File newickFile = new File(filePath);
59     PrintWriter writer;
60
61     try
62     {
63       writer = new PrintWriter(newickFile);
64       writer.println(newickOutput);
65
66       // System.out.println(writer.checkError());
67       writer.close();
68
69       String[] commandLineArgs = { "-open", newickFile.getCanonicalPath() };
70       Archaeopteryx.main(commandLineArgs);
71
72     } catch (FileNotFoundException e)
73     {
74       // TODO Auto-generated catch block
75       e.printStackTrace();
76     } catch (IOException e)
77     {
78       // TODO Auto-generated catch block
79       e.printStackTrace();
80     }
81
82
83   }
84
85
86   public String getFilePath()
87   {
88     return filePath;
89   }
90
91   public void setFilePath(String newFilePath)
92   {
93     this.filePath = newFilePath;
94   }
95
96   public TreeModel getTree()
97   {
98     return tree;
99   }
100
101   public void setTree(TreeModel newTree)
102   {
103     this.tree = newTree;
104   }
105
106   public NewickFile getNewickTree()
107   {
108     return newickTree;
109   }
110
111   public void setNewickTree(NewickFile newNewickTree)
112   {
113     this.newickTree = newNewickTree;
114   }
115
116   public static NewickFile treeToNewick(TreeModel tree)
117   {
118     NewickFile newickTree = new NewickFile(tree.getTopNode(),
119             tree.hasBootstrap(), tree.hasDistances(),
120             tree.hasRootDistance());
121       /*     System.out.println(newickTree.print(tree.hasBootstrap(),
122              tree.hasDistances(), tree.hasRootDistance()));
123       
124            System.out.println(newickTree.print(newickTree.hasBootstrap(),
125              newickTree.hasDistances(), newickTree.hasRootDistance()));*/
126
127     return newickTree;
128   }
129
130 }