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.NewickFile;
9 import jalview.util.MessageManager;
12 import java.io.IOException;
14 public class TreeParser // implements ExternalTreeParserI<MainFrame>
16 private final String filePath;
18 private final File file;
20 public TreeParser(final String treeFilePath)
23 filePath = treeFilePath;
24 file = new File(filePath);
28 public TreeParser(final File treeFile) throws IOException
31 filePath = file.getCanonicalPath();
34 public void loadTree(AlignViewport viewport)
37 NewickFile fin = null; // old tree
40 AptxInit.createInstancesFromFile(filePath, viewport);
42 // fin = new NewickFile(filePath, DataSourceType.FILE);
43 // viewport.setCurrentTree(viewport.getAlignPanel().alignFrame
44 // .showNewickTree(fin, filePath).getTree());
46 } catch (Exception ex)
48 JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
49 MessageManager.getString("label.problem_reading_tree_file"),
50 JvOptionPane.WARNING_MESSAGE);
53 // if (fin != null && fin.hasWarningMessage())
55 // JvOptionPane.showMessageDialog(Desktop.desktop,
56 // fin.getWarningMessage(),
58 // .getString("label.possible_problem_with_tree_file"),
59 // JvOptionPane.WARNING_MESSAGE);
67 // public MainFrame loadTreeFile(AlignmentViewport viewport)
69 // String[] AptxArgs = new String[] { "-c",
70 // "_aptx_jalview_configuration_file", filePath };
71 // MainFrame aptx = Archaeopteryx.main(AptxArgs);
73 // LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
74 // viewport.getAlignment().getSequencesArray(),
75 // aptx.getMainPanel().getCurrentTreePanel().getPhylogeny());
77 // bindAptxNodes.associateLeavesToSequences();
79 // new JalviewBinding(aptx, viewport, bindAptxNodes.getAlignmentWithNodes(),
80 // bindAptxNodes.getNodesWithAlignment());
82 // AptxInit.bindFrameToJalview(aptx);
89 // void readPhylogeniesFromURL() {
91 // Phylogeny[] phys = null;
92 // final String message = "Please enter a complete URL, for example
93 // \"http://purl.org/phylo/treebase/phylows/study/TB2:S15480?format=nexus\"";
94 // final String url_string = JOptionPane
95 // .showInputDialog( this,
97 // "Use URL/webservice to obtain a phylogeny",
98 // JOptionPane.QUESTION_MESSAGE );
99 // boolean nhx_or_nexus = false;
100 // if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
102 // url = new URL( url_string );
103 // PhylogenyParser parser = null;
104 // if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
105 // parser = new TolParser();
108 // parser = ParserUtils
109 // .createParserDependingOnUrlContents( url,
110 // getConfiguration().isValidatePhyloXmlAgainstSchema() );
112 // if ( parser instanceof NexusPhylogeniesParser ) {
113 // nhx_or_nexus = true;
115 // else if ( parser instanceof NHXParser ) {
116 // nhx_or_nexus = true;
118 // if ( _mainpanel.getCurrentTreePanel() != null ) {
119 // _mainpanel.getCurrentTreePanel().setWaitCursor();
122 // _mainpanel.setWaitCursor();
124 // final PhylogenyFactory factory =
125 // ParserBasedPhylogenyFactory.getInstance();
126 // phys = factory.create( url.openStream(), parser );
128 // catch ( final MalformedURLException e ) {
129 // JOptionPane.showMessageDialog( this,
130 // "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
132 // JOptionPane.ERROR_MESSAGE );
134 // catch ( final IOException e ) {
135 // JOptionPane.showMessageDialog( this,
136 // "Could not read from " + url + "\n"
137 // + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
138 // "Failed to read URL",
139 // JOptionPane.ERROR_MESSAGE );
141 // catch ( final Exception e ) {
142 // JOptionPane.showMessageDialog( this,
143 // ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
144 // "Unexpected Exception",
145 // JOptionPane.ERROR_MESSAGE );
148 // if ( _mainpanel.getCurrentTreePanel() != null ) {
149 // _mainpanel.getCurrentTreePanel().setArrowCursor();
152 // _mainpanel.setArrowCursor();
155 // if ( ( phys != null ) && ( phys.length > 0 ) ) {
156 // if ( nhx_or_nexus &&
157 // getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
158 // for( final Phylogeny phy : phys ) {
159 // PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" );
162 // AptxUtil.addPhylogeniesToTabs( phys,
163 // new File( url.getFile() ).getName(),
164 // new File( url.getFile() ).toString(),
165 // getConfiguration(),
167 // _mainpanel.getControlPanel().showWhole();
170 // activateSaveAllIfNeeded();