From 19262eceac6a9d7a77c5a4220ab07042bd545e98 Mon Sep 17 00:00:00 2001 From: kjvdheide Date: Tue, 9 Jan 2018 11:51:02 +0000 Subject: [PATCH] JAL-2805 added Aptx factory method reading directly from a File --- src/jalview/ext/archaeopteryx/AptxInit.java | 126 ++++++++++++++------------- 1 file changed, 66 insertions(+), 60 deletions(-) diff --git a/src/jalview/ext/archaeopteryx/AptxInit.java b/src/jalview/ext/archaeopteryx/AptxInit.java index f8347bd..ba34213 100644 --- a/src/jalview/ext/archaeopteryx/AptxInit.java +++ b/src/jalview/ext/archaeopteryx/AptxInit.java @@ -88,84 +88,90 @@ public final class AptxInit return aptxApp; } - - /** - * Refactored from Archaeopteryx.main - * - * @param filePath - * @param viewport - * @return - * @throws IOException - * @throws FileNotFoundException - */ - public static TreeFrameI[] createInstancesFromFile( - String filePath, + public static TreeFrameI[] createInstancesFromFile(File treeFile, AlignmentViewport viewport) throws FileNotFoundException, IOException { - File treeFile = new File(filePath); TreeFrameI[] aptxFrames = null; if (UtilityMethods.canForesterReadFile(treeFile)) { - if (Desktop.instance != null) - { - Desktop.instance.startLoading(filePath); - } - boolean nhx_or_nexus = false; - final PhylogenyParser parser = ParserUtils - .createParserDependingOnFileType( - treeFile, VALIDATE_PHYLOXML_XSD); - if (parser instanceof NHXParser) - { - nhx_or_nexus = true; - final NHXParser nhx = (NHXParser) parser; - nhx.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES); - nhx.setIgnoreQuotes(false); - nhx.setTaxonomyExtraction(TAXONOMY_EXTRACTION); - } - else if (parser instanceof NexusPhylogeniesParser) - { - nhx_or_nexus = true; - final NexusPhylogeniesParser nex = (NexusPhylogeniesParser) parser; - nex.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES); - nex.setIgnoreQuotes(false); - } - else if (parser instanceof PhyloXmlParser) - { - if (VALIDATE_PHYLOXML_XSD == false) + if (Desktop.instance != null) { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString("error.phyloxml_validation"), - MessageManager.getString("label.file_open_error"), - JvOptionPane.WARNING_MESSAGE ); + Desktop.instance.startLoading(treeFile.getCanonicalPath()); } - } - Phylogeny[] trees = PhylogenyMethods.readPhylogenies(parser, - treeFile); + boolean nhx_or_nexus = false; + final PhylogenyParser parser = ParserUtils + .createParserDependingOnFileType(treeFile, + VALIDATE_PHYLOXML_XSD); + if (parser instanceof NHXParser) + { + nhx_or_nexus = true; + final NHXParser nhx = (NHXParser) parser; + nhx.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES); + nhx.setIgnoreQuotes(false); + nhx.setTaxonomyExtraction(TAXONOMY_EXTRACTION); + } + else if (parser instanceof NexusPhylogeniesParser) + { + nhx_or_nexus = true; + final NexusPhylogeniesParser nex = (NexusPhylogeniesParser) parser; + nex.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES); + nex.setIgnoreQuotes(false); + } + else if (parser instanceof PhyloXmlParser) + { + if (VALIDATE_PHYLOXML_XSD == false) + { + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + MessageManager.getString("error.phyloxml_validation"), + MessageManager.getString("label.file_open_error"), + JvOptionPane.WARNING_MESSAGE); + } + } + Phylogeny[] trees = PhylogenyMethods.readPhylogenies(parser, + treeFile); aptxFrames = new TreeFrameI[trees.length]; - - for (int i = 0; i < trees.length; i++) + for (int i = 0; i < trees.length; i++) { - Phylogeny aptxPhylogeny = trees[i]; + Phylogeny aptxPhylogeny = trees[i]; - if (nhx_or_nexus && INTERNAL_NUMBERS_AS_CONFIDENCE) - { - PhylogenyMethods.transferInternalNodeNamesToConfidence(aptxPhylogeny, - ""); - } - String treeTitle = treeFile.getName() + "[" + i + "]"; - aptxPhylogeny.setName(treeTitle); + if (nhx_or_nexus && INTERNAL_NUMBERS_AS_CONFIDENCE) + { + PhylogenyMethods + .transferInternalNodeNamesToConfidence(aptxPhylogeny, ""); + } + String treeTitle = treeFile.getName() + "[" + i + "]"; + aptxPhylogeny.setName(treeTitle); aptxFrames[i] = createAptxFrame(aptxPhylogeny, viewport, treeTitle); - } - if (Desktop.instance != null) - { - Desktop.instance.stopLoading(); + } + if (Desktop.instance != null) + { + Desktop.instance.stopLoading(); } } return aptxFrames; + } + + /** + * Refactored from Archaeopteryx.main + * + * @param filePath + * @param viewport + * @return + * @throws IOException + * @throws FileNotFoundException + */ + public static TreeFrameI[] createInstancesFromFile( + String filePath, + AlignmentViewport viewport) + throws FileNotFoundException, IOException + { + File treeFile = new File(filePath); + return createInstancesFromFile(treeFile, viewport); + } -- 1.7.10.2