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;
58 AptxInit.createInstanceFromFile(filePath, viewport);
60 fin = new NewickFile(filePath, DataSourceType.FILE);
61 viewport.setCurrentTree(viewport.getAlignPanel().alignFrame
62 .showNewickTree(fin, filePath).getTree());
63 } catch (Exception ex)
65 JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
66 MessageManager.getString("label.problem_reading_tree_file"),
67 JvOptionPane.WARNING_MESSAGE);
70 if (fin != null && fin.hasWarningMessage())
72 JvOptionPane.showMessageDialog(Desktop.desktop,
73 fin.getWarningMessage(),
75 .getString("label.possible_problem_with_tree_file"),
76 JvOptionPane.WARNING_MESSAGE);
84 // public MainFrame loadTreeFile(AlignmentViewport viewport)
86 // String[] AptxArgs = new String[] { "-c",
87 // "_aptx_jalview_configuration_file", filePath };
88 // MainFrame aptx = Archaeopteryx.main(AptxArgs);
90 // LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
91 // viewport.getAlignment().getSequencesArray(),
92 // aptx.getMainPanel().getCurrentTreePanel().getPhylogeny());
94 // bindAptxNodes.associateLeavesToSequences();
96 // new JalviewBinding(aptx, viewport, bindAptxNodes.getAlignmentWithNodes(),
97 // bindAptxNodes.getNodesWithAlignment());
99 // AptxInit.bindFrameToJalview(aptx);
106 // void readPhylogeniesFromURL() {
108 // Phylogeny[] phys = null;
109 // final String message = "Please enter a complete URL, for example
110 // \"http://purl.org/phylo/treebase/phylows/study/TB2:S15480?format=nexus\"";
111 // final String url_string = JOptionPane
112 // .showInputDialog( this,
114 // "Use URL/webservice to obtain a phylogeny",
115 // JOptionPane.QUESTION_MESSAGE );
116 // boolean nhx_or_nexus = false;
117 // if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
119 // url = new URL( url_string );
120 // PhylogenyParser parser = null;
121 // if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
122 // parser = new TolParser();
125 // parser = ParserUtils
126 // .createParserDependingOnUrlContents( url,
127 // getConfiguration().isValidatePhyloXmlAgainstSchema() );
129 // if ( parser instanceof NexusPhylogeniesParser ) {
130 // nhx_or_nexus = true;
132 // else if ( parser instanceof NHXParser ) {
133 // nhx_or_nexus = true;
135 // if ( _mainpanel.getCurrentTreePanel() != null ) {
136 // _mainpanel.getCurrentTreePanel().setWaitCursor();
139 // _mainpanel.setWaitCursor();
141 // final PhylogenyFactory factory =
142 // ParserBasedPhylogenyFactory.getInstance();
143 // phys = factory.create( url.openStream(), parser );
145 // catch ( final MalformedURLException e ) {
146 // JOptionPane.showMessageDialog( this,
147 // "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
149 // JOptionPane.ERROR_MESSAGE );
151 // catch ( final IOException e ) {
152 // JOptionPane.showMessageDialog( this,
153 // "Could not read from " + url + "\n"
154 // + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
155 // "Failed to read URL",
156 // JOptionPane.ERROR_MESSAGE );
158 // catch ( final Exception e ) {
159 // JOptionPane.showMessageDialog( this,
160 // ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
161 // "Unexpected Exception",
162 // JOptionPane.ERROR_MESSAGE );
165 // if ( _mainpanel.getCurrentTreePanel() != null ) {
166 // _mainpanel.getCurrentTreePanel().setArrowCursor();
169 // _mainpanel.setArrowCursor();
172 // if ( ( phys != null ) && ( phys.length > 0 ) ) {
173 // if ( nhx_or_nexus &&
174 // getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
175 // for( final Phylogeny phy : phys ) {
176 // PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" );
179 // AptxUtil.addPhylogeniesToTabs( phys,
180 // new File( url.getFile() ).getName(),
181 // new File( url.getFile() ).toString(),
182 // getConfiguration(),
184 // _mainpanel.getControlPanel().showWhole();
187 // activateSaveAllIfNeeded();