From fc5e6326a0df6e78a44c0c53c2125091f992d1e1 Mon Sep 17 00:00:00 2001 From: kjvdheide Date: Sun, 3 Dec 2017 16:30:05 +0000 Subject: [PATCH] JAL-2847 start of cleaning up db loading code --- src/jalview/ext/archaeopteryx/AptxInit.java | 49 ++++++++++---------- ...ion.java => LoadedTreeSequenceAssociation.java} | 4 +- src/jalview/gui/AlignFrame.java | 5 ++ 3 files changed, 31 insertions(+), 27 deletions(-) rename src/jalview/ext/archaeopteryx/{LoadedTreeAssociation.java => LoadedTreeSequenceAssociation.java} (97%) diff --git a/src/jalview/ext/archaeopteryx/AptxInit.java b/src/jalview/ext/archaeopteryx/AptxInit.java index 805cc6c..b9a7ae2 100644 --- a/src/jalview/ext/archaeopteryx/AptxInit.java +++ b/src/jalview/ext/archaeopteryx/AptxInit.java @@ -108,20 +108,20 @@ public final class AptxInit Desktop.instance.startLoading(filePath); } boolean nhx_or_nexus = false; - final PhylogenyParser p = ParserUtils.createParserDependingOnFileType( + final PhylogenyParser parser = ParserUtils.createParserDependingOnFileType( treeFile, VALIDATE_PHYLOXML_XSD); - if (p instanceof NHXParser) + if (parser instanceof NHXParser) { nhx_or_nexus = true; - final NHXParser nhx = (NHXParser) p; + final NHXParser nhx = (NHXParser) parser; nhx.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES); nhx.setIgnoreQuotes(false); nhx.setTaxonomyExtraction(TAXONOMY_EXTRACTION); } - else if (p instanceof NexusPhylogeniesParser) + else if (parser instanceof NexusPhylogeniesParser) { nhx_or_nexus = true; - final NexusPhylogeniesParser nex = (NexusPhylogeniesParser) p; + final NexusPhylogeniesParser nex = (NexusPhylogeniesParser) parser; nex.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES); nex.setIgnoreQuotes(false); } @@ -129,20 +129,20 @@ public final class AptxInit // { // MainFrameApplication.warnIfNotPhyloXmlValidation(APTX_CONFIG); // } - Phylogeny[] phylogenies = PhylogenyMethods.readPhylogenies(p, treeFile); - MainFrame[] aptxFrames = new MainFrame[phylogenies.length]; + Phylogeny[] trees = PhylogenyMethods.readPhylogenies(parser, treeFile); + MainFrame[] aptxFrames = new MainFrame[trees.length]; String treeTitle = treeFile.getName(); - for (int i = 0; i < phylogenies.length; i++) + for (int i = 0; i < trees.length; i++) { - Phylogeny tree = phylogenies[i]; + Phylogeny tree = trees[i]; if (nhx_or_nexus && INTERNAL_NUMBERS_AS_CONFIDENCE) { PhylogenyMethods.transferInternalNodeNamesToConfidence(tree, ""); } - aptxFrames[i] = createAptxFrame(tree, viewport, treeTitle); + } if (Desktop.instance != null) { @@ -193,10 +193,6 @@ public final class AptxInit public static MainFrame[] createInstancesFromDb(int databaseIndex, AlignmentViewport viewport) { - if (Desktop.desktop != null) - { - // Desktop.desktop.startLoading(treeTitle); - } URL url = null; Phylogeny[] trees = null; @@ -209,22 +205,25 @@ public final class AptxInit client.getInstructions() + "\n(Reference: " + client.getReference() + ")", client.getDescription(), JvOptionPane.QUESTION_MESSAGE); + if ((identifier != null) && (identifier.trim().length() > 0)) { + if (Desktop.instance != null) + { + Desktop.instance.startLoading(identifier); + } + identifier = identifier.trim(); if (client.isQueryInteger()) { identifier = identifier.replaceAll("^\\D+", ""); - int id = -1; + + int id; 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); @@ -471,17 +470,16 @@ public final class AptxInit { MainFrame aptxApp = Archaeopteryx.createApplication(aptxTree, APTX_CONFIG, treeTitle); - // addPartitioningSlider(aptxApp); - - LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation( + LoadedTreeSequenceAssociation bindAptxNodes = new LoadedTreeSequenceAssociation( jalviewAlignport.getAlignment().getSequencesArray(), aptxTree); - bindAptxNodes.associateLeavesToSequences(); + bindNodesToJalviewSequences(aptxApp, jalviewAlignport, bindAptxNodes.getAlignmentWithNodes(), bindAptxNodes.getNodesWithAlignment()); - bindFrameToJalview(aptxApp); + bindTreeViewFrameToJalview(aptxApp); + return aptxApp; } @@ -503,7 +501,8 @@ public final class AptxInit } - public static MainFrame bindFrameToJalview(final MainFrame aptxApp) + public static MainFrame bindTreeViewFrameToJalview( + final MainFrame aptxApp) { int width = 400; int height = 550; diff --git a/src/jalview/ext/archaeopteryx/LoadedTreeAssociation.java b/src/jalview/ext/archaeopteryx/LoadedTreeSequenceAssociation.java similarity index 97% rename from src/jalview/ext/archaeopteryx/LoadedTreeAssociation.java rename to src/jalview/ext/archaeopteryx/LoadedTreeSequenceAssociation.java index c869cd5..1bc71b4 100644 --- a/src/jalview/ext/archaeopteryx/LoadedTreeAssociation.java +++ b/src/jalview/ext/archaeopteryx/LoadedTreeSequenceAssociation.java @@ -13,7 +13,7 @@ import java.util.Map; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyNode; -public class LoadedTreeAssociation +public class LoadedTreeSequenceAssociation implements ExternalLoadedTreeAssociationI { SequenceI[] alignSequences; @@ -24,7 +24,7 @@ public class LoadedTreeAssociation Map nodesWithAlignment; - public LoadedTreeAssociation(SequenceI[] alignmentSequences, + public LoadedTreeSequenceAssociation(SequenceI[] alignmentSequences, Phylogeny aptxTree) { alignSequences = alignmentSequences; diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 97120fc..5f26925 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -4031,6 +4031,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } + /** + * Disgustingly hardcoded atm. + * + * @param databaseIndex + */ public void chooseTreeDb(int databaseIndex) { AptxInit.createInstancesFromDb(databaseIndex, viewport); -- 1.7.10.2