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 public class TreeParser // implements ExternalTreeParserI<MainFrame>
17 private final String filePath;
19 private final File file;
21 public TreeParser(final String treeFilePath)
24 filePath = treeFilePath;
25 file = new File(filePath);
29 public TreeParser(final File treeFile) throws IOException
32 filePath = file.getCanonicalPath();
35 public void loadTree(AlignViewport viewport)
38 NewickFile fin = null; // old tree
41 AptxInit.createInstancesFromFile(filePath, viewport);
43 fin = new NewickFile(filePath, DataSourceType.FILE);
44 viewport.setCurrentTree(viewport.getAlignPanel().alignFrame
45 .showNewickTree(fin, filePath).getTree());
47 } catch (Exception ex)
49 JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
50 MessageManager.getString("label.problem_reading_tree_file"),
51 JvOptionPane.WARNING_MESSAGE);
54 if (fin != null && fin.hasWarningMessage())
56 JvOptionPane.showMessageDialog(Desktop.desktop,
57 fin.getWarningMessage(),
59 .getString("label.possible_problem_with_tree_file"),
60 JvOptionPane.WARNING_MESSAGE);
68 // public MainFrame loadTreeFile(AlignmentViewport viewport)
70 // String[] AptxArgs = new String[] { "-c",
71 // "_aptx_jalview_configuration_file", filePath };
72 // MainFrame aptx = Archaeopteryx.main(AptxArgs);
74 // LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
75 // viewport.getAlignment().getSequencesArray(),
76 // aptx.getMainPanel().getCurrentTreePanel().getPhylogeny());
78 // bindAptxNodes.associateLeavesToSequences();
80 // new JalviewBinding(aptx, viewport, bindAptxNodes.getAlignmentWithNodes(),
81 // bindAptxNodes.getNodesWithAlignment());
83 // AptxInit.bindFrameToJalview(aptx);
90 // void readPhylogeniesFromURL() {
92 // Phylogeny[] phys = null;
93 // final String message = "Please enter a complete URL, for example
94 // \"http://purl.org/phylo/treebase/phylows/study/TB2:S15480?format=nexus\"";
95 // final String url_string = JOptionPane
96 // .showInputDialog( this,
98 // "Use URL/webservice to obtain a phylogeny",
99 // JOptionPane.QUESTION_MESSAGE );
100 // boolean nhx_or_nexus = false;
101 // if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
103 // url = new URL( url_string );
104 // PhylogenyParser parser = null;
105 // if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
106 // parser = new TolParser();
109 // parser = ParserUtils
110 // .createParserDependingOnUrlContents( url,
111 // getConfiguration().isValidatePhyloXmlAgainstSchema() );
113 // if ( parser instanceof NexusPhylogeniesParser ) {
114 // nhx_or_nexus = true;
116 // else if ( parser instanceof NHXParser ) {
117 // nhx_or_nexus = true;
119 // if ( _mainpanel.getCurrentTreePanel() != null ) {
120 // _mainpanel.getCurrentTreePanel().setWaitCursor();
123 // _mainpanel.setWaitCursor();
125 // final PhylogenyFactory factory =
126 // ParserBasedPhylogenyFactory.getInstance();
127 // phys = factory.create( url.openStream(), parser );
129 // catch ( final MalformedURLException e ) {
130 // JOptionPane.showMessageDialog( this,
131 // "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
133 // JOptionPane.ERROR_MESSAGE );
135 // catch ( final IOException e ) {
136 // JOptionPane.showMessageDialog( this,
137 // "Could not read from " + url + "\n"
138 // + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
139 // "Failed to read URL",
140 // JOptionPane.ERROR_MESSAGE );
142 // catch ( final Exception e ) {
143 // JOptionPane.showMessageDialog( this,
144 // ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
145 // "Unexpected Exception",
146 // JOptionPane.ERROR_MESSAGE );
149 // if ( _mainpanel.getCurrentTreePanel() != null ) {
150 // _mainpanel.getCurrentTreePanel().setArrowCursor();
153 // _mainpanel.setArrowCursor();
156 // if ( ( phys != null ) && ( phys.length > 0 ) ) {
157 // if ( nhx_or_nexus &&
158 // getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
159 // for( final Phylogeny phy : phys ) {
160 // PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" );
163 // AptxUtil.addPhylogeniesToTabs( phys,
164 // new File( url.getFile() ).getName(),
165 // new File( url.getFile() ).toString(),
166 // getConfiguration(),
168 // _mainpanel.getControlPanel().showWhole();
171 // activateSaveAllIfNeeded();