From f975d866f1108d926b27a92c3d270bbe8f1273e6 Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Fri, 3 Jun 2011 19:57:27 +0000 Subject: [PATCH] in progress --- .../org/forester/archaeopteryx/Archaeopteryx.java | 2 +- .../archaeopteryx/MainFrameApplication.java | 16 +++--- .../java/src/org/forester/archaeopteryx/Util.java | 10 ---- .../org/forester/surfacing/SurfacingConstants.java | 2 +- .../src/org/forester/test/examples/Example1.java | 59 ++++++++++++++++++++ .../java/src/org/forester/util/ForesterUtil.java | 12 ++++ 6 files changed, 81 insertions(+), 20 deletions(-) create mode 100644 forester/java/src/org/forester/test/examples/Example1.java diff --git a/forester/java/src/org/forester/archaeopteryx/Archaeopteryx.java b/forester/java/src/org/forester/archaeopteryx/Archaeopteryx.java index b9bdcb8..3593218 100644 --- a/forester/java/src/org/forester/archaeopteryx/Archaeopteryx.java +++ b/forester/java/src/org/forester/archaeopteryx/Archaeopteryx.java @@ -110,7 +110,7 @@ public final class Archaeopteryx { else if ( p instanceof PhyloXmlParser ) { MainFrameApplication.warnIfNotPhyloXmlValidation( conf ); } - phylogenies = Util.readPhylogenies( p, f ); + phylogenies = ForesterUtil.readPhylogenies( p, f ); if ( nhx_or_nexus && conf.isInternalNumberAreConfidenceForNhParsing() ) { for( final Phylogeny phy : phylogenies ) { ForesterUtil.transferInternalNodeNamesToConfidence( phy ); diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index 9d3fab4..b1dda81 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -1630,7 +1630,7 @@ public final class MainFrameApplication extends MainFrame { try { final NHXParser nhx = new NHXParser(); setSpecialOptionsForNhxParser( nhx ); - phys = Util.readPhylogenies( nhx, file ); + phys = ForesterUtil.readPhylogenies( nhx, file ); nhx_or_nexus = true; } catch ( final Exception e ) { @@ -1642,7 +1642,7 @@ public final class MainFrameApplication extends MainFrame { warnIfNotPhyloXmlValidation( getConfiguration() ); try { final PhyloXmlParser xml_parser = createPhyloXmlParser(); - phys = Util.readPhylogenies( xml_parser, file ); + phys = ForesterUtil.readPhylogenies( xml_parser, file ); } catch ( final Exception e ) { exception = true; @@ -1651,7 +1651,7 @@ public final class MainFrameApplication extends MainFrame { } else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) { try { - phys = Util.readPhylogenies( new TolParser(), file ); + phys = ForesterUtil.readPhylogenies( new TolParser(), file ); } catch ( final Exception e ) { exception = true; @@ -1662,7 +1662,7 @@ public final class MainFrameApplication extends MainFrame { try { final NexusPhylogeniesParser nex = new NexusPhylogeniesParser(); setSpecialOptionsForNexParser( nex ); - phys = Util.readPhylogenies( nex, file ); + phys = ForesterUtil.readPhylogenies( nex, file ); nhx_or_nexus = true; } catch ( final Exception e ) { @@ -1689,7 +1689,7 @@ public final class MainFrameApplication extends MainFrame { else if ( parser instanceof PhyloXmlParser ) { warnIfNotPhyloXmlValidation( getConfiguration() ); } - phys = Util.readPhylogenies( parser, file ); + phys = ForesterUtil.readPhylogenies( parser, file ); } catch ( final Exception e ) { exception = true; @@ -2044,7 +2044,7 @@ public final class MainFrameApplication extends MainFrame { if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) { if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) { try { - final Phylogeny[] trees = Util.readPhylogenies( new PhyloXmlParser(), file ); + final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file ); t = trees[ 0 ]; } catch ( final Exception e ) { @@ -2054,7 +2054,7 @@ public final class MainFrameApplication extends MainFrame { } else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) { try { - final Phylogeny[] trees = Util.readPhylogenies( new TolParser(), file ); + final Phylogeny[] trees = ForesterUtil.readPhylogenies( new TolParser(), file ); t = trees[ 0 ]; } catch ( final Exception e ) { @@ -2065,7 +2065,7 @@ public final class MainFrameApplication extends MainFrame { // "*.*": else { try { - final Phylogeny[] trees = Util.readPhylogenies( new PhyloXmlParser(), file ); + final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file ); t = trees[ 0 ]; } catch ( final Exception e ) { diff --git a/forester/java/src/org/forester/archaeopteryx/Util.java b/forester/java/src/org/forester/archaeopteryx/Util.java index 408a3d7..198dc1a 100644 --- a/forester/java/src/org/forester/archaeopteryx/Util.java +++ b/forester/java/src/org/forester/archaeopteryx/Util.java @@ -57,7 +57,6 @@ import javax.swing.text.MaskFormatter; import org.forester.io.parsers.PhylogenyParser; import org.forester.io.parsers.tol.TolParser; -import org.forester.io.parsers.util.PhylogenyParserException; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyMethods; import org.forester.phylogeny.PhylogenyNode; @@ -618,15 +617,6 @@ public final class Util { System.out.println( "[" + name + "] > " + message ); } - final static Phylogeny[] readPhylogenies( final PhylogenyParser parser, final File file ) throws IOException { - final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - final Phylogeny[] trees = factory.create( file, parser ); - if ( ( trees == null ) || ( trees.length == 0 ) ) { - throw new PhylogenyParserException( "Unable to parse phylogeny from file: " + file ); - } - return trees; - } - final static Phylogeny[] readPhylogeniesFromUrl( final URL url, final boolean phyloxml_validate_against_xsd ) throws FileNotFoundException, IOException { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); diff --git a/forester/java/src/org/forester/surfacing/SurfacingConstants.java b/forester/java/src/org/forester/surfacing/SurfacingConstants.java index ac29712..c78f157 100644 --- a/forester/java/src/org/forester/surfacing/SurfacingConstants.java +++ b/forester/java/src/org/forester/surfacing/SurfacingConstants.java @@ -40,7 +40,7 @@ public class SurfacingConstants { static final boolean SECONDARY_FEATURES_ARE_SCOP = true; static final String SECONDARY_FEATURES_SCOP_LINK = "http://scop.mrc-lmb.cam.ac.uk/scop/search.cgi?key="; public static final String NONE = "[none]"; - public static final String UNIPROT_LINK = "http://beta.uniprot.org/taxonomy/?query="; + public static final String UNIPROT_LINK = "http://www.uniprot.org/taxonomy/?query="; public static final String GO_LINK = "http://amigo.geneontology.org/cgi-bin/amigo/go.cgi?view=details&search_constraint=terms&query="; public static final String EOL_LINK = "http://www.eol.org/search?q="; public static final String TOL_LINK = "http://www.googlesyndicatedsearch.com/u/TreeofLife?q="; diff --git a/forester/java/src/org/forester/test/examples/Example1.java b/forester/java/src/org/forester/test/examples/Example1.java new file mode 100644 index 0000000..045ee6b --- /dev/null +++ b/forester/java/src/org/forester/test/examples/Example1.java @@ -0,0 +1,59 @@ +// $Id: +// +// forester -- software libraries and applications +// for evolutionary biology research and applications. +// +// Copyright (C) 2008-2011 Christian M. Zmasek +// Copyright (C) 2008-2011 Burnham Institute for Medical Research +// All rights reserved +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +// +// Contact: phylosoft @ gmail . com +// WWW: www.phylosoft.org/forester + +package org.forester.test.examples; + +import java.io.File; +import java.io.IOException; + +import org.forester.archaeopteryx.Archaeopteryx; +import org.forester.io.parsers.PhylogenyParser; +import org.forester.phylogeny.Phylogeny; +import org.forester.util.ForesterUtil; + +public class Example1 { + + public static void main( final String[] args ) { + // Reads in (a) tree(s) from a file. + final File treefile = new File( "/home/czmasek/tol_117_TEST.xml" ); + PhylogenyParser parser = null; + try { + parser = ForesterUtil.createParserDependingOnFileType( treefile, true ); + } + catch ( final IOException e ) { + e.printStackTrace(); + } + Phylogeny[] phys = null; + try { + phys = ForesterUtil.readPhylogenies( parser, treefile ); + } + catch ( final IOException e ) { + e.printStackTrace(); + } + // Display of the tree(s) with Archaeopteryx. + Archaeopteryx.createApplication( phys ); + } +} diff --git a/forester/java/src/org/forester/util/ForesterUtil.java b/forester/java/src/org/forester/util/ForesterUtil.java index 9aba8cc..11eb2e4 100644 --- a/forester/java/src/org/forester/util/ForesterUtil.java +++ b/forester/java/src/org/forester/util/ForesterUtil.java @@ -66,6 +66,7 @@ import org.forester.io.parsers.nhx.NHXParser; import org.forester.io.parsers.phyloxml.PhyloXmlParser; import org.forester.io.parsers.phyloxml.PhyloXmlUtil; import org.forester.io.parsers.tol.TolParser; +import org.forester.io.parsers.util.PhylogenyParserException; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyMethods; import org.forester.phylogeny.PhylogenyNode; @@ -74,6 +75,8 @@ import org.forester.phylogeny.data.Distribution; import org.forester.phylogeny.data.Identifier; import org.forester.phylogeny.data.Sequence; import org.forester.phylogeny.data.Taxonomy; +import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory; +import org.forester.phylogeny.factories.PhylogenyFactory; import org.forester.phylogeny.iterators.PhylogenyNodeIterator; public final class ForesterUtil { @@ -105,6 +108,15 @@ public final class ForesterUtil { private ForesterUtil() { } + public final static Phylogeny[] readPhylogenies( final PhylogenyParser parser, final File file ) throws IOException { + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final Phylogeny[] trees = factory.create( file, parser ); + if ( ( trees == null ) || ( trees.length == 0 ) ) { + throw new PhylogenyParserException( "Unable to parse phylogeny from file: " + file ); + } + return trees; + } + final public static void appendSeparatorIfNotEmpty( final StringBuffer sb, final char separator ) { if ( sb.length() > 0 ) { sb.append( separator ); -- 1.7.10.2