From: kjvdheide Date: Mon, 13 Nov 2017 14:22:27 +0000 (+0000) Subject: JAL-2805 First try at loading tree through Forester by calling Aptx main X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=03e9de7cc0b1fda7a09855f884e012177e0648ee;p=jalview.git JAL-2805 First try at loading tree through Forester by calling Aptx main Added file filters for Forester supported tree formats to the file chooser window and Forester tree parser in the ActionPerformed of loading an associated tree, also see Forester commits for more details --- diff --git a/forester b/forester index a3c44ca..b977efb 160000 --- a/forester +++ b/forester @@ -1 +1 @@ -Subproject commit a3c44cae09b9d94e3cf63c5c4e776374f646bc67 +Subproject commit b977efb66f2d0b539bd433e80762737925035edc diff --git a/src/jalview/ext/archaeopteryx/ArchaeopteryxInit.java b/src/jalview/ext/archaeopteryx/ArchaeopteryxInit.java index 744bf04..dc887fb 100644 --- a/src/jalview/ext/archaeopteryx/ArchaeopteryxInit.java +++ b/src/jalview/ext/archaeopteryx/ArchaeopteryxInit.java @@ -32,24 +32,24 @@ public final class ArchaeopteryxInit public static MainFrame createUnboundInstance(final Phylogeny aptxTree) { Phylogeny[] aptxTrees = { aptxTree }; - return createBoundAptxFrame(aptxTrees, null); + return createAptxFrameInJalview(aptxTrees); } - public static MainFrame createInstance(final Phylogeny[] aptxTrees, - AlignmentViewport jalviewAlignmentView) - { - return createBoundAptxFrame(aptxTrees, jalviewAlignmentView); - - } - - public static MainFrame createInstance(final Phylogeny aptxTree, - final AlignmentViewport jalviewAlignmentView) - { - Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in - // several trees simultaneously - return createBoundAptxFrame(aptxTrees, jalviewAlignmentView); - - } + // public static MainFrame createInstance(final Phylogeny[] aptxTrees, + // AlignmentViewport jalviewAlignmentView) + // { + // return createAptxFrameInJalview(aptxTrees); + // + // } + // + // public static MainFrame createInstance(final Phylogeny aptxTree, + // final AlignmentViewport jalviewAlignmentView) + // { + // Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in + // // several trees simultaneously + // return createAptxFrameInJalview(aptxTrees); + // + // } public static MainFrame createInstance( final TreeBuilder calculatedTree) // very dense method, to be split up @@ -61,8 +61,8 @@ public final class ArchaeopteryxInit Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in // several trees simultaneously - MainFrame aptxApp = createBoundAptxFrame(aptxTrees, - calculatedTree.getAvport()); + MainFrame aptxApp = createAptxFrameInJalview(aptxTrees); + bindNodesToJalviewSequences(aptxApp, calculatedTree.getAvport(), aptxTreeBuilder.getAlignmentBoundNodes(), aptxTreeBuilder.getNodesBoundAlignment()); @@ -73,16 +73,16 @@ public final class ArchaeopteryxInit - private static MainFrame createBoundAptxFrame(final Phylogeny[] aptxTrees, - final AlignmentViewport jalviewAlignmentView) + public static MainFrame createAptxFrameInJalview( + final Phylogeny[] aptxTrees) { MainFrame aptxApp = Archaeopteryx.createApplication(aptxTrees, "_aptx_jalview_configuration_file", null); - + bindFrameToJalview(aptxApp); return aptxApp; } - private static void bindNodesToJalviewSequences(final MainFrame aptxApp, + public static void bindNodesToJalviewSequences(final MainFrame aptxApp, final AlignmentViewport jalviewAlignViewport, final Map alignMappedToNodes, final Map nodesMappedToAlign) @@ -92,7 +92,7 @@ public final class ArchaeopteryxInit } - private static MainFrame bindFrameToJalview(final MainFrame aptxApp) + public static MainFrame bindFrameToJalview(final MainFrame aptxApp) { int width = 400; int height = 550; diff --git a/src/jalview/ext/forester/io/SupportedTreeFileFilter.java b/src/jalview/ext/forester/io/SupportedTreeFileFilter.java new file mode 100644 index 0000000..214dd1d --- /dev/null +++ b/src/jalview/ext/forester/io/SupportedTreeFileFilter.java @@ -0,0 +1,36 @@ +package jalview.ext.forester.io; + + +import javax.swing.filechooser.FileFilter; + +import org.forester.archaeopteryx.MainFrame; + + +public enum SupportedTreeFileFilter +{ + NHFILTER(MainFrame.nhfilter), NHXFILTER(MainFrame.nhxfilter), + XMLFILTER(MainFrame.xmlfilter), TOLFILTER(MainFrame.tolfilter), + NEXUSFILTER(MainFrame.nexusfilter); + + private final FileFilter treeFilter; + + SupportedTreeFileFilter(FileFilter treeFilter) + { + this.treeFilter = treeFilter; + + } + + public void printSupportedFormats() + { + for (SupportedTreeFileFilter format : SupportedTreeFileFilter.values()) + { + System.out.println(format.getTreeFilter().getDescription()); + } + } + + public FileFilter getTreeFilter() + { + return treeFilter; + } + +} diff --git a/src/jalview/ext/forester/io/TreeParser.java b/src/jalview/ext/forester/io/TreeParser.java new file mode 100644 index 0000000..7d097bd --- /dev/null +++ b/src/jalview/ext/forester/io/TreeParser.java @@ -0,0 +1,108 @@ +package jalview.ext.forester.io; + +import jalview.ext.archaeopteryx.ArchaeopteryxInit; + +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 +{ + private final String filePath; + + private final File file; + + public TreeParser(String treeFilePath) + { + final String possibleError = ForesterUtil.isReadableFile(treeFilePath); + if (possibleError != null) + { + // something + } + filePath = treeFilePath; + file = new File(filePath); + + + } + + public TreeParser(File treeFile) throws IOException + { + final String possibleError = ForesterUtil.isReadableFile(treeFile); + if (possibleError != null) + { + // something + } + file = treeFile; + filePath = file.getCanonicalPath(); + } + + + public void loadTree() + { + String[] AptxArgs = new String[] { "-c", + "_aptx_jalview_configuration_file", filePath }; + MainFrame aptx = Archaeopteryx.main(AptxArgs); + ArchaeopteryxInit.bindFrameToJalview(aptx); + + + } +} + +/** + * Mostly refactored from Archaeopteryx.main() and + * MainFrameApplication.readPhylogeniesFromFile() + */ +// boolean nhx_or_nexus = false; +// Configuration config = new Configuration( +// "_aptx_jalview_configuration_file", false, false, false); +// try +// { +// final PhylogenyParser p = ParserUtils.createParserDependingOnFileType( +// file, config.isValidatePhyloXmlAgainstSchema()); +// +// if (p instanceof NHXParser) +// { +// nhx_or_nexus = true; +// final NHXParser nhx = (NHXParser) p; +// nhx.setReplaceUnderscores(false); +// nhx.setIgnoreQuotes(false); +// nhx.setTaxonomyExtraction(config.getTaxonomyExtraction()); +// } +// else if (p instanceof NexusPhylogeniesParser) +// { +// nhx_or_nexus = true; +// final NexusPhylogeniesParser nex = (NexusPhylogeniesParser) p; +// nex.setReplaceUnderscores(config.isReplaceUnderscoresInNhParsing()); +// nex.setIgnoreQuotes(false); +// } +// else if (p instanceof PhyloXmlParser) +// { +// +// } +// Phylogeny[] phylogenies = PhylogenyMethods.readPhylogenies(p, file); +// if (nhx_or_nexus +// && config.isInternalNumberAreConfidenceForNhParsing()) +// { +// for (final Phylogeny phy : phylogenies) +// { +// PhylogenyMethods.transferInternalNodeNamesToConfidence(phy, ""); +// +// } +// } +// } +// +// catch (IOException e) +// { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// } + + + + + + diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 774a4f1..4e3df8b 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -60,6 +60,8 @@ import jalview.datamodel.SeqCigar; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.ext.forester.io.SupportedTreeFileFilter; +import jalview.ext.forester.io.TreeParser; import jalview.gui.ColourMenuHelper.ColourChangeListener; import jalview.gui.ViewSelectionMenu.ViewSetProvider; import jalview.io.AlignmentProperties; @@ -3882,9 +3884,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, jalview.bin.Cache.getProperty("LAST_DIRECTORY")); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle( - MessageManager.getString("label.select_newick_like_tree_file")); + MessageManager.getString("label.select_newick_like_tree_file")); // modify chooser.setToolTipText( MessageManager.getString("label.load_tree_file")); + for (SupportedTreeFileFilter treeFormat : SupportedTreeFileFilter.values()) + { + chooser.setFileFilter(treeFormat.getTreeFilter()); + } int value = chooser.showOpenDialog(null); @@ -3892,9 +3898,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { String filePath = chooser.getSelectedFile().getPath(); Cache.setProperty("LAST_DIRECTORY", filePath); + NewickFile fin = null; try { + TreeParser treeParser = new TreeParser(filePath); + treeParser.loadTree(); + + + fin = new NewickFile(filePath, DataSourceType.FILE); viewport.setCurrentTree(showNewickTree(fin, filePath).getTree()); } catch (Exception ex)