From: kjvdheide Date: Mon, 20 Nov 2017 11:13:36 +0000 (+0000) Subject: JAL-2799 JAL-2805 JAL-281 multiple trees can now be loaded in X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=c737743893559b3eba3eade8f97dabfce38eee6e JAL-2799 JAL-2805 JAL-281 multiple trees can now be loaded in --- diff --git a/forester b/forester index eb22dac..a2e1b38 160000 --- a/forester +++ b/forester @@ -1 +1 @@ -Subproject commit eb22dac14771c467104f57362e3a624d0140f897 +Subproject commit a2e1b38bab7e593d79946c24e653776e6d796e00 diff --git a/src/jalview/ext/archaeopteryx/AptxInit.java b/src/jalview/ext/archaeopteryx/AptxInit.java index 107aeca..f6d9fd6 100644 --- a/src/jalview/ext/archaeopteryx/AptxInit.java +++ b/src/jalview/ext/archaeopteryx/AptxInit.java @@ -8,11 +8,16 @@ import jalview.gui.Desktop; import jalview.viewmodel.AlignmentViewport; import java.awt.Dimension; +import java.io.FileNotFoundException; +import java.io.IOException; import java.net.URL; import java.util.Map; +import org.forester.archaeopteryx.AptxUtil; import org.forester.archaeopteryx.Archaeopteryx; +import org.forester.archaeopteryx.Configuration; import org.forester.archaeopteryx.MainFrame; +import org.forester.io.parsers.nhx.NHXParser; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyNode; @@ -25,6 +30,25 @@ import org.forester.phylogeny.PhylogenyNode; */ public final class AptxInit { + + private final static Configuration APTX_CONFIG = new Configuration( + "_aptx_jalview_configuration_file", false, false, false); + + private final static boolean VALIDATE_PHYLOXML_XSD = APTX_CONFIG + .isValidatePhyloXmlAgainstSchema(); + + private final static boolean REPLACE_NHX_UNDERSCORES = APTX_CONFIG + .isReplaceUnderscoresInNhParsing(); + + private final static boolean INTERNAL_NUMBERS_AS_CONFIDENCE = APTX_CONFIG + .isInternalNumberAreConfidenceForNhParsing(); + + private final static boolean MIDPOINT_REROOT = APTX_CONFIG + .isMidpointReroot(); + + private final static NHXParser.TAXONOMY_EXTRACTION TAXONOMY_EXTRACTION = APTX_CONFIG + .getTaxonomyExtraction(); + /** * Test method, should generally not be used as it does not bind the tree to * its alignment @@ -78,110 +102,58 @@ public final class AptxInit AlignmentViewport viewport) { String[] AptxArgs = new String[] { "-c", - "_aptx_jalview_configuration_file", filePath }; + APTX_CONFIG.getConfigFilename(), filePath }; MainFrame aptxApp = Archaeopteryx.main(AptxArgs); + int tabCount = aptxApp.getMainPanel().getTabbedPane().getTabCount(); + + for (int i = 0; i < tabCount; i++) + { + // roundabout way to select each tree because getComponentAt(i) requires + // casting to TreePanel which doesn't work + aptxApp.getMainPanel().getTabbedPane().setSelectedIndex(i); + Phylogeny tree = aptxApp.getMainPanel().getCurrentTreePanel() + .getPhylogeny(); + LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation( viewport.getAlignment().getSequencesArray(), - aptxApp.getMainPanel().getCurrentTreePanel().getPhylogeny()); + tree); bindAptxNodes.associateLeavesToSequences(); bindNodesToJalviewSequences(aptxApp, viewport, bindAptxNodes.getAlignmentWithNodes(), bindAptxNodes.getNodesWithAlignment()); - + } return bindFrameToJalview(aptxApp); } - public static MainFrame createInstanceFromUrl(URL url) + public static MainFrame createInstanceFromUrl(URL treeUrl, + AlignmentViewport viewport) + throws FileNotFoundException, IOException { + + Phylogeny[] trees = AptxUtil.readPhylogeniesFromUrl(treeUrl, + VALIDATE_PHYLOXML_XSD, + REPLACE_NHX_UNDERSCORES, INTERNAL_NUMBERS_AS_CONFIDENCE, + TAXONOMY_EXTRACTION, MIDPOINT_REROOT); + MainFrame aptxApp = Archaeopteryx.createApplication(trees, APTX_CONFIG, + null); + + for (Phylogeny tree : trees) + { + LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation( + viewport.getAlignment().getSequencesArray(), tree); + + bindAptxNodes.associateLeavesToSequences(); + bindNodesToJalviewSequences(aptxApp, viewport, + bindAptxNodes.getAlignmentWithNodes(), + bindAptxNodes.getNodesWithAlignment()); + + } + + return bindFrameToJalview(aptxApp); - return null; - // 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(); - // } } @@ -191,7 +163,7 @@ public final class AptxInit final Phylogeny[] aptxTrees) { MainFrame aptxApp = Archaeopteryx.createApplication(aptxTrees, - "_aptx_jalview_configuration_file", null); + APTX_CONFIG, null); return aptxApp; } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 2040897..f5e8521 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -128,8 +128,8 @@ import java.awt.print.PrinterJob; import java.beans.PropertyChangeEvent; import java.io.File; import java.io.FileWriter; +import java.io.IOException; import java.io.PrintWriter; -import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; @@ -3906,12 +3906,16 @@ public void chooseTreeFile() { } } + /** + * Move to TreeParser? + */ public void chooseTreeUrl() { - URL treeUrl; + JLabel label = new JLabel( MessageManager.getString("label.tree_url_example")); + // add "example" button final JComboBox history = new JComboBox<>(); JPanel panel = new JPanel(new GridLayout(2, 1)); @@ -3934,18 +3938,27 @@ public void chooseTreeFile() { history.addItem(st.nextToken()); } } - String urlString = JvOptionPane.showInputDialog(this, - panel, + + int reply = JvOptionPane.showInternalConfirmDialog(this, panel, MessageManager.getString("label.load_tree_url"), - JvOptionPane.QUESTION_MESSAGE); - if ((urlString != null) && (!urlString.isEmpty())) + JvOptionPane.OK_CANCEL_OPTION); + + if (reply == JvOptionPane.OK_OPTION) { + + String urlString = history.getSelectedItem().toString(); + URL treeUrl; + try { + FileFormatI format = null; + + format = new IdentifyFile().identify(urlString, DataSourceType.URL); + // add actual use for the format identification (jalview .jar files) treeUrl = new URL(urlString); - AptxInit.createInstanceFromUrl(treeUrl); + AptxInit.createInstanceFromUrl(treeUrl, viewport); - } catch (MalformedURLException e) + } catch (IOException e) { JvOptionPane.showMessageDialog(this, MessageManager.formatMessage( @@ -3954,7 +3967,11 @@ public void chooseTreeFile() { { urlString }), MessageManager.getString("label.url_not_found") , JvOptionPane.ERROR_MESSAGE); + e.printStackTrace(); } + } + else + { }