1 package jalview.ext.forester.io;
3 import jalview.ext.archaeopteryx.AptxInit;
4 import jalview.ext.archaeopteryx.JalviewBinding;
5 import jalview.ext.archaeopteryx.LoadedTreeAssociation;
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 loadTreeFile(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();
68 new JalviewBinding(aptx, viewport, bindAptxNodes.getAlignmentWithNodes(),
69 bindAptxNodes.getNodesWithAlignment());
71 AptxInit.bindFrameToJalview(aptx);
78 // void readPhylogeniesFromURL() {
80 // Phylogeny[] phys = null;
81 // final String message = "Please enter a complete URL, for example
82 // \"http://purl.org/phylo/treebase/phylows/study/TB2:S15480?format=nexus\"";
83 // final String url_string = JOptionPane
84 // .showInputDialog( this,
86 // "Use URL/webservice to obtain a phylogeny",
87 // JOptionPane.QUESTION_MESSAGE );
88 // boolean nhx_or_nexus = false;
89 // if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
91 // url = new URL( url_string );
92 // PhylogenyParser parser = null;
93 // if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
94 // parser = new TolParser();
97 // parser = ParserUtils
98 // .createParserDependingOnUrlContents( url,
99 // getConfiguration().isValidatePhyloXmlAgainstSchema() );
101 // if ( parser instanceof NexusPhylogeniesParser ) {
102 // nhx_or_nexus = true;
104 // else if ( parser instanceof NHXParser ) {
105 // nhx_or_nexus = true;
107 // if ( _mainpanel.getCurrentTreePanel() != null ) {
108 // _mainpanel.getCurrentTreePanel().setWaitCursor();
111 // _mainpanel.setWaitCursor();
113 // final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
114 // phys = factory.create( url.openStream(), parser );
116 // catch ( final MalformedURLException e ) {
117 // JOptionPane.showMessageDialog( this,
118 // "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
120 // JOptionPane.ERROR_MESSAGE );
122 // catch ( final IOException e ) {
123 // JOptionPane.showMessageDialog( this,
124 // "Could not read from " + url + "\n"
125 // + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
126 // "Failed to read URL",
127 // JOptionPane.ERROR_MESSAGE );
129 // catch ( final Exception e ) {
130 // JOptionPane.showMessageDialog( this,
131 // ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
132 // "Unexpected Exception",
133 // JOptionPane.ERROR_MESSAGE );
136 // if ( _mainpanel.getCurrentTreePanel() != null ) {
137 // _mainpanel.getCurrentTreePanel().setArrowCursor();
140 // _mainpanel.setArrowCursor();
143 // if ( ( phys != null ) && ( phys.length > 0 ) ) {
144 // if ( nhx_or_nexus &&
145 // getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
146 // for( final Phylogeny phy : phys ) {
147 // PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" );
150 // AptxUtil.addPhylogeniesToTabs( phys,
151 // new File( url.getFile() ).getName(),
152 // new File( url.getFile() ).toString(),
153 // getConfiguration(),
155 // _mainpanel.getControlPanel().showWhole();
158 // activateSaveAllIfNeeded();