1 package jalview.ext.archaeopteryx;
3 import jalview.analysis.TreeBuilder;
4 import jalview.datamodel.SequenceI;
5 import jalview.ext.treeviewer.ExternalTreeBuilderI;
6 import jalview.ext.treeviewer.ExternalTreeViewerBindingI;
7 import jalview.gui.Desktop;
8 import jalview.viewmodel.AlignmentViewport;
10 import java.awt.Dimension;
13 import org.forester.archaeopteryx.Archaeopteryx;
14 import org.forester.archaeopteryx.MainFrame;
15 import org.forester.phylogeny.Phylogeny;
16 import org.forester.phylogeny.PhylogenyNode;
19 * Static class for creating Archaeopteryx tree viewer instances from calculated
20 * trees and letting them be bound to Jalview.
22 * @author kjvanderheide
25 public final class AptxInit
28 * Test method, should generally not be used as it does not bind the tree to
34 public static MainFrame createUnboundInstance(final Phylogeny aptxTree)
36 Phylogeny[] aptxTrees = { aptxTree };
37 return createAptxFrame(aptxTrees);
40 // public static MainFrame createInstance(final Phylogeny[] aptxTrees,
41 // AlignmentViewport jalviewAlignmentView)
43 // return createAptxFrameInJalview(aptxTrees);
47 // public static MainFrame createInstance(final Phylogeny aptxTree,
48 // final AlignmentViewport jalviewAlignmentView)
50 // Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in
51 // // several trees simultaneously
52 // return createAptxFrameInJalview(aptxTrees);
56 public static MainFrame createInstance(
57 final TreeBuilder calculatedTree) // very dense method, to be split up
59 ExternalTreeBuilderI<Phylogeny, PhylogenyNode> aptxTreeBuilder = new AptxTreeBuilder(
62 Phylogeny aptxTree = aptxTreeBuilder.buildTree();
63 Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in
64 // several trees simultaneously
66 MainFrame aptxApp = createAptxFrame(aptxTrees);
68 bindNodesToJalviewSequences(aptxApp, calculatedTree.getAvport(),
69 aptxTreeBuilder.getAlignmentBoundNodes(),
70 aptxTreeBuilder.getNodesBoundAlignment());
72 return bindFrameToJalview(aptxApp);
76 public static MainFrame createInstanceFromFile(String filePath,
77 AlignmentViewport viewport)
79 String[] AptxArgs = new String[] { "-c",
80 "_aptx_jalview_configuration_file", filePath };
81 MainFrame aptxApp = Archaeopteryx.main(AptxArgs);
83 LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
84 viewport.getAlignment().getSequencesArray(),
85 aptxApp.getMainPanel().getCurrentTreePanel().getPhylogeny());
87 bindAptxNodes.associateLeavesToSequences();
89 bindNodesToJalviewSequences(aptxApp, viewport,
90 bindAptxNodes.getAlignmentWithNodes(),
91 bindAptxNodes.getNodesWithAlignment());
93 return bindFrameToJalview(aptxApp);
96 public static MainFrame createInstanceFromUrl()
100 // void readPhylogeniesFromURL() {
102 // Phylogeny[] phys = null;
103 // final String message = "Please enter a complete URL, for example
104 // \"http://purl.org/phylo/treebase/phylows/study/TB2:S15480?format=nexus\"";
105 // final String url_string = JOptionPane
106 // .showInputDialog( this,
108 // "Use URL/webservice to obtain a phylogeny",
109 // JOptionPane.QUESTION_MESSAGE );
110 // boolean nhx_or_nexus = false;
111 // if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
113 // url = new URL( url_string );
114 // PhylogenyParser parser = null;
115 // if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
116 // parser = new TolParser();
119 // parser = ParserUtils
120 // .createParserDependingOnUrlContents( url,
121 // getConfiguration().isValidatePhyloXmlAgainstSchema() );
123 // if ( parser instanceof NexusPhylogeniesParser ) {
124 // nhx_or_nexus = true;
126 // else if ( parser instanceof NHXParser ) {
127 // nhx_or_nexus = true;
129 // if ( _mainpanel.getCurrentTreePanel() != null ) {
130 // _mainpanel.getCurrentTreePanel().setWaitCursor();
133 // _mainpanel.setWaitCursor();
135 // final PhylogenyFactory factory =
136 // ParserBasedPhylogenyFactory.getInstance();
137 // phys = factory.create( url.openStream(), parser );
139 // catch ( final MalformedURLException e ) {
140 // JOptionPane.showMessageDialog( this,
141 // "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
143 // JOptionPane.ERROR_MESSAGE );
145 // catch ( final IOException e ) {
146 // JOptionPane.showMessageDialog( this,
147 // "Could not read from " + url + "\n"
148 // + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
149 // "Failed to read URL",
150 // JOptionPane.ERROR_MESSAGE );
152 // catch ( final Exception e ) {
153 // JOptionPane.showMessageDialog( this,
154 // ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
155 // "Unexpected Exception",
156 // JOptionPane.ERROR_MESSAGE );
159 // if ( _mainpanel.getCurrentTreePanel() != null ) {
160 // _mainpanel.getCurrentTreePanel().setArrowCursor();
163 // _mainpanel.setArrowCursor();
166 // if ( ( phys != null ) && ( phys.length > 0 ) ) {
167 // if ( nhx_or_nexus &&
168 // getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
169 // for( final Phylogeny phy : phys ) {
170 // PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" );
173 // AptxUtil.addPhylogeniesToTabs( phys,
174 // new File( url.getFile() ).getName(),
175 // new File( url.getFile() ).toString(),
176 // getConfiguration(),
178 // _mainpanel.getControlPanel().showWhole();
181 // activateSaveAllIfNeeded();
189 public static MainFrame createAptxFrame(
190 final Phylogeny[] aptxTrees)
192 MainFrame aptxApp = Archaeopteryx.createApplication(aptxTrees,
193 "_aptx_jalview_configuration_file", null);
198 public static ExternalTreeViewerBindingI<?> bindNodesToJalviewSequences(
199 final MainFrame aptxApp,
200 final AlignmentViewport jalviewAlignViewport,
201 final Map<SequenceI, PhylogenyNode> alignMappedToNodes,
202 final Map<PhylogenyNode, SequenceI> nodesMappedToAlign)
204 return new JalviewBinding(aptxApp, jalviewAlignViewport,
205 alignMappedToNodes, nodesMappedToAlign);
209 public static MainFrame bindFrameToJalview(final MainFrame aptxApp)
213 aptxApp.setMinimumSize(new Dimension(width, height));
214 // aptxApp.setFont(Desktop.instance.getFont());
215 // aptxApp.getMainPanel().setFont(Desktop.instance.getFont());
217 Desktop.addInternalFrame(aptxApp, "Archaeopteryx Tree View", true,
218 width, height, true, true);