1 package jalview.ext.forester.io;
3 import jalview.ext.archaeopteryx.JalviewBinding;
4 import jalview.ext.archaeopteryx.LoadedTreeAssociation;
5 import jalview.ext.archaeopteryx.ArchaeopteryxInit;
6 import jalview.ext.treeviewer.ExternalTreeParserI;
7 import jalview.gui.Desktop;
8 import jalview.gui.JvOptionPane;
9 import jalview.util.MessageManager;
10 import jalview.viewmodel.AlignmentViewport;
13 import java.io.IOException;
15 import org.forester.archaeopteryx.Archaeopteryx;
16 import org.forester.archaeopteryx.MainFrame;
17 import org.forester.util.ForesterUtil;
19 public class TreeParser implements ExternalTreeParserI<MainFrame>
21 private final String filePath;
23 private final File file;
25 public TreeParser(final String treeFilePath)
27 final String possibleError = ForesterUtil.isReadableFile(treeFilePath);
28 if (possibleError != null)
30 JvOptionPane.showMessageDialog(Desktop.desktop, possibleError,
31 MessageManager.getString("label.problem_reading_tree_file"),
32 JvOptionPane.WARNING_MESSAGE);
35 filePath = treeFilePath;
36 file = new File(filePath);
41 public TreeParser(final File treeFile) throws IOException
43 final String possibleError = ForesterUtil.isReadableFile(treeFile);
44 if (possibleError != null)
46 JvOptionPane.showMessageDialog(Desktop.desktop, possibleError,
47 MessageManager.getString("label.problem_reading_tree_file"),
48 JvOptionPane.WARNING_MESSAGE);
52 filePath = file.getCanonicalPath();
56 public MainFrame loadTree(AlignmentViewport viewport)
58 String[] AptxArgs = new String[] { "-c",
59 "_aptx_jalview_configuration_file", filePath };
60 MainFrame aptx = Archaeopteryx.main(AptxArgs);
62 LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
63 viewport.getAlignment().getSequencesArray(),
64 aptx.getMainPanel().getCurrentTreePanel().getPhylogeny());
66 bindAptxNodes.associateLeavesToSequences();
67 new JalviewBinding(aptx, viewport, bindAptxNodes.getAlignmentWithNodes(),
68 bindAptxNodes.getNodesWithAlignment());
70 ArchaeopteryxInit.bindFrameToJalview(aptx);