From: kjvdheide Date: Sun, 26 Nov 2017 23:08:21 +0000 (+0000) Subject: JAL-2847 first rough attempt at loading in via database ID X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8afce1e45bd2e14240715c8a6f06be8b55a78a18;p=jalview.git JAL-2847 first rough attempt at loading in via database ID --- diff --git a/forester b/forester index 642ccb7..718bd74 160000 --- a/forester +++ b/forester @@ -1 +1 @@ -Subproject commit 642ccb75fc1e4cb7def346cb2f56191907f82a34 +Subproject commit 718bd74aff29f5883486fc0ab8b54e1519ab51d0 diff --git a/src/jalview/ext/archaeopteryx/Aptx.java b/src/jalview/ext/archaeopteryx/Aptx.java index 640dd31..f0c535b 100644 --- a/src/jalview/ext/archaeopteryx/Aptx.java +++ b/src/jalview/ext/archaeopteryx/Aptx.java @@ -1,5 +1,6 @@ package jalview.ext.archaeopteryx; +import jalview.ext.treeviewer.ExternalTreePanelI; import jalview.ext.treeviewer.ExternalTreeViewerI; import org.forester.archaeopteryx.MainFrame; @@ -13,5 +14,14 @@ public class Aptx implements ExternalTreeViewerI aptxApp = aptx; + + } + + @Override + public ExternalTreePanelI getTreePanel() + { + ExternalTreePanelI aptxPanel = new AptxTreePanel( + aptxApp.getMainPanel().getCurrentTreePanel()); + return aptxPanel; } } diff --git a/src/jalview/ext/archaeopteryx/AptxInit.java b/src/jalview/ext/archaeopteryx/AptxInit.java index 5a9fb12..81bf4fb 100644 --- a/src/jalview/ext/archaeopteryx/AptxInit.java +++ b/src/jalview/ext/archaeopteryx/AptxInit.java @@ -13,6 +13,7 @@ import java.awt.Dimension; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.net.MalformedURLException; import java.net.URL; import java.util.Map; @@ -20,13 +21,20 @@ import org.forester.archaeopteryx.AptxUtil; import org.forester.archaeopteryx.Archaeopteryx; import org.forester.archaeopteryx.Configuration; import org.forester.archaeopteryx.MainFrame; +import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient; +import org.forester.archaeopteryx.webservices.WebserviceUtil; +import org.forester.archaeopteryx.webservices.WebservicesManager; import org.forester.io.parsers.PhylogenyParser; import org.forester.io.parsers.nexus.NexusPhylogeniesParser; import org.forester.io.parsers.nhx.NHXParser; +import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException; +import org.forester.io.parsers.phyloxml.PhyloXmlParser; +import org.forester.io.parsers.tol.TolParser; import org.forester.io.parsers.util.ParserUtils; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyMethods; import org.forester.phylogeny.PhylogenyNode; +import org.forester.phylogeny.data.Identifier; import org.forester.util.ForesterUtil; /** @@ -60,7 +68,7 @@ public final class AptxInit public static MainFrame createInstanceFromCalculation( - final TreeBuilder calculatedTree) // very dense method, to be split up + final TreeBuilder calculatedTree) { ExternalTreeBuilderI aptxTreeBuilder = new AptxTreeBuilder( calculatedTree); @@ -94,6 +102,11 @@ public final class AptxInit MessageManager.getString("label.problem_reading_tree_file"), JvOptionPane.WARNING_MESSAGE); } + + if (Desktop.instance != null) + { + Desktop.instance.startLoading(filePath); + } boolean nhx_or_nexus = false; final PhylogenyParser p = ParserUtils.createParserDependingOnFileType( treeFile, VALIDATE_PHYLOXML_XSD); @@ -131,7 +144,10 @@ public final class AptxInit aptxFrames[i] = createAptxFrame(tree, viewport, treeTitle); } - + if (Desktop.instance != null) + { + Desktop.instance.stopLoading(); + } return aptxFrames; } @@ -142,6 +158,10 @@ public final class AptxInit { String treeTitle = treeUrl.getFile(); + if (Desktop.instance != null) + { + Desktop.instance.startLoading(treeTitle); + } Phylogeny[] trees = AptxUtil.readPhylogeniesFromUrl(treeUrl, VALIDATE_PHYLOXML_XSD, REPLACE_NHX_UNDERSCORES, INTERNAL_NUMBERS_AS_CONFIDENCE, @@ -154,10 +174,293 @@ public final class AptxInit aptxFrames[i] = createAptxFrame(tree, viewport, treeTitle); } + if (Desktop.instance != null) + { + Desktop.instance.stopLoading(); + } + return aptxFrames; } + /** + * Refactored from Forester's UrlTreeReader + * + * @param databaseIndex + * @param viewport + * @return + */ + public static MainFrame[] createInstancesFromDb(int databaseIndex, + AlignmentViewport viewport) + { + if (Desktop.desktop != null) + { + // Desktop.desktop.startLoading(treeTitle); + } + + URL url = null; + Phylogeny[] trees = null; + final WebservicesManager webservices_manager = WebservicesManager + .getInstance(); + final PhylogeniesWebserviceClient client = webservices_manager + .getAvailablePhylogeniesWebserviceClient(databaseIndex); + String identifier = JvOptionPane.showInternalInputDialog( + Desktop.desktop, + client.getInstructions() + "\n(Reference: " + + client.getReference() + ")", + client.getDescription(), JvOptionPane.QUESTION_MESSAGE); + if ((identifier != null) && (identifier.trim().length() > 0)) + { + identifier = identifier.trim(); + if (client.isQueryInteger()) + { + identifier = identifier.replaceAll("^\\D+", ""); + int id = -1; + try + { + id = Integer.parseInt(identifier); + } catch (final NumberFormatException e) + { + id = -1; + } + if (id < 1) + { + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + "Identifier is expected to be a number", + "Can not open URL", JvOptionPane.ERROR_MESSAGE); + return new MainFrame[0]; + } + identifier = id + ""; + } + boolean exception = false; + try + { + String url_str = client.getUrl(); + url_str = url_str.replaceFirst( + PhylogeniesWebserviceClient.QUERY_PLACEHOLDER, identifier); + url = new URL(url_str); + PhylogenyParser parser = null; + switch (client.getReturnFormat()) + { + case TOL_XML_RESPONSE: + parser = new TolParser(); + break; + case NEXUS: + parser = new NexusPhylogeniesParser(); + ((NexusPhylogeniesParser) parser).setReplaceUnderscores(true); + break; + case TREEBASE_TREE: + parser = new NexusPhylogeniesParser(); + ((NexusPhylogeniesParser) parser).setReplaceUnderscores(true); + ((NexusPhylogeniesParser) parser) + .setTaxonomyExtraction(NHXParser.TAXONOMY_EXTRACTION.NO); + break; + case TREEBASE_STUDY: + parser = new NexusPhylogeniesParser(); + ((NexusPhylogeniesParser) parser).setReplaceUnderscores(true); + ((NexusPhylogeniesParser) parser) + .setTaxonomyExtraction(NHXParser.TAXONOMY_EXTRACTION.NO); + break; + case NH: + parser = new NHXParser(); + ((NHXParser) parser) + .setTaxonomyExtraction(NHXParser.TAXONOMY_EXTRACTION.NO); + ((NHXParser) parser).setReplaceUnderscores(true); + ((NHXParser) parser).setGuessRootedness(true); + break; + case NH_EXTRACT_TAXONOMY: + parser = new NHXParser(); + ((NHXParser) parser).setTaxonomyExtraction( + NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE); + ((NHXParser) parser).setReplaceUnderscores(false); + ((NHXParser) parser).setGuessRootedness(true); + break; + case PFAM: + parser = new NHXParser(); + ((NHXParser) parser).setTaxonomyExtraction( + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT); + ((NHXParser) parser).setReplaceUnderscores(false); + ((NHXParser) parser).setGuessRootedness(true); + break; + case NHX: + parser = new NHXParser(); + ((NHXParser) parser) + .setTaxonomyExtraction(NHXParser.TAXONOMY_EXTRACTION.NO); + ((NHXParser) parser).setReplaceUnderscores(false); + ((NHXParser) parser).setGuessRootedness(true); + break; + case PHYLOXML: + parser = PhyloXmlParser.createPhyloXmlParserXsdValidating(); + break; + default: + throw new IllegalArgumentException( + "unknown format: " + client.getReturnFormat()); + } + // + // if (_main_frame.getMainPanel().getCurrentTreePanel() != null) + // { + // _main_frame.getMainPanel().getCurrentTreePanel().setWaitCursor(); + // } + // else + // { + // _main_frame.getMainPanel().setWaitCursor(); + // } + trees = ForesterUtil.readPhylogeniesFromUrl(url, parser); + } catch (final MalformedURLException e) + { + exception = true; + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + "Malformed URL: " + url + "\n" + e.getLocalizedMessage(), + "Malformed URL", JvOptionPane.ERROR_MESSAGE); + } catch (final IOException e) + { + exception = true; + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + "Could not read from " + url + "\n" + + e.getLocalizedMessage(), + "Failed to read tree from " + client.getName() + " for " + + identifier, + JvOptionPane.ERROR_MESSAGE); + } catch (final NumberFormatException e) + { + exception = true; + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + "Could not read from " + url + "\n" + + e.getLocalizedMessage(), + "Failed to read tree from " + client.getName() + " for " + + identifier, + JvOptionPane.ERROR_MESSAGE); + } catch (final Exception e) + { + exception = true; + e.printStackTrace(); + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + e.getLocalizedMessage(), "Unexpected Exception", + JvOptionPane.ERROR_MESSAGE); + } finally + { + // if (_main_frame.getCurrentTreePanel() != null) + // { + // _main_frame.getCurrentTreePanel().setArrowCursor(); + // } + // else + // { + // _main_frame.getMainPanel().setArrowCursor(); + // } + } + if ((trees != null) && (trees.length > 0)) + { + for (final Phylogeny phylogeny : trees) + { + if (!phylogeny.isEmpty()) + { + if (client.getName().equals(WebserviceUtil.TREE_FAM_NAME)) + { + phylogeny.setRerootable(false); + phylogeny.setRooted(true); + } + if (client.getProcessingInstructions() != null) + { + try + { + WebserviceUtil.processInstructions(client, phylogeny); + } catch (final PhyloXmlDataFormatException e) + { + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + "Error:\n" + e.getLocalizedMessage(), "Error", + JvOptionPane.ERROR_MESSAGE); + } + } + if (client.getNodeField() != null) + { + try + { + PhylogenyMethods.transferNodeNameToField(phylogeny, + client.getNodeField(), false); + } catch (final PhyloXmlDataFormatException e) + { + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + "Error:\n" + e.getLocalizedMessage(), "Error", + JvOptionPane.ERROR_MESSAGE); + } + } + phylogeny.setIdentifier( + new Identifier(identifier, client.getName())); + // _main_frame.getJMenuBar().remove(_main_frame.getHelpMenu()); + // _main_frame.getMenuBarOfMainFrame() + // .add(_main_frame.getHelpMenu()); + // _main_frame.getMainPanel().addPhylogenyInNewTab(phylogeny, + // _main_frame.getConfiguration(), + // new File(url.getFile()).getName(), url.toString()); + + MainFrame aptxApp = createAptxFrame(phylogeny, viewport, + url.getFile()); + String my_name_for_file = ""; + if (!ForesterUtil.isEmpty(phylogeny.getName())) + { + my_name_for_file = new String(phylogeny.getName()) + .replaceAll(" ", "_"); + } + else if (phylogeny.getIdentifier() != null) + { + final StringBuffer sb = new StringBuffer(); + if (!ForesterUtil + .isEmpty(phylogeny.getIdentifier().getProvider())) + { + sb.append(phylogeny.getIdentifier().getProvider()); + sb.append("_"); + } + sb.append(phylogeny.getIdentifier().getValue()); + my_name_for_file = new String( + sb.toString().replaceAll(" ", "_")); + } + // _main_frame.getMainPanel().getCurrentTreePanel() + // .setTreeFile(new File(my_name_for_file)); + AptxUtil.lookAtSomeTreePropertiesForAptxControlSettings( + phylogeny, aptxApp.getMainPanel().getControlPanel(), + APTX_CONFIG); + // _main_frame.getMainPanel().getControlPanel().showWhole(); + + aptxApp.activateSaveAllIfNeeded(); + } + } + } + else if (!exception) + { + JvOptionPane.showMessageDialog(null, + ForesterUtil.wordWrap( + "Failed to read in tree(s) from [" + url + "]", 80), + "Error", JvOptionPane.ERROR_MESSAGE); + } + if ((trees != null) && (trees.length > 0)) + { + try + { + JvOptionPane.showMessageDialog(null, + ForesterUtil.wordWrap("Successfully read in " + + trees.length + " tree(s) from [" + url + "]", + 80), + "Success", JvOptionPane.INFORMATION_MESSAGE); + } catch (final Exception e) + { + // Not important if this fails, do nothing. + } + // _main_frame.getContentPane().repaint(); + } + } + + System.gc(); + + + if (Desktop.instance != null) + { + Desktop.instance.stopLoading(); + } + return null; + + + } + diff --git a/src/jalview/ext/archaeopteryx/TreeNode.java b/src/jalview/ext/archaeopteryx/TreeNode.java index 8e06d6c..b2e33d4 100644 --- a/src/jalview/ext/archaeopteryx/TreeNode.java +++ b/src/jalview/ext/archaeopteryx/TreeNode.java @@ -32,6 +32,7 @@ public class TreeNode implements ExternalTreeNodeI { // return node.getDescendants(); return null; + } diff --git a/src/jalview/ext/forester/io/TreeDatabaseMenuBuilder.java b/src/jalview/ext/forester/io/TreeDatabaseMenuBuilder.java index 45415d1..3d11c8d 100644 --- a/src/jalview/ext/forester/io/TreeDatabaseMenuBuilder.java +++ b/src/jalview/ext/forester/io/TreeDatabaseMenuBuilder.java @@ -1,5 +1,7 @@ package jalview.ext.forester.io; +import java.util.List; + import javax.swing.JMenu; import javax.swing.JMenuItem; @@ -10,7 +12,6 @@ public class TreeDatabaseMenuBuilder { final WebservicesManager webservicesManager; - JMenuItem[] treeDatabaseMenuItems; public TreeDatabaseMenuBuilder() @@ -20,8 +21,10 @@ public class TreeDatabaseMenuBuilder } - public JMenu fillMenu(JMenu treeDbMenu) { - treeDatabaseMenuItems = new JMenuItem[webservicesManager + public JMenu createDbMenu() + { + JMenu treeDbMenu = new JMenu(); + JMenuItem[] treeDatabaseMenuItems = new JMenuItem[webservicesManager .getAvailablePhylogeniesWebserviceClients().size()]; for (int i = 0; i < treeDatabaseMenuItems.length; ++i) @@ -37,4 +40,9 @@ public class TreeDatabaseMenuBuilder } + public List getTreeDatabases() + { + return webservicesManager.getAvailablePhylogeniesWebserviceClients(); + } + } diff --git a/src/jalview/ext/treeviewer/ExternalTreeViewerI.java b/src/jalview/ext/treeviewer/ExternalTreeViewerI.java index 20c47f6..bc1924a 100644 --- a/src/jalview/ext/treeviewer/ExternalTreeViewerI.java +++ b/src/jalview/ext/treeviewer/ExternalTreeViewerI.java @@ -2,5 +2,6 @@ package jalview.ext.treeviewer; public interface ExternalTreeViewerI { + public ExternalTreePanelI getTreePanel(); } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 128eccc..97120fc 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -3900,39 +3900,40 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override protected void loadTreeBaseStudy_actionPerformed(ActionEvent e) { - chooseTreeDb(); + chooseTreeDb(0); } @Override - protected void loadTreeOfLife_actionPerformed(ActionEvent e) + protected void loadTreeBase_actionPerformed(ActionEvent e) { - chooseTreeDb(); + chooseTreeDb(1); } - @Override - protected void loadTreeFam_actionPerformed(ActionEvent e) + protected void loadTreePfam_actionPerformed(ActionEvent e) { - chooseTreeDb(); + chooseTreeDb(2); } - @Override - protected void loadTreePfam_actionPerformed(ActionEvent e) + protected void loadTreeFam_actionPerformed(ActionEvent e) { - chooseTreeDb(); + chooseTreeDb(3); } @Override - protected void loadTreeBase_actionPerformed(ActionEvent e) + protected void loadTreeOfLife_actionPerformed(ActionEvent e) { - chooseTreeDb(); + chooseTreeDb(4); } + + + public void chooseTreeFile() { // Pick the tree file @@ -4030,11 +4031,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } - public void chooseTreeDb() + public void chooseTreeDb(int databaseIndex) { - - - + AptxInit.createInstancesFromDb(databaseIndex, viewport); } public TreePanel showNewickTree(NewickFile nf, String treeTitle) @@ -4100,6 +4099,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, private boolean buildingMenu = false; + public void BuildTreeDbMenu() + { + + } /** * Generates menu items and listener event actions for web service clients *