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;
14 import org.forester.archaeopteryx.Archaeopteryx;
15 import org.forester.archaeopteryx.MainFrame;
16 import org.forester.phylogeny.Phylogeny;
17 import org.forester.phylogeny.PhylogenyNode;
20 * Static class for creating Archaeopteryx tree viewer instances from calculated
21 * trees and letting them be bound to Jalview.
23 * @author kjvanderheide
26 public final class AptxInit
29 * Test method, should generally not be used as it does not bind the tree to
35 public static MainFrame createUnboundInstance(final Phylogeny aptxTree)
37 Phylogeny[] aptxTrees = { aptxTree };
38 return createAptxFrame(aptxTrees);
41 // public static MainFrame createInstance(final Phylogeny[] aptxTrees,
42 // AlignmentViewport jalviewAlignmentView)
44 // return createAptxFrameInJalview(aptxTrees);
48 // public static MainFrame createInstance(final Phylogeny aptxTree,
49 // final AlignmentViewport jalviewAlignmentView)
51 // Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in
52 // // several trees simultaneously
53 // return createAptxFrameInJalview(aptxTrees);
57 public static MainFrame createInstance(
58 final TreeBuilder calculatedTree) // very dense method, to be split up
60 ExternalTreeBuilderI<Phylogeny, PhylogenyNode> aptxTreeBuilder = new AptxTreeBuilder(
63 Phylogeny aptxTree = aptxTreeBuilder.buildTree();
64 Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in
65 // several trees simultaneously
67 MainFrame aptxApp = createAptxFrame(aptxTrees);
69 bindNodesToJalviewSequences(aptxApp, calculatedTree.getAvport(),
70 aptxTreeBuilder.getAlignmentBoundNodes(),
71 aptxTreeBuilder.getNodesBoundAlignment());
73 return bindFrameToJalview(aptxApp);
77 public static MainFrame createInstanceFromFile(String filePath,
78 AlignmentViewport viewport)
80 String[] AptxArgs = new String[] { "-c",
81 "_aptx_jalview_configuration_file", filePath };
82 MainFrame aptxApp = Archaeopteryx.main(AptxArgs);
84 LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
85 viewport.getAlignment().getSequencesArray(),
86 aptxApp.getMainPanel().getCurrentTreePanel().getPhylogeny());
88 bindAptxNodes.associateLeavesToSequences();
90 bindNodesToJalviewSequences(aptxApp, viewport,
91 bindAptxNodes.getAlignmentWithNodes(),
92 bindAptxNodes.getNodesWithAlignment());
94 return bindFrameToJalview(aptxApp);
97 public static MainFrame createInstanceFromUrl(URL url)
101 // void readPhylogeniesFromURL() {
103 // Phylogeny[] phys = null;
104 // final String message = "Please enter a complete URL, for example
105 // \"http://purl.org/phylo/treebase/phylows/study/TB2:S15480?format=nexus\"";
106 // final String url_string = JOptionPane
107 // .showInputDialog( this,
109 // "Use URL/webservice to obtain a phylogeny",
110 // JOptionPane.QUESTION_MESSAGE );
111 // boolean nhx_or_nexus = false;
112 // if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
114 // url = new URL( url_string );
115 // PhylogenyParser parser = null;
116 // if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
117 // parser = new TolParser();
120 // parser = ParserUtils
121 // .createParserDependingOnUrlContents( url,
122 // getConfiguration().isValidatePhyloXmlAgainstSchema() );
124 // if ( parser instanceof NexusPhylogeniesParser ) {
125 // nhx_or_nexus = true;
127 // else if ( parser instanceof NHXParser ) {
128 // nhx_or_nexus = true;
130 // if ( _mainpanel.getCurrentTreePanel() != null ) {
131 // _mainpanel.getCurrentTreePanel().setWaitCursor();
134 // _mainpanel.setWaitCursor();
136 // final PhylogenyFactory factory =
137 // ParserBasedPhylogenyFactory.getInstance();
138 // phys = factory.create( url.openStream(), parser );
140 // catch ( final MalformedURLException e ) {
141 // JOptionPane.showMessageDialog( this,
142 // "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
144 // JOptionPane.ERROR_MESSAGE );
146 // catch ( final IOException e ) {
147 // JOptionPane.showMessageDialog( this,
148 // "Could not read from " + url + "\n"
149 // + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
150 // "Failed to read URL",
151 // JOptionPane.ERROR_MESSAGE );
153 // catch ( final Exception e ) {
154 // JOptionPane.showMessageDialog( this,
155 // ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
156 // "Unexpected Exception",
157 // JOptionPane.ERROR_MESSAGE );
160 // if ( _mainpanel.getCurrentTreePanel() != null ) {
161 // _mainpanel.getCurrentTreePanel().setArrowCursor();
164 // _mainpanel.setArrowCursor();
167 // if ( ( phys != null ) && ( phys.length > 0 ) ) {
168 // if ( nhx_or_nexus &&
169 // getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
170 // for( final Phylogeny phy : phys ) {
171 // PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" );
174 // AptxUtil.addPhylogeniesToTabs( phys,
175 // new File( url.getFile() ).getName(),
176 // new File( url.getFile() ).toString(),
177 // getConfiguration(),
179 // _mainpanel.getControlPanel().showWhole();
182 // activateSaveAllIfNeeded();
190 public static MainFrame createAptxFrame(
191 final Phylogeny[] aptxTrees)
193 MainFrame aptxApp = Archaeopteryx.createApplication(aptxTrees,
194 "_aptx_jalview_configuration_file", null);
199 public static ExternalTreeViewerBindingI<?> bindNodesToJalviewSequences(
200 final MainFrame aptxApp,
201 final AlignmentViewport jalviewAlignViewport,
202 final Map<SequenceI, PhylogenyNode> alignMappedToNodes,
203 final Map<PhylogenyNode, SequenceI> nodesMappedToAlign)
205 return new JalviewBinding(aptxApp, jalviewAlignViewport,
206 alignMappedToNodes, nodesMappedToAlign);
210 public static MainFrame bindFrameToJalview(final MainFrame aptxApp)
214 aptxApp.setMinimumSize(new Dimension(width, height));
215 // aptxApp.setFont(Desktop.instance.getFont());
216 // aptxApp.getMainPanel().setFont(Desktop.instance.getFont());
218 Desktop.addInternalFrame(aptxApp, "Archaeopteryx Tree View", true,
219 width, height, true, true);