85f57b69edd24fe4ad11a51f0bd15e0f0e14752c
[jalview.git] / src / jalview / ext / forester / io / TreeParser.java
1 package jalview.ext.forester.io;
2
3 import jalview.ext.archaeopteryx.ArchaeopteryxInit;
4 import jalview.gui.Desktop;
5 import jalview.gui.JvOptionPane;
6 import jalview.util.MessageManager;
7
8 import java.io.File;
9 import java.io.IOException;
10
11 import org.forester.archaeopteryx.Archaeopteryx;
12 import org.forester.archaeopteryx.MainFrame;
13 import org.forester.util.ForesterUtil;
14
15 public class TreeParser implements TreeParserI<MainFrame>
16 {
17   private final String filePath;
18
19   private final File file;
20
21   public TreeParser(final String treeFilePath)
22   {
23     final String possibleError = ForesterUtil.isReadableFile(treeFilePath);
24     if (possibleError != null)
25     {
26       JvOptionPane.showMessageDialog(Desktop.desktop, possibleError,
27               MessageManager.getString("label.problem_reading_tree_file"),
28               JvOptionPane.WARNING_MESSAGE);
29
30     }
31     filePath = treeFilePath;
32     file = new File(filePath);
33
34
35   }
36
37   public TreeParser(final File treeFile) throws IOException
38   {
39     final String possibleError = ForesterUtil.isReadableFile(treeFile);
40     if (possibleError != null)
41     {
42       JvOptionPane.showMessageDialog(Desktop.desktop, possibleError,
43               MessageManager.getString("label.problem_reading_tree_file"),
44               JvOptionPane.WARNING_MESSAGE);
45
46     }
47     file = treeFile;
48     filePath = file.getCanonicalPath();
49   }
50
51   @Override
52   public MainFrame loadTree()
53   {
54     String[] AptxArgs = new String[] { "-c",
55         "_aptx_jalview_configuration_file", filePath };
56     MainFrame aptx = Archaeopteryx.main(AptxArgs);
57     ArchaeopteryxInit.bindFrameToJalview(aptx);
58     return aptx;
59
60
61   }
62
63 }
64
65 /**
66  * Mostly refactored from Archaeopteryx.main() and
67  * MainFrameApplication.readPhylogeniesFromFile()
68  */
69 // boolean nhx_or_nexus = false;
70 // Configuration config = new Configuration(
71 // "_aptx_jalview_configuration_file", false, false, false);
72 // try
73 // {
74 // final PhylogenyParser p = ParserUtils.createParserDependingOnFileType(
75 // file, config.isValidatePhyloXmlAgainstSchema());
76 //
77 // if (p instanceof NHXParser)
78 // {
79 // nhx_or_nexus = true;
80 // final NHXParser nhx = (NHXParser) p;
81 // nhx.setReplaceUnderscores(false);
82 // nhx.setIgnoreQuotes(false);
83 // nhx.setTaxonomyExtraction(config.getTaxonomyExtraction());
84 // }
85 // else if (p instanceof NexusPhylogeniesParser)
86 // {
87 // nhx_or_nexus = true;
88 // final NexusPhylogeniesParser nex = (NexusPhylogeniesParser) p;
89 // nex.setReplaceUnderscores(config.isReplaceUnderscoresInNhParsing());
90 // nex.setIgnoreQuotes(false);
91 // }
92 // else if (p instanceof PhyloXmlParser)
93 // {
94 //
95 // }
96 // Phylogeny[] phylogenies = PhylogenyMethods.readPhylogenies(p, file);
97 // if (nhx_or_nexus
98 // && config.isInternalNumberAreConfidenceForNhParsing())
99 // {
100 // for (final Phylogeny phy : phylogenies)
101 // {
102 // PhylogenyMethods.transferInternalNodeNamesToConfidence(phy, "");
103 //
104 // }
105 // }
106 // }
107 //
108 // catch (IOException e)
109 // {
110 // // TODO Auto-generated catch block
111 // e.printStackTrace();
112 // }
113 // }
114
115
116
117
118
119