1 package jalview.ext.forester.io;
3 import jalview.ext.archaeopteryx.AptxInit;
4 import jalview.gui.AlignViewport;
5 //import jalview.ext.treeviewer.ExternalTreeParserI;
6 import jalview.gui.Desktop;
7 import jalview.gui.JvOptionPane;
8 import jalview.io.DataSourceType;
9 import jalview.io.NewickFile;
10 import jalview.util.MessageManager;
13 import java.io.IOException;
15 import org.forester.util.ForesterUtil;
17 public class TreeParser // implements ExternalTreeParserI<MainFrame>
19 private final String filePath;
21 private final File file;
23 public TreeParser(final String treeFilePath)
25 final String possibleError = ForesterUtil.isReadableFile(treeFilePath);
26 if (possibleError != null)
28 JvOptionPane.showMessageDialog(Desktop.desktop, possibleError,
29 MessageManager.getString("label.problem_reading_tree_file"),
30 JvOptionPane.WARNING_MESSAGE);
33 filePath = treeFilePath;
34 file = new File(filePath);
38 public TreeParser(final File treeFile) throws IOException
40 final String possibleError = ForesterUtil.isReadableFile(treeFile);
41 if (possibleError != null)
43 JvOptionPane.showMessageDialog(Desktop.desktop, possibleError,
44 MessageManager.getString("label.problem_reading_tree_file"),
45 JvOptionPane.WARNING_MESSAGE);
49 filePath = file.getCanonicalPath();
52 public void loadTree(AlignViewport viewport)
55 NewickFile fin = null; // old tree
58 AptxInit.createInstanceFromFile(filePath, viewport);
60 fin = new NewickFile(filePath, DataSourceType.FILE);
61 viewport.setCurrentTree(viewport.getAlignPanel().alignFrame
62 .showNewickTree(fin, filePath).getTree());
64 } catch (Exception ex)
66 JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
67 MessageManager.getString("label.problem_reading_tree_file"),
68 JvOptionPane.WARNING_MESSAGE);
71 if (fin != null && fin.hasWarningMessage())
73 JvOptionPane.showMessageDialog(Desktop.desktop,
74 fin.getWarningMessage(),
76 .getString("label.possible_problem_with_tree_file"),
77 JvOptionPane.WARNING_MESSAGE);
85 // public MainFrame loadTreeFile(AlignmentViewport viewport)
87 // String[] AptxArgs = new String[] { "-c",
88 // "_aptx_jalview_configuration_file", filePath };
89 // MainFrame aptx = Archaeopteryx.main(AptxArgs);
91 // LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
92 // viewport.getAlignment().getSequencesArray(),
93 // aptx.getMainPanel().getCurrentTreePanel().getPhylogeny());
95 // bindAptxNodes.associateLeavesToSequences();
97 // new JalviewBinding(aptx, viewport, bindAptxNodes.getAlignmentWithNodes(),
98 // bindAptxNodes.getNodesWithAlignment());
100 // AptxInit.bindFrameToJalview(aptx);
107 // void readPhylogeniesFromURL() {
109 // Phylogeny[] phys = null;
110 // final String message = "Please enter a complete URL, for example
111 // \"http://purl.org/phylo/treebase/phylows/study/TB2:S15480?format=nexus\"";
112 // final String url_string = JOptionPane
113 // .showInputDialog( this,
115 // "Use URL/webservice to obtain a phylogeny",
116 // JOptionPane.QUESTION_MESSAGE );
117 // boolean nhx_or_nexus = false;
118 // if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
120 // url = new URL( url_string );
121 // PhylogenyParser parser = null;
122 // if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
123 // parser = new TolParser();
126 // parser = ParserUtils
127 // .createParserDependingOnUrlContents( url,
128 // getConfiguration().isValidatePhyloXmlAgainstSchema() );
130 // if ( parser instanceof NexusPhylogeniesParser ) {
131 // nhx_or_nexus = true;
133 // else if ( parser instanceof NHXParser ) {
134 // nhx_or_nexus = true;
136 // if ( _mainpanel.getCurrentTreePanel() != null ) {
137 // _mainpanel.getCurrentTreePanel().setWaitCursor();
140 // _mainpanel.setWaitCursor();
142 // final PhylogenyFactory factory =
143 // ParserBasedPhylogenyFactory.getInstance();
144 // phys = factory.create( url.openStream(), parser );
146 // catch ( final MalformedURLException e ) {
147 // JOptionPane.showMessageDialog( this,
148 // "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
150 // JOptionPane.ERROR_MESSAGE );
152 // catch ( final IOException e ) {
153 // JOptionPane.showMessageDialog( this,
154 // "Could not read from " + url + "\n"
155 // + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
156 // "Failed to read URL",
157 // JOptionPane.ERROR_MESSAGE );
159 // catch ( final Exception e ) {
160 // JOptionPane.showMessageDialog( this,
161 // ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
162 // "Unexpected Exception",
163 // JOptionPane.ERROR_MESSAGE );
166 // if ( _mainpanel.getCurrentTreePanel() != null ) {
167 // _mainpanel.getCurrentTreePanel().setArrowCursor();
170 // _mainpanel.setArrowCursor();
173 // if ( ( phys != null ) && ( phys.length > 0 ) ) {
174 // if ( nhx_or_nexus &&
175 // getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
176 // for( final Phylogeny phy : phys ) {
177 // PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" );
180 // AptxUtil.addPhylogeniesToTabs( phys,
181 // new File( url.getFile() ).getName(),
182 // new File( url.getFile() ).toString(),
183 // getConfiguration(),
185 // _mainpanel.getControlPanel().showWhole();
188 // activateSaveAllIfNeeded();