1 package jalview.ext.forester.io;
3 import jalview.ext.archaeopteryx.AptxBinding;
4 import jalview.ext.archaeopteryx.AptxNodeAssociation;
5 import jalview.ext.archaeopteryx.ArchaeopteryxInit;
6 import jalview.gui.Desktop;
7 import jalview.gui.JvOptionPane;
8 import jalview.util.MessageManager;
9 import jalview.viewmodel.AlignmentViewport;
12 import java.io.IOException;
14 import org.forester.archaeopteryx.Archaeopteryx;
15 import org.forester.archaeopteryx.MainFrame;
16 import org.forester.util.ForesterUtil;
18 public class ForesterTreeParser implements ExternalTreeParserI<MainFrame>
20 private final String filePath;
22 private final File file;
24 public ForesterTreeParser(final String treeFilePath)
26 final String possibleError = ForesterUtil.isReadableFile(treeFilePath);
27 if (possibleError != null)
29 JvOptionPane.showMessageDialog(Desktop.desktop, possibleError,
30 MessageManager.getString("label.problem_reading_tree_file"),
31 JvOptionPane.WARNING_MESSAGE);
34 filePath = treeFilePath;
35 file = new File(filePath);
40 public ForesterTreeParser(final File treeFile) throws IOException
42 final String possibleError = ForesterUtil.isReadableFile(treeFile);
43 if (possibleError != null)
45 JvOptionPane.showMessageDialog(Desktop.desktop, possibleError,
46 MessageManager.getString("label.problem_reading_tree_file"),
47 JvOptionPane.WARNING_MESSAGE);
51 filePath = file.getCanonicalPath();
55 public MainFrame loadTreeFile(AlignmentViewport viewport)
57 String[] AptxArgs = new String[] { "-c",
58 "_aptx_jalview_configuration_file", filePath };
59 MainFrame aptx = Archaeopteryx.main(AptxArgs);
61 AptxNodeAssociation bindAptxNodes = new AptxNodeAssociation(
62 viewport.getAlignment().getSequencesArray(),
63 aptx.getMainPanel().getCurrentTreePanel().getPhylogeny());
65 bindAptxNodes.associateLeavesToSequences();
66 new AptxBinding(aptx, viewport, bindAptxNodes.getAlignmentWithNodes(),
67 bindAptxNodes.getNodesWithAlignment());
69 ArchaeopteryxInit.bindFrameToJalview(aptx);
76 // void readPhylogeniesFromURL() {
78 // Phylogeny[] phys = null;
79 // final String message = "Please enter a complete URL, for example
80 // \"http://purl.org/phylo/treebase/phylows/study/TB2:S15480?format=nexus\"";
81 // final String url_string = JOptionPane
82 // .showInputDialog( this,
84 // "Use URL/webservice to obtain a phylogeny",
85 // JOptionPane.QUESTION_MESSAGE );
86 // boolean nhx_or_nexus = false;
87 // if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
89 // url = new URL( url_string );
90 // PhylogenyParser parser = null;
91 // if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
92 // parser = new TolParser();
95 // parser = ParserUtils
96 // .createParserDependingOnUrlContents( url,
97 // getConfiguration().isValidatePhyloXmlAgainstSchema() );
99 // if ( parser instanceof NexusPhylogeniesParser ) {
100 // nhx_or_nexus = true;
102 // else if ( parser instanceof NHXParser ) {
103 // nhx_or_nexus = true;
105 // if ( _mainpanel.getCurrentTreePanel() != null ) {
106 // _mainpanel.getCurrentTreePanel().setWaitCursor();
109 // _mainpanel.setWaitCursor();
111 // final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
112 // phys = factory.create( url.openStream(), parser );
114 // catch ( final MalformedURLException e ) {
115 // JOptionPane.showMessageDialog( this,
116 // "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
118 // JOptionPane.ERROR_MESSAGE );
120 // catch ( final IOException e ) {
121 // JOptionPane.showMessageDialog( this,
122 // "Could not read from " + url + "\n"
123 // + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
124 // "Failed to read URL",
125 // JOptionPane.ERROR_MESSAGE );
127 // catch ( final Exception e ) {
128 // JOptionPane.showMessageDialog( this,
129 // ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
130 // "Unexpected Exception",
131 // JOptionPane.ERROR_MESSAGE );
134 // if ( _mainpanel.getCurrentTreePanel() != null ) {
135 // _mainpanel.getCurrentTreePanel().setArrowCursor();
138 // _mainpanel.setArrowCursor();
141 // if ( ( phys != null ) && ( phys.length > 0 ) ) {
142 // if ( nhx_or_nexus &&
143 // getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
144 // for( final Phylogeny phy : phys ) {
145 // PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" );
148 // AptxUtil.addPhylogeniesToTabs( phys,
149 // new File( url.getFile() ).getName(),
150 // new File( url.getFile() ).toString(),
151 // getConfiguration(),
153 // _mainpanel.getControlPanel().showWhole();
156 // activateSaveAllIfNeeded();