JAL-2805 couple of method name changes
[jalview.git] / src / jalview / ext / forester / io / ForesterTreeParser.java
1 package jalview.ext.forester.io;
2
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;
10
11 import java.io.File;
12 import java.io.IOException;
13
14 import org.forester.archaeopteryx.Archaeopteryx;
15 import org.forester.archaeopteryx.MainFrame;
16 import org.forester.util.ForesterUtil;
17
18 public class ForesterTreeParser implements ExternalTreeParserI<MainFrame>
19 {
20   private final String filePath;
21
22   private final File file;
23
24   public ForesterTreeParser(final String treeFilePath)
25   {
26     final String possibleError = ForesterUtil.isReadableFile(treeFilePath);
27     if (possibleError != null)
28     {
29       JvOptionPane.showMessageDialog(Desktop.desktop, possibleError,
30               MessageManager.getString("label.problem_reading_tree_file"),
31               JvOptionPane.WARNING_MESSAGE);
32
33     }
34     filePath = treeFilePath;
35     file = new File(filePath);
36
37
38   }
39
40   public ForesterTreeParser(final File treeFile) throws IOException
41   {
42     final String possibleError = ForesterUtil.isReadableFile(treeFile);
43     if (possibleError != null)
44     {
45       JvOptionPane.showMessageDialog(Desktop.desktop, possibleError,
46               MessageManager.getString("label.problem_reading_tree_file"),
47               JvOptionPane.WARNING_MESSAGE);
48
49     }
50     file = treeFile;
51     filePath = file.getCanonicalPath();
52   }
53
54   @Override
55   public MainFrame loadTreeFile(AlignmentViewport viewport)
56   {
57     String[] AptxArgs = new String[] { "-c",
58         "_aptx_jalview_configuration_file", filePath };
59     MainFrame aptx = Archaeopteryx.main(AptxArgs);
60
61     AptxNodeAssociation bindAptxNodes = new AptxNodeAssociation(
62             viewport.getAlignment().getSequencesArray(),
63             aptx.getMainPanel().getCurrentTreePanel().getPhylogeny());
64
65     bindAptxNodes.associateLeavesToSequences();
66     new AptxBinding(aptx, viewport, bindAptxNodes.getAlignmentWithNodes(),
67             bindAptxNodes.getNodesWithAlignment());
68
69     ArchaeopteryxInit.bindFrameToJalview(aptx);
70
71     return aptx;
72
73
74   }
75   //
76   // void readPhylogeniesFromURL() {
77   // URL url = null;
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,
83   // message,
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 ) ) {
88   // try {
89   // url = new URL( url_string );
90   // PhylogenyParser parser = null;
91   // if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
92   // parser = new TolParser();
93   // }
94   // else {
95   // parser = ParserUtils
96   // .createParserDependingOnUrlContents( url,
97   // getConfiguration().isValidatePhyloXmlAgainstSchema() );
98   // }
99   // if ( parser instanceof NexusPhylogeniesParser ) {
100   // nhx_or_nexus = true;
101   // }
102   // else if ( parser instanceof NHXParser ) {
103   // nhx_or_nexus = true;
104   // }
105   // if ( _mainpanel.getCurrentTreePanel() != null ) {
106   // _mainpanel.getCurrentTreePanel().setWaitCursor();
107   // }
108   // else {
109   // _mainpanel.setWaitCursor();
110   // }
111   // final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
112   // phys = factory.create( url.openStream(), parser );
113   // }
114   // catch ( final MalformedURLException e ) {
115   // JOptionPane.showMessageDialog( this,
116   // "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
117   // "Malformed URL",
118   // JOptionPane.ERROR_MESSAGE );
119   // }
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 );
126   // }
127   // catch ( final Exception e ) {
128   // JOptionPane.showMessageDialog( this,
129   // ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
130   // "Unexpected Exception",
131   // JOptionPane.ERROR_MESSAGE );
132   // }
133   // finally {
134   // if ( _mainpanel.getCurrentTreePanel() != null ) {
135   // _mainpanel.getCurrentTreePanel().setArrowCursor();
136   // }
137   // else {
138   // _mainpanel.setArrowCursor();
139   // }
140   // }
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, "" );
146   // }
147   // }
148   // AptxUtil.addPhylogeniesToTabs( phys,
149   // new File( url.getFile() ).getName(),
150   // new File( url.getFile() ).toString(),
151   // getConfiguration(),
152   // getMainPanel() );
153   // _mainpanel.getControlPanel().showWhole();
154   // }
155   // }
156   // activateSaveAllIfNeeded();
157   // System.gc();
158   // }
159
160 }
161
162
163
164
165
166