import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import org.forester.archaeopteryx.Archaeopteryx;
import org.forester.archaeopteryx.Configuration;
import org.forester.archaeopteryx.MainFrame;
+import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
+import org.forester.archaeopteryx.webservices.WebserviceUtil;
+import org.forester.archaeopteryx.webservices.WebservicesManager;
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.phyloxml.PhyloXmlDataFormatException;
+import org.forester.io.parsers.phyloxml.PhyloXmlParser;
+import org.forester.io.parsers.tol.TolParser;
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.phylogeny.data.Identifier;
import org.forester.util.ForesterUtil;
/**
public static MainFrame createInstanceFromCalculation(
- final TreeBuilder calculatedTree) // very dense method, to be split up
+ final TreeBuilder calculatedTree)
{
ExternalTreeBuilderI<Phylogeny, PhylogenyNode> aptxTreeBuilder = new AptxTreeBuilder(
calculatedTree);
MessageManager.getString("label.problem_reading_tree_file"),
JvOptionPane.WARNING_MESSAGE);
}
+
+ if (Desktop.instance != null)
+ {
+ Desktop.instance.startLoading(filePath);
+ }
boolean nhx_or_nexus = false;
final PhylogenyParser p = ParserUtils.createParserDependingOnFileType(
treeFile, VALIDATE_PHYLOXML_XSD);
aptxFrames[i] = createAptxFrame(tree, viewport, treeTitle);
}
-
+ if (Desktop.instance != null)
+ {
+ Desktop.instance.stopLoading();
+ }
return aptxFrames;
}
{
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,
aptxFrames[i] = createAptxFrame(tree, viewport, treeTitle);
}
+ if (Desktop.instance != null)
+ {
+ Desktop.instance.stopLoading();
+ }
+
return aptxFrames;
}
+ /**
+ * Refactored from Forester's UrlTreeReader
+ *
+ * @param databaseIndex
+ * @param viewport
+ * @return
+ */
+ public static MainFrame[] createInstancesFromDb(int databaseIndex,
+ AlignmentViewport viewport)
+ {
+ if (Desktop.desktop != null)
+ {
+ // Desktop.desktop.startLoading(treeTitle);
+ }
+
+ URL url = null;
+ Phylogeny[] trees = null;
+ final WebservicesManager webservices_manager = WebservicesManager
+ .getInstance();
+ final PhylogeniesWebserviceClient client = webservices_manager
+ .getAvailablePhylogeniesWebserviceClient(databaseIndex);
+ String identifier = JvOptionPane.showInternalInputDialog(
+ Desktop.desktop,
+ client.getInstructions() + "\n(Reference: "
+ + client.getReference() + ")",
+ client.getDescription(), JvOptionPane.QUESTION_MESSAGE);
+ if ((identifier != null) && (identifier.trim().length() > 0))
+ {
+ identifier = identifier.trim();
+ if (client.isQueryInteger())
+ {
+ identifier = identifier.replaceAll("^\\D+", "");
+ int id = -1;
+ try
+ {
+ id = Integer.parseInt(identifier);
+ } catch (final NumberFormatException e)
+ {
+ id = -1;
+ }
+ if (id < 1)
+ {
+ JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+ "Identifier is expected to be a number",
+ "Can not open URL", JvOptionPane.ERROR_MESSAGE);
+ return new MainFrame[0];
+ }
+ identifier = id + "";
+ }
+ boolean exception = false;
+ try
+ {
+ String url_str = client.getUrl();
+ url_str = url_str.replaceFirst(
+ PhylogeniesWebserviceClient.QUERY_PLACEHOLDER, identifier);
+ url = new URL(url_str);
+ PhylogenyParser parser = null;
+ switch (client.getReturnFormat())
+ {
+ case TOL_XML_RESPONSE:
+ parser = new TolParser();
+ break;
+ case NEXUS:
+ parser = new NexusPhylogeniesParser();
+ ((NexusPhylogeniesParser) parser).setReplaceUnderscores(true);
+ break;
+ case TREEBASE_TREE:
+ parser = new NexusPhylogeniesParser();
+ ((NexusPhylogeniesParser) parser).setReplaceUnderscores(true);
+ ((NexusPhylogeniesParser) parser)
+ .setTaxonomyExtraction(NHXParser.TAXONOMY_EXTRACTION.NO);
+ break;
+ case TREEBASE_STUDY:
+ parser = new NexusPhylogeniesParser();
+ ((NexusPhylogeniesParser) parser).setReplaceUnderscores(true);
+ ((NexusPhylogeniesParser) parser)
+ .setTaxonomyExtraction(NHXParser.TAXONOMY_EXTRACTION.NO);
+ break;
+ case NH:
+ parser = new NHXParser();
+ ((NHXParser) parser)
+ .setTaxonomyExtraction(NHXParser.TAXONOMY_EXTRACTION.NO);
+ ((NHXParser) parser).setReplaceUnderscores(true);
+ ((NHXParser) parser).setGuessRootedness(true);
+ break;
+ case NH_EXTRACT_TAXONOMY:
+ parser = new NHXParser();
+ ((NHXParser) parser).setTaxonomyExtraction(
+ NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE);
+ ((NHXParser) parser).setReplaceUnderscores(false);
+ ((NHXParser) parser).setGuessRootedness(true);
+ break;
+ case PFAM:
+ parser = new NHXParser();
+ ((NHXParser) parser).setTaxonomyExtraction(
+ NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT);
+ ((NHXParser) parser).setReplaceUnderscores(false);
+ ((NHXParser) parser).setGuessRootedness(true);
+ break;
+ case NHX:
+ parser = new NHXParser();
+ ((NHXParser) parser)
+ .setTaxonomyExtraction(NHXParser.TAXONOMY_EXTRACTION.NO);
+ ((NHXParser) parser).setReplaceUnderscores(false);
+ ((NHXParser) parser).setGuessRootedness(true);
+ break;
+ case PHYLOXML:
+ parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "unknown format: " + client.getReturnFormat());
+ }
+ //
+ // if (_main_frame.getMainPanel().getCurrentTreePanel() != null)
+ // {
+ // _main_frame.getMainPanel().getCurrentTreePanel().setWaitCursor();
+ // }
+ // else
+ // {
+ // _main_frame.getMainPanel().setWaitCursor();
+ // }
+ trees = ForesterUtil.readPhylogeniesFromUrl(url, parser);
+ } catch (final MalformedURLException e)
+ {
+ exception = true;
+ JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+ "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
+ "Malformed URL", JvOptionPane.ERROR_MESSAGE);
+ } catch (final IOException e)
+ {
+ exception = true;
+ JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+ "Could not read from " + url + "\n"
+ + e.getLocalizedMessage(),
+ "Failed to read tree from " + client.getName() + " for "
+ + identifier,
+ JvOptionPane.ERROR_MESSAGE);
+ } catch (final NumberFormatException e)
+ {
+ exception = true;
+ JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+ "Could not read from " + url + "\n"
+ + e.getLocalizedMessage(),
+ "Failed to read tree from " + client.getName() + " for "
+ + identifier,
+ JvOptionPane.ERROR_MESSAGE);
+ } catch (final Exception e)
+ {
+ exception = true;
+ e.printStackTrace();
+ JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+ e.getLocalizedMessage(), "Unexpected Exception",
+ JvOptionPane.ERROR_MESSAGE);
+ } finally
+ {
+ // if (_main_frame.getCurrentTreePanel() != null)
+ // {
+ // _main_frame.getCurrentTreePanel().setArrowCursor();
+ // }
+ // else
+ // {
+ // _main_frame.getMainPanel().setArrowCursor();
+ // }
+ }
+ if ((trees != null) && (trees.length > 0))
+ {
+ for (final Phylogeny phylogeny : trees)
+ {
+ if (!phylogeny.isEmpty())
+ {
+ if (client.getName().equals(WebserviceUtil.TREE_FAM_NAME))
+ {
+ phylogeny.setRerootable(false);
+ phylogeny.setRooted(true);
+ }
+ if (client.getProcessingInstructions() != null)
+ {
+ try
+ {
+ WebserviceUtil.processInstructions(client, phylogeny);
+ } catch (final PhyloXmlDataFormatException e)
+ {
+ JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+ "Error:\n" + e.getLocalizedMessage(), "Error",
+ JvOptionPane.ERROR_MESSAGE);
+ }
+ }
+ if (client.getNodeField() != null)
+ {
+ try
+ {
+ PhylogenyMethods.transferNodeNameToField(phylogeny,
+ client.getNodeField(), false);
+ } catch (final PhyloXmlDataFormatException e)
+ {
+ JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+ "Error:\n" + e.getLocalizedMessage(), "Error",
+ JvOptionPane.ERROR_MESSAGE);
+ }
+ }
+ phylogeny.setIdentifier(
+ new Identifier(identifier, client.getName()));
+ // _main_frame.getJMenuBar().remove(_main_frame.getHelpMenu());
+ // _main_frame.getMenuBarOfMainFrame()
+ // .add(_main_frame.getHelpMenu());
+ // _main_frame.getMainPanel().addPhylogenyInNewTab(phylogeny,
+ // _main_frame.getConfiguration(),
+ // new File(url.getFile()).getName(), url.toString());
+
+ MainFrame aptxApp = createAptxFrame(phylogeny, viewport,
+ url.getFile());
+ String my_name_for_file = "";
+ if (!ForesterUtil.isEmpty(phylogeny.getName()))
+ {
+ my_name_for_file = new String(phylogeny.getName())
+ .replaceAll(" ", "_");
+ }
+ else if (phylogeny.getIdentifier() != null)
+ {
+ final StringBuffer sb = new StringBuffer();
+ if (!ForesterUtil
+ .isEmpty(phylogeny.getIdentifier().getProvider()))
+ {
+ sb.append(phylogeny.getIdentifier().getProvider());
+ sb.append("_");
+ }
+ sb.append(phylogeny.getIdentifier().getValue());
+ my_name_for_file = new String(
+ sb.toString().replaceAll(" ", "_"));
+ }
+ // _main_frame.getMainPanel().getCurrentTreePanel()
+ // .setTreeFile(new File(my_name_for_file));
+ AptxUtil.lookAtSomeTreePropertiesForAptxControlSettings(
+ phylogeny, aptxApp.getMainPanel().getControlPanel(),
+ APTX_CONFIG);
+ // _main_frame.getMainPanel().getControlPanel().showWhole();
+
+ aptxApp.activateSaveAllIfNeeded();
+ }
+ }
+ }
+ else if (!exception)
+ {
+ JvOptionPane.showMessageDialog(null,
+ ForesterUtil.wordWrap(
+ "Failed to read in tree(s) from [" + url + "]", 80),
+ "Error", JvOptionPane.ERROR_MESSAGE);
+ }
+ if ((trees != null) && (trees.length > 0))
+ {
+ try
+ {
+ JvOptionPane.showMessageDialog(null,
+ ForesterUtil.wordWrap("Successfully read in "
+ + trees.length + " tree(s) from [" + url + "]",
+ 80),
+ "Success", JvOptionPane.INFORMATION_MESSAGE);
+ } catch (final Exception e)
+ {
+ // Not important if this fails, do nothing.
+ }
+ // _main_frame.getContentPane().repaint();
+ }
+ }
+
+ System.gc();
+
+
+ if (Desktop.instance != null)
+ {
+ Desktop.instance.stopLoading();
+ }
+ return null;
+
+
+ }
+