JAL-2805 functional binding on loading associated trees
[jalview.git] / src / jalview / ext / forester / io / ForesterTreeParser.java
1 package jalview.ext.forester.io;
2
3 import jalview.ext.archaeopteryx.AptxBinding;
4 import jalview.ext.archaeopteryx.AptxNodeAssociation;
5 import jalview.ext.archaeopteryx.ArchaeopteryxInit;
6 import jalview.gui.Desktop;
7 import jalview.gui.JvOptionPane;
8 import jalview.util.MessageManager;
9 import jalview.viewmodel.AlignmentViewport;
10
11 import java.io.File;
12 import java.io.IOException;
13
14 import org.forester.archaeopteryx.Archaeopteryx;
15 import org.forester.archaeopteryx.MainFrame;
16 import org.forester.util.ForesterUtil;
17
18 public class ForesterTreeParser implements ExternalTreeParserI<MainFrame>
19 {
20   private final String filePath;
21
22   private final File file;
23
24   public ForesterTreeParser(final String treeFilePath)
25   {
26     final String possibleError = ForesterUtil.isReadableFile(treeFilePath);
27     if (possibleError != null)
28     {
29       JvOptionPane.showMessageDialog(Desktop.desktop, possibleError,
30               MessageManager.getString("label.problem_reading_tree_file"),
31               JvOptionPane.WARNING_MESSAGE);
32
33     }
34     filePath = treeFilePath;
35     file = new File(filePath);
36
37
38   }
39
40   public ForesterTreeParser(final File treeFile) throws IOException
41   {
42     final String possibleError = ForesterUtil.isReadableFile(treeFile);
43     if (possibleError != null)
44     {
45       JvOptionPane.showMessageDialog(Desktop.desktop, possibleError,
46               MessageManager.getString("label.problem_reading_tree_file"),
47               JvOptionPane.WARNING_MESSAGE);
48
49     }
50     file = treeFile;
51     filePath = file.getCanonicalPath();
52   }
53
54   @Override
55   public MainFrame loadTree(AlignmentViewport viewport)
56   {
57     String[] AptxArgs = new String[] { "-c",
58         "_aptx_jalview_configuration_file", filePath };
59     MainFrame aptx = Archaeopteryx.main(AptxArgs);
60
61     AptxNodeAssociation bindAptxNodes = new AptxNodeAssociation(
62             viewport.getAlignment().getSequencesArray(),
63             aptx.getMainPanel().getCurrentTreePanel().getPhylogeny());
64
65     bindAptxNodes.associateLeavesToSequences();
66     new AptxBinding(aptx, viewport, bindAptxNodes.getAlignmentWithNodes(),
67             bindAptxNodes.getNodesWithAlignment());
68
69     ArchaeopteryxInit.bindFrameToJalview(aptx);
70
71     return aptx;
72
73
74   }
75
76 }
77
78
79
80
81
82