package jalview.ext.archaeopteryx;
-import jalview.analysis.TreeBuilder;
-import jalview.datamodel.SequenceI;
-import jalview.ext.forester.UtilityMethods;
+import jalview.ext.forester.io.UtilityMethods;
import jalview.ext.treeviewer.LoadedTreeAssociationI;
-import jalview.ext.treeviewer.TreeBuilderI;
+import jalview.ext.treeviewer.LoadedTreeSequenceAssociation;
import jalview.ext.treeviewer.TreeFrameI;
import jalview.ext.treeviewer.TreeI;
-import jalview.ext.treeviewer.TreeNodeI;
-import jalview.ext.treeviewer.TreeViewerBindingI;
-import jalview.ext.treeviewer.LoadedTreeSequenceAssociation;
+import jalview.ext.treeviewer.TreeViewerUtils;
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.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
import org.forester.archaeopteryx.AptxUtil;
import org.forester.archaeopteryx.Configuration;
*/
public final class AptxInit
{
+ public final static InputStream CONFIG_LOC = AptxInit.class
+
+ .getResourceAsStream("/_aptx_jalview_configuration_file.txt");
+
public final static Configuration APTX_CONFIG = new Configuration(
- "_aptx_jalview_configuration_file",
- false, false, false);
+ CONFIG_LOC,
+ false, false);
// static
// {
// APTX_CONFIG.setBaseFontFamilyName(
private final static NHXParser.TAXONOMY_EXTRACTION TAXONOMY_EXTRACTION = APTX_CONFIG
.getTaxonomyExtraction();
- private static Map<TreeFrameI, TreeViewerBindingI> activeAptx = new HashMap<>();
+ public static TreeFrameI createInstanceFromNhx(String treeTitle,
+ String nhxString, AlignmentViewport viewport)
+ throws IOException
+ {
+ if (Desktop.instance != null)
+ {
+ Desktop.instance.startLoading(treeTitle);
+ }
+ Phylogeny aptxPhylogeny = Phylogeny
+ .createInstanceFromNhxString(nhxString);
+ aptxPhylogeny.setName(treeTitle);
+ TreeFrameI aptxFrame = createAptxFrame(aptxPhylogeny, viewport,
+ treeTitle);
- public static TreeFrameI createInstanceFromCalculation(
- final TreeBuilder calculatedTree)
- {
- TreeBuilderI aptxTreeBuilder = new AptxTreeBuilder(
- calculatedTree);
+ if (Desktop.instance != null)
+ {
+ Desktop.instance.stopLoading();
+ }
- TreeI aptxTree = aptxTreeBuilder.buildTree();
+ return aptxFrame;
- TreeFrameI aptxApp = createAptxFrame(aptxTree,
- calculatedTree.getAvport(), null);
-
- return aptxApp;
}
-
/**
* Refactored from Archaeopteryx.main
*
* @throws IOException
* @throws FileNotFoundException
*/
- public static TreeFrameI[] createInstancesFromFile(
- String filePath,
+ public static TreeFrameI[] createInstancesFromFile(File treeFile,
AlignmentViewport viewport)
throws FileNotFoundException, IOException
{
- File treeFile = new File(filePath);
TreeFrameI[] aptxFrames = null;
if (UtilityMethods.canForesterReadFile(treeFile))
{
- if (Desktop.instance != null)
- {
- Desktop.instance.startLoading(filePath);
- }
- boolean nhx_or_nexus = false;
- final PhylogenyParser parser = ParserUtils
- .createParserDependingOnFileType(
- treeFile, VALIDATE_PHYLOXML_XSD);
- if (parser instanceof NHXParser)
- {
- nhx_or_nexus = true;
- final NHXParser nhx = (NHXParser) parser;
- nhx.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES);
- nhx.setIgnoreQuotes(false);
- nhx.setTaxonomyExtraction(TAXONOMY_EXTRACTION);
- }
- else if (parser instanceof NexusPhylogeniesParser)
- {
- nhx_or_nexus = true;
- final NexusPhylogeniesParser nex = (NexusPhylogeniesParser) parser;
- nex.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES);
- nex.setIgnoreQuotes(false);
- }
- else if (parser instanceof PhyloXmlParser)
- {
- if (VALIDATE_PHYLOXML_XSD == false)
+ if (Desktop.instance != null)
{
- JvOptionPane.showInternalMessageDialog(Desktop.desktop,
- MessageManager.getString("error.phyloxml_validation"),
- MessageManager.getString("label.file_open_error"),
- JvOptionPane.WARNING_MESSAGE );
+ Desktop.instance.startLoading(treeFile.getCanonicalPath());
}
- }
- Phylogeny[] trees = PhylogenyMethods.readPhylogenies(parser,
- treeFile);
+ boolean nhx_or_nexus = false;
+ final PhylogenyParser parser = ParserUtils
+ .createParserDependingOnFileType(treeFile,
+ VALIDATE_PHYLOXML_XSD);
+ if (parser instanceof NHXParser)
+ {
+ nhx_or_nexus = true;
+ final NHXParser nhx = (NHXParser) parser;
+ nhx.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES);
+ nhx.setIgnoreQuotes(false);
+ nhx.setTaxonomyExtraction(TAXONOMY_EXTRACTION);
+ }
+ else if (parser instanceof NexusPhylogeniesParser)
+ {
+ nhx_or_nexus = true;
+ final NexusPhylogeniesParser nex = (NexusPhylogeniesParser) parser;
+ nex.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES);
+ nex.setIgnoreQuotes(false);
+ }
+ else if (parser instanceof PhyloXmlParser)
+ {
+ if (VALIDATE_PHYLOXML_XSD == false)
+ {
+ JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+ MessageManager.getString("error.phyloxml_validation"),
+ MessageManager.getString("label.file_open_error"),
+ JvOptionPane.WARNING_MESSAGE);
+ }
+ }
+ Phylogeny[] trees = PhylogenyMethods.readPhylogenies(parser,
+ treeFile);
aptxFrames = new TreeFrameI[trees.length];
-
- for (int i = 0; i < trees.length; i++)
+ for (int i = 0; i < trees.length; i++)
{
- Phylogeny aptxPhylogeny = trees[i];
+ Phylogeny aptxPhylogeny = trees[i];
- if (nhx_or_nexus && INTERNAL_NUMBERS_AS_CONFIDENCE)
- {
- PhylogenyMethods.transferInternalNodeNamesToConfidence(aptxPhylogeny,
- "");
- }
- String treeTitle = treeFile.getName() + "[" + i + "]";
- aptxPhylogeny.setName(treeTitle);
+ if (nhx_or_nexus && INTERNAL_NUMBERS_AS_CONFIDENCE)
+ {
+ PhylogenyMethods
+ .transferInternalNodeNamesToConfidence(aptxPhylogeny, "");
+ }
+ String treeTitle = treeFile.getName() + "[" + i + "]";
+ aptxPhylogeny.setName(treeTitle);
aptxFrames[i] = createAptxFrame(aptxPhylogeny, viewport, treeTitle);
- }
- if (Desktop.instance != null)
- {
- Desktop.instance.stopLoading();
+ }
+ if (Desktop.instance != null)
+ {
+ Desktop.instance.stopLoading();
}
}
return aptxFrames;
- }
+ }
+
+
+ public static TreeFrameI[] createInstancesFromFile(
+ String filePath,
+ AlignmentViewport viewport)
+ throws FileNotFoundException, IOException
+ {
+ File treeFile = new File(filePath);
+ return createInstancesFromFile(treeFile, viewport);
+ }
public static TreeFrameI[] createInstancesFromUrl(URL treeUrl,
AlignmentViewport viewport)
{
// Not important if this fails, do nothing.
}
- // _main_frame.getContentPane().repaint();
}
}
- System.gc();
-
if (Desktop.instance != null)
{
jalviewTree);
bindAptxNodes.associateLeavesToSequences();
- bindNodesToJalviewSequences(aptxApp, jalviewAlignport,
+ TreeViewerUtils.associateNodesWithJalviewSequences(aptxApp, jalviewAlignport,
bindAptxNodes.getAlignmentWithNodes(),
bindAptxNodes.getNodesWithAlignment());
- bindTreeViewFrameToJalview(aptxApp);
+ TreeViewerUtils.addTreeViewFrameToJalview(aptxApp);
// adaptAptxGui(aptxApp); //moved to AptxFrame
return aptxApp;
jalviewTree);
bindAptxNodes.associateLeavesToSequences();
- bindNodesToJalviewSequences(aptxApp, jalviewAlignport,
+ TreeViewerUtils.associateNodesWithJalviewSequences(aptxApp, jalviewAlignport,
bindAptxNodes.getAlignmentWithNodes(),
bindAptxNodes.getNodesWithAlignment());
- bindTreeViewFrameToJalview(aptxApp);
+ TreeViewerUtils.addTreeViewFrameToJalview(aptxApp);
// adaptAptxGui(aptxApp); //moved to AptxFrame
return aptxApp;
}
- protected static TreeViewerBindingI bindNodesToJalviewSequences(
- final TreeFrameI aptxApp,
- final AlignmentViewport jalviewAlignViewport,
- final Map<SequenceI, TreeNodeI> alignMappedToNodes,
- final Map<TreeNodeI, SequenceI> nodesMappedToAlign)
- {
- TreeViewerBindingI treeBinding = new JalviewBinding(aptxApp,
- jalviewAlignViewport,
- alignMappedToNodes, nodesMappedToAlign);
- activeAptx.put(aptxApp, treeBinding);
- return treeBinding;
- }
-
-
- protected static TreeFrameI bindTreeViewFrameToJalview(
- final TreeFrameI aptxApp)
- {
- int width = 400;
- int height = 550;
- aptxApp.setMinimumSize(new Dimension(width, height));
- // aptxApp.setFont(Desktop.instance.getFont());
- // aptxApp.getMainPanel().setFont(Desktop.instance.getFont());
- String frameTitle = MessageManager.getString("label.aptx_title");
- File treeFile = aptxApp.getTreePanel().getTreeFile();
- if (treeFile != null)
- {
- frameTitle += MessageManager.formatMessage("label.aptx_title_append",
- new String[]
- { treeFile.getAbsolutePath() });
- }
- aptxApp.addFrameToJalview(frameTitle, true, width, height, true,
- true);
- return aptxApp;
-
- }
-
private static boolean validateConfig(Configuration aptxConfig)
{
if (aptxConfig == null || aptxConfig.isCouldReadConfigFile() == false)
}
-
- public static Map<TreeFrameI, TreeViewerBindingI> getAllAptxFrames()
- {
- return activeAptx;
- }
-
-
}