JAL-2805 loads of file reorganizing, interfaces expanded
[jalview.git] / src / jalview / ext / forester / io / TreeParser.java
index b5a29bf..2c08e99 100644 (file)
@@ -1,9 +1,13 @@
 package jalview.ext.forester.io;
 
+import jalview.ext.archaeopteryx.JalviewBinding;
+import jalview.ext.archaeopteryx.LoadedTreeAssociation;
 import jalview.ext.archaeopteryx.ArchaeopteryxInit;
+import jalview.ext.treeviewer.ExternalTreeParserI;
 import jalview.gui.Desktop;
 import jalview.gui.JvOptionPane;
 import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
 
 import java.io.File;
 import java.io.IOException;
@@ -12,13 +16,13 @@ import org.forester.archaeopteryx.Archaeopteryx;
 import org.forester.archaeopteryx.MainFrame;
 import org.forester.util.ForesterUtil;
 
-public class TreeParser
+public class TreeParser implements ExternalTreeParserI<MainFrame>
 {
   private final String filePath;
 
   private final File file;
 
-  public TreeParser(String treeFilePath)
+  public TreeParser(final String treeFilePath)
   {
     final String possibleError = ForesterUtil.isReadableFile(treeFilePath);
     if (possibleError != null)
@@ -34,7 +38,7 @@ public class TreeParser
 
   }
 
-  public TreeParser(File treeFile) throws IOException
+  public TreeParser(final File treeFile) throws IOException
   {
     final String possibleError = ForesterUtil.isReadableFile(treeFile);
     if (possibleError != null)
@@ -48,67 +52,29 @@ public class TreeParser
     filePath = file.getCanonicalPath();
   }
 
-
-  public void loadTree()
+  @Override
+  public MainFrame loadTree(AlignmentViewport viewport)
   {
     String[] AptxArgs = new String[] { "-c",
         "_aptx_jalview_configuration_file", filePath };
     MainFrame aptx = Archaeopteryx.main(AptxArgs);
+
+    LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
+            viewport.getAlignment().getSequencesArray(),
+            aptx.getMainPanel().getCurrentTreePanel().getPhylogeny());
+
+    bindAptxNodes.associateLeavesToSequences();
+    new JalviewBinding(aptx, viewport, bindAptxNodes.getAlignmentWithNodes(),
+            bindAptxNodes.getNodesWithAlignment());
+
     ArchaeopteryxInit.bindFrameToJalview(aptx);
 
+    return 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();
-// }
-// }
+}