From: kjvdheide Date: Fri, 17 Nov 2017 14:44:46 +0000 (+0000) Subject: JAL-2805 reorganized code, tree building goes through AptxInit for now X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=502de60f8af893ac57576bda0574453a3d5dd345;p=jalview.git JAL-2805 reorganized code, tree building goes through AptxInit for now --- diff --git a/src/jalview/ext/archaeopteryx/AptxInit.java b/src/jalview/ext/archaeopteryx/AptxInit.java index ce34573..2363e4c 100644 --- a/src/jalview/ext/archaeopteryx/AptxInit.java +++ b/src/jalview/ext/archaeopteryx/AptxInit.java @@ -68,10 +68,30 @@ public final class AptxInit bindNodesToJalviewSequences(aptxApp, calculatedTree.getAvport(), aptxTreeBuilder.getAlignmentBoundNodes(), aptxTreeBuilder.getNodesBoundAlignment()); + return bindFrameToJalview(aptxApp); } + public static MainFrame createInstanceFromFile(String filePath, + AlignmentViewport viewport) + { + String[] AptxArgs = new String[] { "-c", + "_aptx_jalview_configuration_file", filePath }; + MainFrame aptxApp = Archaeopteryx.main(AptxArgs); + + LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation( + viewport.getAlignment().getSequencesArray(), + aptxApp.getMainPanel().getCurrentTreePanel().getPhylogeny()); + + bindAptxNodes.associateLeavesToSequences(); + + bindNodesToJalviewSequences(aptxApp, viewport, + bindAptxNodes.getAlignmentWithNodes(), + bindAptxNodes.getNodesWithAlignment()); + + return bindFrameToJalview(aptxApp); + } @@ -83,6 +103,7 @@ public final class AptxInit return aptxApp; } + public static ExternalTreeViewerBindingI bindNodesToJalviewSequences( final MainFrame aptxApp, final AlignmentViewport jalviewAlignViewport, diff --git a/src/jalview/ext/forester/io/TreeParser.java b/src/jalview/ext/forester/io/TreeParser.java index 54f79bc..b2f36b8 100644 --- a/src/jalview/ext/forester/io/TreeParser.java +++ b/src/jalview/ext/forester/io/TreeParser.java @@ -1,168 +1,169 @@ -package jalview.ext.forester.io; - -import jalview.ext.archaeopteryx.AptxInit; -import jalview.ext.archaeopteryx.JalviewBinding; -import jalview.ext.archaeopteryx.LoadedTreeAssociation; -import jalview.ext.treeviewer.ExternalTreeParserI; -import jalview.gui.Desktop; -import jalview.gui.JvOptionPane; -import jalview.util.MessageManager; -import jalview.viewmodel.AlignmentViewport; - -import java.io.File; -import java.io.IOException; - -import org.forester.archaeopteryx.Archaeopteryx; -import org.forester.archaeopteryx.MainFrame; -import org.forester.util.ForesterUtil; - -public class TreeParser implements ExternalTreeParserI -{ - private final String filePath; - - private final File file; - - public TreeParser(final String treeFilePath) - { - final String possibleError = ForesterUtil.isReadableFile(treeFilePath); - if (possibleError != null) - { - JvOptionPane.showMessageDialog(Desktop.desktop, possibleError, - MessageManager.getString("label.problem_reading_tree_file"), - JvOptionPane.WARNING_MESSAGE); - - } - filePath = treeFilePath; - file = new File(filePath); - - - } - - public TreeParser(final File treeFile) throws IOException - { - final String possibleError = ForesterUtil.isReadableFile(treeFile); - if (possibleError != null) - { - JvOptionPane.showMessageDialog(Desktop.desktop, possibleError, - MessageManager.getString("label.problem_reading_tree_file"), - JvOptionPane.WARNING_MESSAGE); - - } - file = treeFile; - filePath = file.getCanonicalPath(); - } - - @Override - public MainFrame loadTreeFile(AlignmentViewport viewport) - { - String[] AptxArgs = new String[] { "-c", - "_aptx_jalview_configuration_file", filePath }; - MainFrame aptx = Archaeopteryx.main(AptxArgs); - - LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation( - viewport.getAlignment().getSequencesArray(), - aptx.getMainPanel().getCurrentTreePanel().getPhylogeny()); - - bindAptxNodes.associateLeavesToSequences(); - - new JalviewBinding(aptx, viewport, bindAptxNodes.getAlignmentWithNodes(), - bindAptxNodes.getNodesWithAlignment()); - - AptxInit.bindFrameToJalview(aptx); - - return aptx; - - - } - // - // void readPhylogeniesFromURL() { - // URL url = null; - // Phylogeny[] phys = null; - // final String message = "Please enter a complete URL, for example - // \"http://purl.org/phylo/treebase/phylows/study/TB2:S15480?format=nexus\""; - // final String url_string = JOptionPane - // .showInputDialog( this, - // message, - // "Use URL/webservice to obtain a phylogeny", - // JOptionPane.QUESTION_MESSAGE ); - // boolean nhx_or_nexus = false; - // if ( ( url_string != null ) && ( url_string.length() > 0 ) ) { - // try { - // url = new URL( url_string ); - // PhylogenyParser parser = null; - // if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) { - // parser = new TolParser(); - // } - // else { - // parser = ParserUtils - // .createParserDependingOnUrlContents( url, - // getConfiguration().isValidatePhyloXmlAgainstSchema() ); - // } - // if ( parser instanceof NexusPhylogeniesParser ) { - // nhx_or_nexus = true; - // } - // else if ( parser instanceof NHXParser ) { - // nhx_or_nexus = true; - // } - // if ( _mainpanel.getCurrentTreePanel() != null ) { - // _mainpanel.getCurrentTreePanel().setWaitCursor(); - // } - // else { - // _mainpanel.setWaitCursor(); - // } - // final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - // phys = factory.create( url.openStream(), parser ); - // } - // catch ( final MalformedURLException e ) { - // JOptionPane.showMessageDialog( this, - // "Malformed URL: " + url + "\n" + e.getLocalizedMessage(), - // "Malformed URL", - // JOptionPane.ERROR_MESSAGE ); - // } - // catch ( final IOException e ) { - // JOptionPane.showMessageDialog( this, - // "Could not read from " + url + "\n" - // + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ), - // "Failed to read URL", - // JOptionPane.ERROR_MESSAGE ); - // } - // catch ( final Exception e ) { - // JOptionPane.showMessageDialog( this, - // ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ), - // "Unexpected Exception", - // JOptionPane.ERROR_MESSAGE ); - // } - // finally { - // if ( _mainpanel.getCurrentTreePanel() != null ) { - // _mainpanel.getCurrentTreePanel().setArrowCursor(); - // } - // else { - // _mainpanel.setArrowCursor(); - // } - // } - // if ( ( phys != null ) && ( phys.length > 0 ) ) { - // if ( nhx_or_nexus && - // getOptions().isInternalNumberAreConfidenceForNhParsing() ) { - // for( final Phylogeny phy : phys ) { - // PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" ); - // } - // } - // AptxUtil.addPhylogeniesToTabs( phys, - // new File( url.getFile() ).getName(), - // new File( url.getFile() ).toString(), - // getConfiguration(), - // getMainPanel() ); - // _mainpanel.getControlPanel().showWhole(); - // } - // } - // activateSaveAllIfNeeded(); - // System.gc(); - // } - -} - - - - - - +// package jalview.ext.forester.io; +// +// import jalview.ext.archaeopteryx.AptxInit; +// import jalview.ext.archaeopteryx.JalviewBinding; +// import jalview.ext.archaeopteryx.LoadedTreeAssociation; +// import jalview.ext.treeviewer.ExternalTreeParserI; +// import jalview.gui.Desktop; +// import jalview.gui.JvOptionPane; +// import jalview.util.MessageManager; +// import jalview.viewmodel.AlignmentViewport; +// +// import java.io.File; +// import java.io.IOException; +// +// import org.forester.archaeopteryx.Archaeopteryx; +// import org.forester.archaeopteryx.MainFrame; +// import org.forester.util.ForesterUtil; +// +// public class TreeParser implements ExternalTreeParserI +// { +// private final String filePath; +// +// private final File file; +// +// public TreeParser(final String treeFilePath) +// { +// final String possibleError = ForesterUtil.isReadableFile(treeFilePath); +// if (possibleError != null) +// { +// JvOptionPane.showMessageDialog(Desktop.desktop, possibleError, +// MessageManager.getString("label.problem_reading_tree_file"), +// JvOptionPane.WARNING_MESSAGE); +// +// } +// filePath = treeFilePath; +// file = new File(filePath); +// +// +// } +// +// public TreeParser(final File treeFile) throws IOException +// { +// final String possibleError = ForesterUtil.isReadableFile(treeFile); +// if (possibleError != null) +// { +// JvOptionPane.showMessageDialog(Desktop.desktop, possibleError, +// MessageManager.getString("label.problem_reading_tree_file"), +// JvOptionPane.WARNING_MESSAGE); +// +// } +// file = treeFile; +// filePath = file.getCanonicalPath(); +// } +// +// @Override +// public MainFrame loadTreeFile(AlignmentViewport viewport) +// { +// String[] AptxArgs = new String[] { "-c", +// "_aptx_jalview_configuration_file", filePath }; +// MainFrame aptx = Archaeopteryx.main(AptxArgs); +// +// LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation( +// viewport.getAlignment().getSequencesArray(), +// aptx.getMainPanel().getCurrentTreePanel().getPhylogeny()); +// +// bindAptxNodes.associateLeavesToSequences(); +// +// new JalviewBinding(aptx, viewport, bindAptxNodes.getAlignmentWithNodes(), +// bindAptxNodes.getNodesWithAlignment()); +// +// AptxInit.bindFrameToJalview(aptx); +// +// return aptx; +// +// +// } +// // +// // void readPhylogeniesFromURL() { +// // URL url = null; +// // Phylogeny[] phys = null; +// // final String message = "Please enter a complete URL, for example +// // \"http://purl.org/phylo/treebase/phylows/study/TB2:S15480?format=nexus\""; +// // final String url_string = JOptionPane +// // .showInputDialog( this, +// // message, +// // "Use URL/webservice to obtain a phylogeny", +// // JOptionPane.QUESTION_MESSAGE ); +// // boolean nhx_or_nexus = false; +// // if ( ( url_string != null ) && ( url_string.length() > 0 ) ) { +// // try { +// // url = new URL( url_string ); +// // PhylogenyParser parser = null; +// // if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) { +// // parser = new TolParser(); +// // } +// // else { +// // parser = ParserUtils +// // .createParserDependingOnUrlContents( url, +// // getConfiguration().isValidatePhyloXmlAgainstSchema() ); +// // } +// // if ( parser instanceof NexusPhylogeniesParser ) { +// // nhx_or_nexus = true; +// // } +// // else if ( parser instanceof NHXParser ) { +// // nhx_or_nexus = true; +// // } +// // if ( _mainpanel.getCurrentTreePanel() != null ) { +// // _mainpanel.getCurrentTreePanel().setWaitCursor(); +// // } +// // else { +// // _mainpanel.setWaitCursor(); +// // } +// // final PhylogenyFactory factory = +// ParserBasedPhylogenyFactory.getInstance(); +// // phys = factory.create( url.openStream(), parser ); +// // } +// // catch ( final MalformedURLException e ) { +// // JOptionPane.showMessageDialog( this, +// // "Malformed URL: " + url + "\n" + e.getLocalizedMessage(), +// // "Malformed URL", +// // JOptionPane.ERROR_MESSAGE ); +// // } +// // catch ( final IOException e ) { +// // JOptionPane.showMessageDialog( this, +// // "Could not read from " + url + "\n" +// // + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ), +// // "Failed to read URL", +// // JOptionPane.ERROR_MESSAGE ); +// // } +// // catch ( final Exception e ) { +// // JOptionPane.showMessageDialog( this, +// // ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ), +// // "Unexpected Exception", +// // JOptionPane.ERROR_MESSAGE ); +// // } +// // finally { +// // if ( _mainpanel.getCurrentTreePanel() != null ) { +// // _mainpanel.getCurrentTreePanel().setArrowCursor(); +// // } +// // else { +// // _mainpanel.setArrowCursor(); +// // } +// // } +// // if ( ( phys != null ) && ( phys.length > 0 ) ) { +// // if ( nhx_or_nexus && +// // getOptions().isInternalNumberAreConfidenceForNhParsing() ) { +// // for( final Phylogeny phy : phys ) { +// // PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" ); +// // } +// // } +// // AptxUtil.addPhylogeniesToTabs( phys, +// // new File( url.getFile() ).getName(), +// // new File( url.getFile() ).toString(), +// // getConfiguration(), +// // getMainPanel() ); +// // _mainpanel.getControlPanel().showWhole(); +// // } +// // } +// // activateSaveAllIfNeeded(); +// // System.gc(); +// // } +// +// } +// +// +// +// +// +// diff --git a/src/jalview/ext/treeviewer/ExternalTreeParserI.java b/src/jalview/ext/treeviewer/ExternalTreeParserI.java index defd744..fb7227f 100644 --- a/src/jalview/ext/treeviewer/ExternalTreeParserI.java +++ b/src/jalview/ext/treeviewer/ExternalTreeParserI.java @@ -1,18 +1,21 @@ -package jalview.ext.treeviewer; - -import jalview.viewmodel.AlignmentViewport; - -import javax.swing.JInternalFrame; - -/** - * Interface for loading in existing trees to an external tree viewer. - * - * @author kjvanderheide - * - * @param - * Frame of the tree viewer. - */ -public interface ExternalTreeParserI -{ - public F loadTreeFile(AlignmentViewport viewport); -} +// package jalview.ext.treeviewer; +// +// import jalview.viewmodel.AlignmentViewport; +// +// import javax.swing.JInternalFrame; +// +/// ** +// * Interface for loading in existing trees to an external tree viewer. +// * +// * @author kjvanderheide +// * +// * @param +// * Frame of the tree viewer. +// */ +// public interface ExternalTreeParserI +// { +// public void loadTreeFile(AlignmentViewport viewport); +// +// public void loadTreeUrl(AlignmentViewport viewport); +// +// } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 71f240b..b9bf23e 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -60,9 +60,8 @@ import jalview.datamodel.SeqCigar; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.ext.archaeopteryx.AptxInit; import jalview.ext.forester.io.SupportedTreeFileFilter; -import jalview.ext.forester.io.TreeParser; -import jalview.ext.treeviewer.ExternalTreeParserI; import jalview.gui.ColourMenuHelper.ColourChangeListener; import jalview.gui.ViewSelectionMenu.ViewSetProvider; import jalview.io.AlignmentProperties; @@ -3904,9 +3903,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, NewickFile fin = null; try { - ExternalTreeParserI treeParser = new TreeParser( - filePath); - treeParser.loadTreeFile(viewport); + AptxInit.createInstanceFromFile(filePath, getViewport());