package jalview.ext.archaeopteryx;
import jalview.analysis.TreeBuilder;
+import jalview.bin.Cache;
import jalview.datamodel.SequenceI;
import jalview.ext.treeviewer.ExternalTreeBuilderI;
import jalview.ext.treeviewer.ExternalTreeViewerBindingI;
import jalview.util.MessageManager;
import jalview.viewmodel.AlignmentViewport;
+import java.awt.Component;
import java.awt.Dimension;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JSeparator;
+
import org.forester.archaeopteryx.AptxUtil;
import org.forester.archaeopteryx.Archaeopteryx;
import org.forester.archaeopteryx.Configuration;
public final class AptxInit
{
- private final static Configuration APTX_CONFIG = new Configuration(
- "_aptx_jalview_configuration_file", false, false, false);
-
- private final static boolean VALIDATE_PHYLOXML_XSD = APTX_CONFIG
- .isValidatePhyloXmlAgainstSchema();
-
- private final static boolean REPLACE_NHX_UNDERSCORES = APTX_CONFIG
- .isReplaceUnderscoresInNhParsing();
-
- private final static boolean INTERNAL_NUMBERS_AS_CONFIDENCE = APTX_CONFIG
- .isInternalNumberAreConfidenceForNhParsing();
-
- private final static boolean MIDPOINT_REROOT = APTX_CONFIG
- .isMidpointReroot();
-
- private final static NHXParser.TAXONOMY_EXTRACTION TAXONOMY_EXTRACTION = APTX_CONFIG
- .getTaxonomyExtraction();
-
private static Map<MainFrame, JalviewBinding> activeAptx = new HashMap<>();
AlignmentViewport viewport)
throws FileNotFoundException, IOException
{
+ Configuration APTX_CONFIG = new Configuration(Cache.getDefault(
+ "APTXCONFIG",
+ Desktop.instance.getClass()
+ .getResource("/_aptx_jalview_configuration_file.txt")
+ .toString()),
+ false, false, false);
File treeFile = new File(filePath);
final String err = ForesterUtil.isReadableFile(treeFile);
if (!ForesterUtil.isEmpty(err))
}
boolean nhx_or_nexus = false;
final PhylogenyParser parser = ParserUtils.createParserDependingOnFileType(
- treeFile, VALIDATE_PHYLOXML_XSD);
+ treeFile,
+ APTX_CONFIG.isValidatePhyloXmlAgainstSchema());
if (parser instanceof NHXParser)
{
nhx_or_nexus = true;
final NHXParser nhx = (NHXParser) parser;
- nhx.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES);
+ nhx.setReplaceUnderscores(
+ APTX_CONFIG.isReplaceUnderscoresInNhParsing());
nhx.setIgnoreQuotes(false);
- nhx.setTaxonomyExtraction(TAXONOMY_EXTRACTION);
+ nhx.setTaxonomyExtraction(APTX_CONFIG.getTaxonomyExtraction());
}
else if (parser instanceof NexusPhylogeniesParser)
{
nhx_or_nexus = true;
final NexusPhylogeniesParser nex = (NexusPhylogeniesParser) parser;
- nex.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES);
+ nex.setReplaceUnderscores(
+ APTX_CONFIG.isReplaceUnderscoresInNhParsing());
nex.setIgnoreQuotes(false);
}
else if (parser instanceof PhyloXmlParser)
{
- if (VALIDATE_PHYLOXML_XSD == false)
+ if (APTX_CONFIG.isValidatePhyloXmlAgainstSchema() == false)
{
JvOptionPane.showInternalMessageDialog(Desktop.desktop,
MessageManager.getString("error.phyloxml_validation"),
{
Phylogeny tree = trees[i];
- if (nhx_or_nexus && INTERNAL_NUMBERS_AS_CONFIDENCE)
+ if (nhx_or_nexus
+ && APTX_CONFIG.isInternalNumberAreConfidenceForNhParsing())
{
PhylogenyMethods.transferInternalNodeNamesToConfidence(tree, "");
}
AlignmentViewport viewport)
throws FileNotFoundException, IOException, RuntimeException
{
-
+ Configuration APTX_CONFIG = new Configuration(Cache.getDefault(
+ "APTXCONFIG",
+ Desktop.instance.getClass()
+ .getResource("/_aptx_jalview_configuration_file.txt")
+ .toString()),
+ false, false, false);
String treeTitle = treeUrl.getFile();
if (Desktop.instance != null)
{
Desktop.instance.startLoading(treeTitle);
}
Phylogeny[] trees = AptxUtil.readPhylogeniesFromUrl(treeUrl,
- VALIDATE_PHYLOXML_XSD,
- REPLACE_NHX_UNDERSCORES, INTERNAL_NUMBERS_AS_CONFIDENCE,
- TAXONOMY_EXTRACTION, MIDPOINT_REROOT);
+ APTX_CONFIG.isValidatePhyloXmlAgainstSchema(),
+ APTX_CONFIG.isReplaceUnderscoresInNhParsing(),
+ APTX_CONFIG.isInternalNumberAreConfidenceForNhParsing(),
+ APTX_CONFIG.getTaxonomyExtraction(),
+ APTX_CONFIG.isMidpointReroot());
MainFrame[] aptxFrames = new MainFrame[trees.length];
for (int i = 0; i < trees.length; i++)
PhylogeniesWebserviceClient treeDbClient, String identifier,
AlignmentViewport viewport)
{
-
+ Configuration APTX_CONFIG = new Configuration(Cache.getDefault(
+ "APTXCONFIG",
+ Desktop.instance.getClass()
+ .getResource("/_aptx_jalview_configuration_file.txt")
+ .toString()),
+ false, false, false);
URL url = null;
Phylogeny[] trees = null;
final Phylogeny aptxTree,
final AlignmentViewport jalviewAlignport, String treeTitle)
{
+ Configuration APTX_CONFIG = new Configuration(Cache.getDefault(
+ "APTXCONFIG",
+ Desktop.instance.getClass()
+ .getResource("/_aptx_jalview_configuration_file.txt")
+ .toString()),
+ false, false, false);
+ if (APTX_CONFIG == null || APTX_CONFIG.isCouldReadConfigFile() == false)
+ {
+ int keepGoing = JvOptionPane.showConfirmDialog(Desktop.desktop,
+ MessageManager.getString("label.aptx_config_not_found"),
+ MessageManager.formatMessage("label.couldnt_locate",
+ new String[]
+ { "_aptx_jalview_configuration_file" }),
+ JvOptionPane.YES_NO_CANCEL_OPTION);
+
+ if (keepGoing == JvOptionPane.CANCEL_OPTION
+ || keepGoing == JvOptionPane.CLOSED_OPTION
+ || keepGoing == JvOptionPane.NO_OPTION)
+ {
+ return null;
+ }
+
+ }
MainFrame aptxApp = Archaeopteryx.createApplication(aptxTree,
APTX_CONFIG, treeTitle);
+
LoadedTreeSequenceAssociation bindAptxNodes = new LoadedTreeSequenceAssociation(
jalviewAlignport.getAlignment().getSequencesArray(), aptxTree);
bindAptxNodes.associateLeavesToSequences();
bindAptxNodes.getNodesWithAlignment());
bindTreeViewFrameToJalview(aptxApp);
+ adaptAptxGui(aptxApp);
return aptxApp;
}
}
+ /**
+ * Hides certain redundant Archaeopteryx GUI elements such as the menu items
+ * for reading in trees and adds extra items related to Jalview such as the
+ * tree sorting item.
+ *
+ *
+ * @param aptxFrame
+ */
+ private static void adaptAptxGui(MainFrame aptxFrame)
+ {
+ JMenuBar frameBar = aptxFrame.getJMenuBar();
+
+ for (int i = 0; i < frameBar.getMenuCount();i++) {
+ JMenu menu = frameBar.getMenu(i);
+
+ if (menu.getText().contains("File"))
+ {
+ // hide all "Read from ..." and "New" menu items and any Separators that
+ // come directly after them
+ Component previousMenuItem = null;
+ for (Component menuItem : menu.getMenuComponents()) {
+ if (previousMenuItem instanceof JMenuItem)
+ {
+ if (((JMenuItem) previousMenuItem).getText().startsWith("Read")
+ || ((JMenuItem) previousMenuItem).getText()
+ .startsWith("New"))
+ {
+ previousMenuItem.setVisible(false);
+
+ if (menuItem instanceof JSeparator)
+ {
+ menuItem.setVisible(false);
+ }
+ }
+ }
+ previousMenuItem = menuItem;
+ }
+ }
+ else if (menu.getText().contains("Inference"))
+ {
+ menu.setVisible(false);
+ }
+ else if (menu.getText().contains("View"))
+ {
+ menu.addSeparator();
+ JMenuItem sortByTree = new JMenuItem("Sort alignment by tree");
+ JMenuItem refreshJalview = new JMenuItem(
+ "Filter alignment to show only currently visible sequences");
+
+ refreshJalview.setFont(menu.getFont());
+
+ menu.add(sortByTree);
+ menu.add(refreshJalview);
+
+ sortByTree.setFont(menu.getFont());
+ sortByTree.setVisible(false); // don't show unless it's actually
+ // possible
+
+ refreshJalview.addActionListener(activeAptx.get(aptxFrame));
+
+
+ }
+
+ }
+ aptxFrame.validate();
+ }
+
public static Map<MainFrame, JalviewBinding> getAllAptxFrames()
{
return activeAptx;