import jalview.ext.treeviewer.ExternalTreeBuilderI;
import jalview.ext.treeviewer.ExternalTreeViewerBindingI;
import jalview.gui.Desktop;
+import jalview.gui.JvOptionPane;
+import jalview.util.MessageManager;
import jalview.viewmodel.AlignmentViewport;
import java.awt.Dimension;
+import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import org.forester.archaeopteryx.Archaeopteryx;
import org.forester.archaeopteryx.Configuration;
import org.forester.archaeopteryx.MainFrame;
+import org.forester.io.parsers.PhylogenyParser;
+import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
import org.forester.io.parsers.nhx.NHXParser;
+import org.forester.io.parsers.util.ParserUtils;
import org.forester.phylogeny.Phylogeny;
+import org.forester.phylogeny.PhylogenyMethods;
import org.forester.phylogeny.PhylogenyNode;
+import org.forester.util.ForesterUtil;
/**
* Static class for creating Archaeopteryx tree viewer instances from calculated
*/
public static MainFrame createUnboundInstance(final Phylogeny aptxTree)
{
- Phylogeny[] aptxTrees = { aptxTree };
- return createAptxFrame(aptxTrees);
+ return createAptxFrame(aptxTree);
}
// public static MainFrame createInstance(final Phylogeny[] aptxTrees,
calculatedTree);
Phylogeny aptxTree = aptxTreeBuilder.buildTree();
- Phylogeny[] aptxTrees = { aptxTree }; // future possibility to load in
- // several trees simultaneously
- MainFrame aptxApp = createAptxFrame(aptxTrees);
+ MainFrame aptxApp = createAptxFrame(aptxTree);
bindNodesToJalviewSequences(aptxApp, calculatedTree.getAvport(),
aptxTreeBuilder.getAlignmentBoundNodes(),
}
- public static MainFrame createInstanceFromFile(String filePath,
+ /**
+ * Refactored from Archaeopteryx.main
+ *
+ * @param filePath
+ * @param viewport
+ * @return
+ * @throws IOException
+ * @throws FileNotFoundException
+ */
+ public static MainFrame[] createInstancesFromFile(String filePath,
AlignmentViewport viewport)
+ throws FileNotFoundException, IOException
{
- String[] AptxArgs = new String[] { "-c",
- APTX_CONFIG.getConfigFilename(), filePath };
- MainFrame aptxApp = Archaeopteryx.main(AptxArgs);
-
- int tabCount = aptxApp.getMainPanel().getTabbedPane().getTabCount();
-
- for (int i = 0; i < tabCount; i++)
+ File treeFile = new File(filePath);
+ final String err = ForesterUtil.isReadableFile(treeFile);
+ if (!ForesterUtil.isEmpty(err))
{
- // roundabout way to select each tree because getComponentAt(i) requires
- // casting to TreePanel which doesn't work
- aptxApp.getMainPanel().getTabbedPane().setSelectedIndex(i);
- Phylogeny tree = aptxApp.getMainPanel().getCurrentTreePanel()
- .getPhylogeny();
-
- LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
- viewport.getAlignment().getSequencesArray(),
- tree);
+ JvOptionPane.showMessageDialog(Desktop.desktop, err,
+ MessageManager.getString("label.problem_reading_tree_file"),
+ JvOptionPane.WARNING_MESSAGE);
+ }
+ boolean nhx_or_nexus = false;
+ final PhylogenyParser p = ParserUtils.createParserDependingOnFileType(
+ treeFile, VALIDATE_PHYLOXML_XSD);
+ if (p instanceof NHXParser)
+ {
+ nhx_or_nexus = true;
+ final NHXParser nhx = (NHXParser) p;
+ nhx.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES);
+ nhx.setIgnoreQuotes(false);
+ nhx.setTaxonomyExtraction(TAXONOMY_EXTRACTION);
+ }
+ else if (p instanceof NexusPhylogeniesParser)
+ {
+ nhx_or_nexus = true;
+ final NexusPhylogeniesParser nex = (NexusPhylogeniesParser) p;
+ nex.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES);
+ nex.setIgnoreQuotes(false);
+ }
+// else if (p instanceof PhyloXmlParser)
+// {
+// MainFrameApplication.warnIfNotPhyloXmlValidation(APTX_CONFIG);
+// }
+ Phylogeny[] phylogenies = PhylogenyMethods.readPhylogenies(p, treeFile);
+ MainFrame[] aptxFrames = new MainFrame[phylogenies.length];
+ String treeTitle = treeFile.getName();
+
+ for (int i = 0; i < phylogenies.length; i++)
+ {
+ Phylogeny tree = phylogenies[i];
+ if (nhx_or_nexus && INTERNAL_NUMBERS_AS_CONFIDENCE)
+ {
+ PhylogenyMethods.transferInternalNodeNamesToConfidence(tree, "");
+ }
+
+ MainFrame aptxApp = Archaeopteryx.createApplication(tree, APTX_CONFIG,
+ treeTitle);
+ LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
+ viewport.getAlignment().getSequencesArray(), tree);
- bindAptxNodes.associateLeavesToSequences();
+ bindAptxNodes.associateLeavesToSequences();
+ bindNodesToJalviewSequences(aptxApp, viewport,
+ bindAptxNodes.getAlignmentWithNodes(),
+ bindAptxNodes.getNodesWithAlignment());
+ bindFrameToJalview(aptxApp);
+ aptxFrames[i] = aptxApp;
+ }
- bindNodesToJalviewSequences(aptxApp, viewport,
- bindAptxNodes.getAlignmentWithNodes(),
- bindAptxNodes.getNodesWithAlignment());
+ return aptxFrames;
}
- return bindFrameToJalview(aptxApp);
- }
- public static MainFrame createInstanceFromUrl(URL treeUrl,
+
+ public static MainFrame[] createInstancesFromUrl(URL treeUrl,
AlignmentViewport viewport)
throws FileNotFoundException, IOException, RuntimeException
{
+
String treeTitle = treeUrl.getFile();
Phylogeny[] trees = AptxUtil.readPhylogeniesFromUrl(treeUrl,
VALIDATE_PHYLOXML_XSD,
REPLACE_NHX_UNDERSCORES, INTERNAL_NUMBERS_AS_CONFIDENCE,
TAXONOMY_EXTRACTION, MIDPOINT_REROOT);
- MainFrame aptxApp = Archaeopteryx.createApplication(trees, APTX_CONFIG,
- treeTitle);
- for (Phylogeny tree : trees)
+ MainFrame[] aptxFrames = new MainFrame[trees.length];
+ for (int i = 0; i < trees.length; i++)
{
+ Phylogeny tree = trees[i];
+ MainFrame aptxApp = Archaeopteryx.createApplication(tree, APTX_CONFIG,
+ treeTitle);
LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
viewport.getAlignment().getSequencesArray(), tree);
bindNodesToJalviewSequences(aptxApp, viewport,
bindAptxNodes.getAlignmentWithNodes(),
bindAptxNodes.getNodesWithAlignment());
-
+ bindFrameToJalview(aptxApp);
+ aptxFrames[i] = aptxApp;
}
- return bindFrameToJalview(aptxApp);
+ return aptxFrames;
}
public static MainFrame createAptxFrame(
- final Phylogeny[] aptxTrees)
+ final Phylogeny aptxTree)
{
- MainFrame aptxApp = Archaeopteryx.createApplication(aptxTrees,
+ MainFrame aptxApp = Archaeopteryx.createApplication(aptxTree,
APTX_CONFIG, null);
return aptxApp;
}