import jalview.viewmodel.AlignmentViewport;
import java.awt.Dimension;
+import java.io.FileNotFoundException;
+import java.io.IOException;
import java.net.URL;
import java.util.Map;
+import org.forester.archaeopteryx.AptxUtil;
import org.forester.archaeopteryx.Archaeopteryx;
+import org.forester.archaeopteryx.Configuration;
import org.forester.archaeopteryx.MainFrame;
+import org.forester.io.parsers.nhx.NHXParser;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyNode;
*/
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();
+
/**
* Test method, should generally not be used as it does not bind the tree to
* its alignment
AlignmentViewport viewport)
{
String[] AptxArgs = new String[] { "-c",
- "_aptx_jalview_configuration_file", filePath };
+ APTX_CONFIG.getConfigFilename(), filePath };
MainFrame aptxApp = Archaeopteryx.main(AptxArgs);
+ int tabCount = aptxApp.getMainPanel().getTabbedPane().getTabCount();
+
+ for (int i = 0; i < tabCount; i++)
+ {
+ // 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(),
- aptxApp.getMainPanel().getCurrentTreePanel().getPhylogeny());
+ tree);
bindAptxNodes.associateLeavesToSequences();
bindNodesToJalviewSequences(aptxApp, viewport,
bindAptxNodes.getAlignmentWithNodes(),
bindAptxNodes.getNodesWithAlignment());
-
+ }
return bindFrameToJalview(aptxApp);
}
- public static MainFrame createInstanceFromUrl(URL url)
+ public static MainFrame createInstanceFromUrl(URL treeUrl,
+ AlignmentViewport viewport)
+ throws FileNotFoundException, IOException
{
+
+ 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,
+ null);
+
+ for (Phylogeny tree : trees)
+ {
+ LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
+ viewport.getAlignment().getSequencesArray(), tree);
+
+ bindAptxNodes.associateLeavesToSequences();
+ bindNodesToJalviewSequences(aptxApp, viewport,
+ bindAptxNodes.getAlignmentWithNodes(),
+ bindAptxNodes.getNodesWithAlignment());
+
+ }
+
+ return bindFrameToJalview(aptxApp);
- return null;
- // void readPhylogeniesFromURL() {
- // URL url = null;
- // Phylogeny[] phys = null;
- // final String message = "Please enter a complete URL, for example
- // \"http://purl.org/phylo/treebase/phylows/study/TB2:S15480?format=nexus\"";
- // final String url_string = JOptionPane
- // .showInputDialog( this,
- // message,
- // "Use URL/webservice to obtain a phylogeny",
- // JOptionPane.QUESTION_MESSAGE );
- // boolean nhx_or_nexus = false;
- // if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
- // try {
- // url = new URL( url_string );
- // PhylogenyParser parser = null;
- // if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
- // parser = new TolParser();
- // }
- // else {
- // parser = ParserUtils
- // .createParserDependingOnUrlContents( url,
- // getConfiguration().isValidatePhyloXmlAgainstSchema() );
- // }
- // if ( parser instanceof NexusPhylogeniesParser ) {
- // nhx_or_nexus = true;
- // }
- // else if ( parser instanceof NHXParser ) {
- // nhx_or_nexus = true;
- // }
- // if ( _mainpanel.getCurrentTreePanel() != null ) {
- // _mainpanel.getCurrentTreePanel().setWaitCursor();
- // }
- // else {
- // _mainpanel.setWaitCursor();
- // }
- // final PhylogenyFactory factory =
- // ParserBasedPhylogenyFactory.getInstance();
- // phys = factory.create( url.openStream(), parser );
- // }
- // catch ( final MalformedURLException e ) {
- // JOptionPane.showMessageDialog( this,
- // "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
- // "Malformed URL",
- // JOptionPane.ERROR_MESSAGE );
- // }
- // catch ( final IOException e ) {
- // JOptionPane.showMessageDialog( this,
- // "Could not read from " + url + "\n"
- // + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
- // "Failed to read URL",
- // JOptionPane.ERROR_MESSAGE );
- // }
- // catch ( final Exception e ) {
- // JOptionPane.showMessageDialog( this,
- // ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
- // "Unexpected Exception",
- // JOptionPane.ERROR_MESSAGE );
- // }
- // finally {
- // if ( _mainpanel.getCurrentTreePanel() != null ) {
- // _mainpanel.getCurrentTreePanel().setArrowCursor();
- // }
- // else {
- // _mainpanel.setArrowCursor();
- // }
- // }
- // if ( ( phys != null ) && ( phys.length > 0 ) ) {
- // if ( nhx_or_nexus &&
- // getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
- // for( final Phylogeny phy : phys ) {
- // PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" );
- // }
- // }
- // AptxUtil.addPhylogeniesToTabs( phys,
- // new File( url.getFile() ).getName(),
- // new File( url.getFile() ).toString(),
- // getConfiguration(),
- // getMainPanel() );
- // _mainpanel.getControlPanel().showWhole();
- // }
- // }
- // activateSaveAllIfNeeded();
- // System.gc();
- // }
}
final Phylogeny[] aptxTrees)
{
MainFrame aptxApp = Archaeopteryx.createApplication(aptxTrees,
- "_aptx_jalview_configuration_file", null);
+ APTX_CONFIG, null);
return aptxApp;
}
import java.beans.PropertyChangeEvent;
import java.io.File;
import java.io.FileWriter;
+import java.io.IOException;
import java.io.PrintWriter;
-import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
}
}
+ /**
+ * Move to TreeParser?
+ */
public void chooseTreeUrl()
{
- URL treeUrl;
+
JLabel label = new JLabel(
MessageManager.getString("label.tree_url_example"));
+ // add "example" button
final JComboBox<String> history = new JComboBox<>();
JPanel panel = new JPanel(new GridLayout(2, 1));
history.addItem(st.nextToken());
}
}
- String urlString = JvOptionPane.showInputDialog(this,
- panel,
+
+ int reply = JvOptionPane.showInternalConfirmDialog(this, panel,
MessageManager.getString("label.load_tree_url"),
- JvOptionPane.QUESTION_MESSAGE);
- if ((urlString != null) && (!urlString.isEmpty()))
+ JvOptionPane.OK_CANCEL_OPTION);
+
+ if (reply == JvOptionPane.OK_OPTION)
{
+
+ String urlString = history.getSelectedItem().toString();
+ URL treeUrl;
+
try
{
+ FileFormatI format = null;
+
+ format = new IdentifyFile().identify(urlString, DataSourceType.URL);
+ // add actual use for the format identification (jalview .jar files)
treeUrl = new URL(urlString);
- AptxInit.createInstanceFromUrl(treeUrl);
+ AptxInit.createInstanceFromUrl(treeUrl, viewport);
- } catch (MalformedURLException e)
+ } catch (IOException e)
{
JvOptionPane.showMessageDialog(this,
MessageManager.formatMessage(
{ urlString }),
MessageManager.getString("label.url_not_found")
, JvOptionPane.ERROR_MESSAGE);
+ e.printStackTrace();
}
+ }
+ else
+ {
}