package jalview.ext.forester.io; import jalview.ext.archaeopteryx.JalviewBinding; import jalview.ext.archaeopteryx.LoadedTreeAssociation; import jalview.ext.archaeopteryx.ArchaeopteryxInit; import jalview.ext.treeviewer.ExternalTreeParserI; import jalview.gui.Desktop; import jalview.gui.JvOptionPane; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; import java.io.File; import java.io.IOException; import org.forester.archaeopteryx.Archaeopteryx; import org.forester.archaeopteryx.MainFrame; import org.forester.util.ForesterUtil; public class TreeParser implements ExternalTreeParserI { private final String filePath; private final File file; public TreeParser(final String treeFilePath) { final String possibleError = ForesterUtil.isReadableFile(treeFilePath); if (possibleError != null) { JvOptionPane.showMessageDialog(Desktop.desktop, possibleError, MessageManager.getString("label.problem_reading_tree_file"), JvOptionPane.WARNING_MESSAGE); } filePath = treeFilePath; file = new File(filePath); } public TreeParser(final File treeFile) throws IOException { final String possibleError = ForesterUtil.isReadableFile(treeFile); if (possibleError != null) { JvOptionPane.showMessageDialog(Desktop.desktop, possibleError, MessageManager.getString("label.problem_reading_tree_file"), JvOptionPane.WARNING_MESSAGE); } file = treeFile; filePath = file.getCanonicalPath(); } @Override public MainFrame loadTree(AlignmentViewport viewport) { String[] AptxArgs = new String[] { "-c", "_aptx_jalview_configuration_file", filePath }; MainFrame aptx = Archaeopteryx.main(AptxArgs); LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation( viewport.getAlignment().getSequencesArray(), aptx.getMainPanel().getCurrentTreePanel().getPhylogeny()); bindAptxNodes.associateLeavesToSequences(); new JalviewBinding(aptx, viewport, bindAptxNodes.getAlignmentWithNodes(), bindAptxNodes.getNodesWithAlignment()); ArchaeopteryxInit.bindFrameToJalview(aptx); return aptx; } }