X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Fforester%2Fio%2FTreeParser.java;h=43fd1fa564d95fc3eafc069124f90c4c4b57a420;hb=57c323c357199f78a812adb4d63290a3347f4097;hp=b5a29bfed9d784738fe16bd3b367083643c1bd7c;hpb=b6c5f18ed142f770c8ff9bbe4a5000dbb277080e;p=jalview.git diff --git a/src/jalview/ext/forester/io/TreeParser.java b/src/jalview/ext/forester/io/TreeParser.java index b5a29bf..43fd1fa 100644 --- a/src/jalview/ext/forester/io/TreeParser.java +++ b/src/jalview/ext/forester/io/TreeParser.java @@ -1,24 +1,26 @@ package jalview.ext.forester.io; -import jalview.ext.archaeopteryx.ArchaeopteryxInit; +import jalview.ext.archaeopteryx.AptxInit; +import jalview.gui.AlignViewport; +//import jalview.ext.treeviewer.ExternalTreeParserI; import jalview.gui.Desktop; import jalview.gui.JvOptionPane; +import jalview.io.DataSourceType; +import jalview.io.NewickFile; import jalview.util.MessageManager; import java.io.File; import java.io.IOException; -import org.forester.archaeopteryx.Archaeopteryx; -import org.forester.archaeopteryx.MainFrame; import org.forester.util.ForesterUtil; -public class TreeParser +public class TreeParser // implements ExternalTreeParserI { private final String filePath; private final File file; - public TreeParser(String treeFilePath) + public TreeParser(final String treeFilePath) { final String possibleError = ForesterUtil.isReadableFile(treeFilePath); if (possibleError != null) @@ -31,10 +33,9 @@ public class TreeParser filePath = treeFilePath; file = new File(filePath); - } - public TreeParser(File treeFile) throws IOException + public TreeParser(final File treeFile) throws IOException { final String possibleError = ForesterUtil.isReadableFile(treeFile); if (possibleError != null) @@ -48,70 +49,150 @@ public class TreeParser filePath = file.getCanonicalPath(); } - - public void loadTree() + public void loadTree(AlignViewport viewport) { - String[] AptxArgs = new String[] { "-c", - "_aptx_jalview_configuration_file", filePath }; - MainFrame aptx = Archaeopteryx.main(AptxArgs); - ArchaeopteryxInit.bindFrameToJalview(aptx); - + NewickFile fin = null; // old tree + try + { + AptxInit.createInstanceFromFile(filePath, viewport); + + fin = new NewickFile(filePath, DataSourceType.FILE); + viewport.setCurrentTree(viewport.getAlignPanel().alignFrame + .showNewickTree(fin, filePath).getTree()); + + } catch (Exception ex) + { + JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(), + MessageManager.getString("label.problem_reading_tree_file"), + JvOptionPane.WARNING_MESSAGE); + ex.printStackTrace(); + } + if (fin != null && fin.hasWarningMessage()) + { + JvOptionPane.showMessageDialog(Desktop.desktop, + fin.getWarningMessage(), + MessageManager + .getString("label.possible_problem_with_tree_file"), + JvOptionPane.WARNING_MESSAGE); + } + } } -} -/** - * Mostly refactored from Archaeopteryx.main() and - * MainFrameApplication.readPhylogeniesFromFile() - */ -// boolean nhx_or_nexus = false; -// Configuration config = new Configuration( -// "_aptx_jalview_configuration_file", false, false, false); -// try -// { -// final PhylogenyParser p = ParserUtils.createParserDependingOnFileType( -// file, config.isValidatePhyloXmlAgainstSchema()); + // -// if (p instanceof NHXParser) +// @Override +// public MainFrame loadTreeFile(AlignmentViewport viewport) // { +// String[] AptxArgs = new String[] { "-c", +// "_aptx_jalview_configuration_file", filePath }; +// MainFrame aptx = Archaeopteryx.main(AptxArgs); +// +// LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation( +// viewport.getAlignment().getSequencesArray(), +// aptx.getMainPanel().getCurrentTreePanel().getPhylogeny()); +// +// bindAptxNodes.associateLeavesToSequences(); +// +// new JalviewBinding(aptx, viewport, bindAptxNodes.getAlignmentWithNodes(), +// bindAptxNodes.getNodesWithAlignment()); +// +// AptxInit.bindFrameToJalview(aptx); +// +// return aptx; +// +// +// } +// // +// 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; -// final NHXParser nhx = (NHXParser) p; -// nhx.setReplaceUnderscores(false); -// nhx.setIgnoreQuotes(false); -// nhx.setTaxonomyExtraction(config.getTaxonomyExtraction()); // } -// else if (p instanceof NexusPhylogeniesParser) -// { +// else if ( parser instanceof NHXParser ) { // nhx_or_nexus = true; -// final NexusPhylogeniesParser nex = (NexusPhylogeniesParser) p; -// nex.setReplaceUnderscores(config.isReplaceUnderscoresInNhParsing()); -// nex.setIgnoreQuotes(false); // } -// else if (p instanceof PhyloXmlParser) -// { -// +// if ( _mainpanel.getCurrentTreePanel() != null ) { +// _mainpanel.getCurrentTreePanel().setWaitCursor(); // } -// Phylogeny[] phylogenies = PhylogenyMethods.readPhylogenies(p, file); -// if (nhx_or_nexus -// && config.isInternalNumberAreConfidenceForNhParsing()) -// { -// for (final Phylogeny phy : phylogenies) -// { -// PhylogenyMethods.transferInternalNodeNamesToConfidence(phy, ""); -// +// 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 (IOException e) -// { -// // TODO Auto-generated catch block -// e.printStackTrace(); +// 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(); +// } +// +// } +// +// +// +// +// +//