X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Farchaeopteryx%2FArchaeopteryxInit.java;h=744bf04e8dc5b680d4abcb7e78745ffa031ad45d;hb=4b25259949fbc582a579aa91922cde6f838155ea;hp=04147cee82437227d4f808680666aa932d724eea;hpb=0e50368033402ab4eb49fb7473fbb232d7b6091b;p=jalview.git diff --git a/src/jalview/ext/archaeopteryx/ArchaeopteryxInit.java b/src/jalview/ext/archaeopteryx/ArchaeopteryxInit.java index 04147ce..744bf04 100644 --- a/src/jalview/ext/archaeopteryx/ArchaeopteryxInit.java +++ b/src/jalview/ext/archaeopteryx/ArchaeopteryxInit.java @@ -1,123 +1,109 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) - * Copyright (C) $$Year-Rel$$ The Jalview Authors - * - * This file is part of Jalview. - * - * Jalview is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 - * of the License, or (at your option) any later version. - * - * Jalview is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Jalview. If not, see . - * The Jalview Authors are detailed in the 'AUTHORS' file. - */ package jalview.ext.archaeopteryx; -import jalview.analysis.TreeModel; -import jalview.io.NewickFile; +import jalview.analysis.TreeBuilder; +import jalview.datamodel.SequenceI; +import jalview.gui.Desktop; +import jalview.viewmodel.AlignmentViewport; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.PrintWriter; +import java.awt.Dimension; +import java.util.Map; import org.forester.archaeopteryx.Archaeopteryx; +import org.forester.archaeopteryx.MainFrame; +import org.forester.phylogeny.Phylogeny; +import org.forester.phylogeny.PhylogenyNode; -public class ArchaeopteryxInit +/** + * Static class for creating Archaeopteryx tree viewer instances from calculated + * trees and letting them be bound to Jalview. + * + * @author kjvanderheide + * + */ +public final class ArchaeopteryxInit { - private String filePath = "/tmp/jalviewtree.nwk"; - - private TreeModel tree; - - private NewickFile newickTree; - - public ArchaeopteryxInit(TreeModel jalviewTreeModel) + /** + * Test method, should generally not be used as it does not bind the tree to + * its alignment + * + * @param aptxTrees + * @return + */ + public static MainFrame createUnboundInstance(final Phylogeny aptxTree) { - this.tree = jalviewTreeModel; - this.newickTree = treeToNewick(tree); + Phylogeny[] aptxTrees = { aptxTree }; + return createBoundAptxFrame(aptxTrees, null); } - public ArchaeopteryxInit(NewickFile newickTreeModel) + public static MainFrame createInstance(final Phylogeny[] aptxTrees, + AlignmentViewport jalviewAlignmentView) { - this.newickTree = newickTreeModel; + return createBoundAptxFrame(aptxTrees, jalviewAlignmentView); + } - public void startArchaeopteryx() + public static MainFrame createInstance(final Phylogeny aptxTree, + final AlignmentViewport jalviewAlignmentView) { - String newickOutput = newickTree.print(newickTree.hasBootstrap(), - newickTree.hasDistances(), newickTree.hasRootDistance()); + Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in + // several trees simultaneously + return createBoundAptxFrame(aptxTrees, jalviewAlignmentView); - File newickFile = new File(filePath); - PrintWriter writer; + } - try - { - writer = new PrintWriter(newickFile); - writer.println(newickOutput); + public static MainFrame createInstance( + final TreeBuilder calculatedTree) // very dense method, to be split up + { + ArchaeopteryxTreeConverter aptxTreeBuilder = new ArchaeopteryxTreeConverter( + calculatedTree); - writer.close(); + Phylogeny aptxTree = aptxTreeBuilder.buildAptxTree(); + Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in + // several trees simultaneously - String[] commandLineArgs = { "-open", newickFile.getCanonicalPath() }; - Archaeopteryx.main(commandLineArgs); + MainFrame aptxApp = createBoundAptxFrame(aptxTrees, + calculatedTree.getAvport()); + bindNodesToJalviewSequences(aptxApp, calculatedTree.getAvport(), + aptxTreeBuilder.getAlignmentBoundNodes(), + aptxTreeBuilder.getNodesBoundAlignment()); + return bindFrameToJalview(aptxApp); - } catch (FileNotFoundException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } + } - } - public String getFilePath() + private static MainFrame createBoundAptxFrame(final Phylogeny[] aptxTrees, + final AlignmentViewport jalviewAlignmentView) { - return filePath; - } + MainFrame aptxApp = Archaeopteryx.createApplication(aptxTrees, + "_aptx_jalview_configuration_file", null); - public void setFilePath(String newFilePath) - { - this.filePath = newFilePath; + return aptxApp; } - public TreeModel getTree() + private static void bindNodesToJalviewSequences(final MainFrame aptxApp, + final AlignmentViewport jalviewAlignViewport, + final Map alignMappedToNodes, + final Map nodesMappedToAlign) { - return tree; + new JalviewAptxBinding(aptxApp, jalviewAlignViewport, + alignMappedToNodes, nodesMappedToAlign); } - public void setTree(TreeModel newTree) - { - this.tree = newTree; - } - public NewickFile getNewickTree() + private static MainFrame bindFrameToJalview(final MainFrame aptxApp) { - return newickTree; - } + int width = 400; + int height = 550; + aptxApp.setMinimumSize(new Dimension(width, height)); - public void setNewickTree(NewickFile newNewickTree) - { - this.newickTree = newNewickTree; - } + Desktop.addInternalFrame(aptxApp, "Archaeopteryx Tree View", true, + width, height, true, true); - public static NewickFile treeToNewick(TreeModel tree) - { - NewickFile newickTree = new NewickFile(tree.getTopNode(), - tree.hasBootstrap(), tree.hasDistances(), - tree.hasRootDistance()); + return aptxApp; - return newickTree; } -} \ No newline at end of file + +}