JAL-2794 Aptx instances get their parent alignment, start on binding
[jalview.git] / src / jalview / ext / archaeopteryx / ArchaeopteryxInit.java
1 package jalview.ext.archaeopteryx;
2
3 import jalview.analysis.TreeBuilder;
4 import jalview.datamodel.SequenceI;
5 import jalview.gui.Desktop;
6 import jalview.viewmodel.AlignmentViewport;
7
8 import java.awt.Dimension;
9 import java.util.Map;
10
11 import org.forester.archaeopteryx.Archaeopteryx;
12 import org.forester.archaeopteryx.MainFrame;
13 import org.forester.phylogeny.Phylogeny;
14 import org.forester.phylogeny.PhylogenyNode;
15
16 public final class ArchaeopteryxInit
17 {
18   /**
19    * This method should generally not be used as it does not bind the tree to
20    * its alignment
21    * 
22    * @param aptxTrees
23    * @return
24    */
25   public static MainFrame createUnboundInstance(Phylogeny aptxTree)
26   {
27     Phylogeny[] aptxTrees = { aptxTree };
28     return createBoundAptxFrame(aptxTrees, null);
29   }
30
31   public static MainFrame createInstance(Phylogeny[] aptxTrees,
32           AlignmentViewport jalviewAlignmentView)
33   {
34     return createBoundAptxFrame(aptxTrees, jalviewAlignmentView);
35
36   }
37
38   public static MainFrame createInstance(Phylogeny aptxTree,
39           AlignmentViewport jalviewAlignmentView)
40   {
41     Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in
42     // several trees simultaneously
43     return createBoundAptxFrame(aptxTrees, jalviewAlignmentView);
44
45   }
46
47   public static MainFrame createInstance(
48           TreeBuilder calculatedTree) // very dense method, to be split up
49   {
50     ArchaeopteryxTreeConverter aptxTreeBuilder = new ArchaeopteryxTreeConverter(
51             calculatedTree);
52
53     Phylogeny aptxTree = aptxTreeBuilder.buildAptxTree();
54     Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in
55                                           // several trees simultaneously
56
57     MainFrame aptxApp = createBoundAptxFrame(aptxTrees,
58             calculatedTree.getAvport());
59     bindNodesToJalviewSequences(aptxApp, calculatedTree.getAvport(),
60             aptxTreeBuilder.getAlignmentBoundNodes());
61     return bindFrameToJalview(aptxApp);
62
63   }
64
65
66
67
68   private static MainFrame createBoundAptxFrame(Phylogeny[] aptxTrees,
69           AlignmentViewport jalviewAlignmentView)
70   {
71     MainFrame aptxApp = Archaeopteryx.createApplication(aptxTrees,
72             "_aptx_jalview_configuration_file", null);
73
74     return aptxApp;
75   }
76
77   private static void bindNodesToJalviewSequences(MainFrame aptxApp,
78           AlignmentViewport jalviewAlignViewport,
79           Map<SequenceI, PhylogenyNode> alignMappedToNodes)
80   {
81     new JalviewAptxBinding(aptxApp, jalviewAlignViewport,
82             alignMappedToNodes);
83   }
84
85
86   private static MainFrame bindFrameToJalview(MainFrame aptxApp)
87   {
88     int width = 400;
89     int height = 550;
90     aptxApp.setMinimumSize(new Dimension(width, height));
91
92     Desktop.addInternalFrame(aptxApp, "Archaeopteryx Tree View", true,
93             width, height, true, true);
94
95     return aptxApp;
96
97   }
98
99
100 }