cbdc3e8c36a55360da89b035ebd529cce4e34490
[jalview.git] / src / jalview / ext / forester / io / TreeParser.java
1 package jalview.ext.forester.io;
2
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;
10
11 import java.io.File;
12 import java.io.IOException;
13
14 public class TreeParser // implements ExternalTreeParserI<MainFrame>
15 {
16   private final String filePath;
17
18   private final File file;
19
20   public TreeParser(final String treeFilePath)
21   {
22
23     filePath = treeFilePath;
24     file = new File(filePath);
25
26   }
27
28   public TreeParser(final File treeFile) throws IOException
29   {
30     file = treeFile;
31     filePath = file.getCanonicalPath();
32   }
33
34   public void loadTree(AlignViewport viewport)
35   {
36
37     NewickFile fin = null; // old tree
38       try
39       {
40         AptxInit.createInstancesFromFile(filePath, viewport);
41
42       // fin = new NewickFile(filePath, DataSourceType.FILE);
43       // viewport.setCurrentTree(viewport.getAlignPanel().alignFrame
44       // .showNewickTree(fin, filePath).getTree());
45
46       } catch (Exception ex)
47       {
48         JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
49                 MessageManager.getString("label.problem_reading_tree_file"),
50                 JvOptionPane.WARNING_MESSAGE);
51         ex.printStackTrace();
52       }
53     // if (fin != null && fin.hasWarningMessage())
54     // {
55     // JvOptionPane.showMessageDialog(Desktop.desktop,
56     // fin.getWarningMessage(),
57     // MessageManager
58     // .getString("label.possible_problem_with_tree_file"),
59     // JvOptionPane.WARNING_MESSAGE);
60     // }
61     }
62   }
63
64
65 //
66 // @Override
67 // public MainFrame loadTreeFile(AlignmentViewport viewport)
68 // {
69 // String[] AptxArgs = new String[] { "-c",
70 // "_aptx_jalview_configuration_file", filePath };
71 // MainFrame aptx = Archaeopteryx.main(AptxArgs);
72 //
73 // LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
74 // viewport.getAlignment().getSequencesArray(),
75 // aptx.getMainPanel().getCurrentTreePanel().getPhylogeny());
76 //
77 // bindAptxNodes.associateLeavesToSequences();
78 //
79 // new JalviewBinding(aptx, viewport, bindAptxNodes.getAlignmentWithNodes(),
80 // bindAptxNodes.getNodesWithAlignment());
81 //
82 // AptxInit.bindFrameToJalview(aptx);
83 //
84 // return aptx;
85 //
86 //
87 // }
88 // //
89 // void readPhylogeniesFromURL() {
90 // URL url = null;
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,
96 // message,
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 ) ) {
101 // try {
102 // url = new URL( url_string );
103 // PhylogenyParser parser = null;
104 // if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
105 // parser = new TolParser();
106 // }
107 // else {
108 // parser = ParserUtils
109 // .createParserDependingOnUrlContents( url,
110 // getConfiguration().isValidatePhyloXmlAgainstSchema() );
111 // }
112 // if ( parser instanceof NexusPhylogeniesParser ) {
113 // nhx_or_nexus = true;
114 // }
115 // else if ( parser instanceof NHXParser ) {
116 // nhx_or_nexus = true;
117 // }
118 // if ( _mainpanel.getCurrentTreePanel() != null ) {
119 // _mainpanel.getCurrentTreePanel().setWaitCursor();
120 // }
121 // else {
122 // _mainpanel.setWaitCursor();
123 // }
124 // final PhylogenyFactory factory =
125 // ParserBasedPhylogenyFactory.getInstance();
126 // phys = factory.create( url.openStream(), parser );
127 // }
128 // catch ( final MalformedURLException e ) {
129 // JOptionPane.showMessageDialog( this,
130 // "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
131 // "Malformed URL",
132 // JOptionPane.ERROR_MESSAGE );
133 // }
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 );
140 // }
141 // catch ( final Exception e ) {
142 // JOptionPane.showMessageDialog( this,
143 // ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
144 // "Unexpected Exception",
145 // JOptionPane.ERROR_MESSAGE );
146 // }
147 // finally {
148 // if ( _mainpanel.getCurrentTreePanel() != null ) {
149 // _mainpanel.getCurrentTreePanel().setArrowCursor();
150 // }
151 // else {
152 // _mainpanel.setArrowCursor();
153 // }
154 // }
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, "" );
160 // }
161 // }
162 // AptxUtil.addPhylogeniesToTabs( phys,
163 // new File( url.getFile() ).getName(),
164 // new File( url.getFile() ).toString(),
165 // getConfiguration(),
166 // getMainPanel() );
167 // _mainpanel.getControlPanel().showWhole();
168 // }
169 // }
170 // activateSaveAllIfNeeded();
171 // System.gc();
172 // }
173 //
174 // }
175 //
176 //
177 //
178 //
179 //
180 //