1 /*******************************************************************************
2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) 2017 The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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 *******************************************************************************/
22 package jalview.ext.archaeopteryx;
24 import jalview.analysis.TreeModel;
25 import jalview.io.NewickFile;
28 import java.io.FileNotFoundException;
29 import java.io.IOException;
30 import java.io.PrintWriter;
32 import org.forester.archaeopteryx.Archaeopteryx;
34 public class ArchaeopteryxInit
36 private String filePath = "/tmp/jalviewtree.nwk";
38 private TreeModel tree;
40 private NewickFile newickTree;
42 public ArchaeopteryxInit(TreeModel jalviewTreeModel)
44 this.tree = jalviewTreeModel;
45 this.newickTree = treeToNewick(tree);
48 public ArchaeopteryxInit(NewickFile newickTreeModel)
50 this.newickTree = newickTreeModel;
53 public void startArchaeopteryx()
55 String newickOutput = newickTree.print(newickTree.hasBootstrap(),
56 newickTree.hasDistances(), newickTree.hasRootDistance());
58 File newickFile = new File(filePath);
63 writer = new PrintWriter(newickFile);
64 writer.println(newickOutput);
66 // System.out.println(writer.checkError());
69 String[] commandLineArgs = { "-open", newickFile.getCanonicalPath() };
70 Archaeopteryx.main(commandLineArgs);
72 } catch (FileNotFoundException e)
74 // TODO Auto-generated catch block
76 } catch (IOException e)
78 // TODO Auto-generated catch block
86 public String getFilePath()
91 public void setFilePath(String newFilePath)
93 this.filePath = newFilePath;
96 public TreeModel getTree()
101 public void setTree(TreeModel newTree)
106 public NewickFile getNewickTree()
111 public void setNewickTree(NewickFile newNewickTree)
113 this.newickTree = newNewickTree;
116 public static NewickFile treeToNewick(TreeModel tree)
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()));
124 System.out.println(newickTree.print(newickTree.hasBootstrap(),
125 newickTree.hasDistances(), newickTree.hasRootDistance()));*/