nex.setIgnoreQuotes( false );
}
}
+ AptxUtil.printAppletMessage( "Archaeopteryx", "parser is " + parser.getName() );
final Phylogeny[] phys = factory.create( url.openStream(), parser );
+ for( final Phylogeny phy : phys ) {
+ System.out.println( phy.toString() );
+ }
if ( nhx_or_nexus && internal_numbers_are_confidences ) {
for( final Phylogeny phy : phys ) {
PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
setConfiguration( configuration );
setOptions( Options.createInstance( configuration ) );
setupUI();
- URL phys_url = null;
- Phylogeny[] phys = null;
final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
+ if ( ForesterUtil.isEmpty( tree_url_str ) ) {
+ ForesterUtil.printErrorMessage( NAME, "could not get tree URL from "
+ + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
+ JOptionPane.showMessageDialog( this, NAME + ": could not get tree URL from "
+ + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD, "Failed get URL", JOptionPane.ERROR_MESSAGE );
+ return;
+ }
AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
// Get URL to tree file
- if ( tree_url_str != null ) {
- try {
- phys_url = new URL( tree_url_str );
- }
- catch ( final Exception e ) {
- ForesterUtil.printErrorMessage( NAME, "error: " + e );
- e.printStackTrace();
- JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
- + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
- }
+ URL phys_url = null;
+ try {
+ phys_url = new URL( tree_url_str );
+ }
+ catch ( final Exception e ) {
+ ForesterUtil.printErrorMessage( NAME, "error: " + e );
+ e.printStackTrace();
+ JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
+ + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
+ }
+ if ( phys_url == null ) {
+ ForesterUtil.printErrorMessage( NAME, "failed to get tree URL from "
+ + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
+ JOptionPane.showMessageDialog( this,
+ NAME + ": Could not create URL from: \"" + tree_url_str,
+ "Failed to create URL",
+ JOptionPane.ERROR_MESSAGE );
+ return;
}
// Load the tree from URL
- if ( phys_url != null ) {
- try {
- phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
- getConfiguration().isValidatePhyloXmlAgainstSchema(),
- getConfiguration().isReplaceUnderscoresInNhParsing(),
- getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
- getConfiguration().getTaxonomyExtraction(),
- getConfiguration().isMidpointReroot() );
- }
- catch ( final Exception e ) {
- ForesterUtil.printErrorMessage( NAME, e.toString() );
- e.printStackTrace();
- JOptionPane.showMessageDialog( this,
- NAME + ": Failed to read phylogenies: " + "\nException: " + e,
- "Failed to read phylogenies",
- JOptionPane.ERROR_MESSAGE );
- }
+ Phylogeny[] phys = null;
+ try {
+ phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
+ getConfiguration().isValidatePhyloXmlAgainstSchema(),
+ getConfiguration().isReplaceUnderscoresInNhParsing(),
+ getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
+ getConfiguration().getTaxonomyExtraction(),
+ getConfiguration().isMidpointReroot() );
+ }
+ catch ( final Exception e ) {
+ ForesterUtil.printErrorMessage( NAME, e.toString() );
+ e.printStackTrace();
+ JOptionPane.showMessageDialog( this,
+ NAME + ": Failed to read phylogenies: " + "\nException: " + e,
+ "Failed to read phylogenies",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ if ( phys == null ) {
+ ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null" );
+ JOptionPane.showMessageDialog( this,
+ NAME + ": phylogenies from [" + phys_url + "] are null",
+ "Failed to read phylogenies",
+ JOptionPane.ERROR_MESSAGE );
+ return;
}
- if ( ( phys == null ) || ( phys.length < 1 ) ) {
- ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null or empty" );
+ else if ( phys.length < 1 ) {
+ ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are empty" );
JOptionPane.showMessageDialog( this,
- NAME + ": phylogenies from [" + phys_url + "] are null or empty",
+ NAME + ": phylogenies from [" + phys_url + "] are empty",
"Failed to read phylogenies",
JOptionPane.ERROR_MESSAGE );
return;
setName( NAME );
getMainPanel().getControlPanel().showWholeAll();
getMainPanel().getControlPanel().showWhole();
- System.gc();
- AptxUtil.printAppletMessage( NAME, "successfully initialized" );
/* GUILHEM_BEG */
getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
}
/* GUILHEM_END */
+ System.gc();
+ AptxUtil.printAppletMessage( NAME, "successfully initialized" );
setVisible( true );
}
public Phylogeny[] parse() throws IOException;
public void setSource( Object source ) throws PhylogenyParserException, IOException;
+
+ public String getName();
}
private final static String removeWhiteSpaceBeforeSemicolon( final String s ) {
return s.replaceAll( "\\s+;", ";" );
}
+
+ @Override
+ public String getName() {
+ return "Nexus Phylogenies Parser";
+ }
}
for( int i = 0; i < l.size(); ++i ) {
p[ i ] = l.get( i );
}
+ System.out.println( "going to return:" );
+ for( Phylogeny phylogeny : p ) {
+ System.out.println( phylogeny.toString() );
+ }
return p;
}
_my_source_charary = ( char[] ) _nhx_source;
break;
case BUFFERED_READER:
- if ( _my_source_br != null ) {
- try {
- _my_source_br.close();
- }
- catch ( final IOException e ) {
- //do nothing
- }
- }
+ //never called:
+ // if ( _my_source_br != null ) {
+ // try {
+ // _my_source_br.close();
+ // }
+ // catch ( final IOException e ) {
+ // //do nothing
+ // }
+ // }
_my_source_br = ( BufferedReader ) _nhx_source;
break;
default:
private final Phylogeny finishPhylogeny() throws PhylogenyParserException, NHXFormatException,
PhyloXmlDataFormatException {
+ System.out.println( "finishPhylogeny()" + _current_phylogeny );
if ( _current_phylogeny != null ) {
parseNHX( _current_anotation != null ? _current_anotation.toString() : "",
_current_phylogeny.getRoot(),
}
}
}
+ System.out.print( c );
if ( !_in_single_quote && !_in_double_quote ) {
if ( c == ':' ) {
_saw_colon = true;
}
}
+ @Override
+ public String getName() {
+ return "NN/NHX Parser";
+ }
+
public static enum TAXONOMY_EXTRACTION {
NO, PFAM_STYLE_RELAXED, PFAM_STYLE_STRICT, AGGRESSIVE;
}
_warning_messages.append( "[line: " + e.getLineNumber() + "] " + e.getMessage() );
}
}
+
+ @Override
+ public String getName() {
+ return "phyloXML Parser";
+ }
}
_warning_messages.append( "[line: " + e.getLineNumber() + "] " + e.getMessage() );
}
}
+
+ @Override
+ public String getName() {
+ return "ToL Parser";
+ }
}
\ No newline at end of file
+++ /dev/null
-// $Id:
-// FORESTER -- software libraries and applications
-// for evolutionary biology research and applications.
-//
-// Copyright (C) 2008-2009 Christian M. Zmasek
-// Copyright (C) 2008-2009 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: https://sites.google.com/site/cmzmasek/home/software/forester
-
-package org.forester.phylogeny.factories;
-
-import java.io.IOException;
-
-import org.forester.phylogeny.Phylogeny;
-
-/*
- * Convinience class for PhylogenyFactories not using parameters.
- *
- * @author Christian M. Zmasek
- */
-public abstract class BasicPhylogenyFactory implements PhylogenyFactory {
-
- @Override
- public Phylogeny create() {
- return new Phylogeny();
- }
-
- @Override
- public Phylogeny[] create( final Object source, final Object creator ) throws IOException {
- return create( source, creator, null );
- }
-}
package org.forester.phylogeny.factories;
import java.io.IOException;
-import java.util.List;
import org.forester.io.parsers.PhylogenyParser;
import org.forester.io.parsers.phyloxml.PhyloXmlParser;
import org.forester.phylogeny.Phylogeny;
import org.forester.util.ForesterUtil;
-public class ParserBasedPhylogenyFactory extends BasicPhylogenyFactory {
+public class ParserBasedPhylogenyFactory implements PhylogenyFactory {
private final static PhylogenyFactory _instance;
static {
}
@Override
- public synchronized Phylogeny[] create( final Object source, final Object parser, final List<Object> parameters )
- throws IOException {
+ public synchronized Phylogeny[] create( final Object source, final Object parser ) throws IOException {
if ( !( parser instanceof PhylogenyParser ) ) {
throw new IllegalArgumentException( "attempt to use object of type other than PhylogenyParser as creator for ParserBasedPhylogenyFactory" );
}
return my_parser.parse();
}
- public synchronized Phylogeny[] create( final Object source,
- final Object parser,
- final String schema_location,
- final List<Object> parameters ) throws IOException {
+ public synchronized Phylogeny[] create( final Object source, final Object parser, final String schema_location )
+ throws IOException {
if ( !( parser instanceof PhylogenyParser ) ) {
throw new IllegalArgumentException( "attempt to use object of type other than PhylogenyParser as creator for ParserBasedPhylogenyFactory." );
}
package org.forester.phylogeny.factories;
import java.io.IOException;
-import java.util.List;
import org.forester.phylogeny.Phylogeny;
public interface PhylogenyFactory {
/**
- * This must be implemented in such a way that it returns an empty
- * Phylogeny.
- *
- * @return an empty Phylogeny
- */
- public Phylogeny create();
-
- /**
* This must create a Phylogeny from source (e.g. an XML file, an alignment,
* pairwise distances) by using creator (e.g. an XML file parser, an
* algorithm implementation).
* @throws IOException
*/
public Phylogeny[] create( Object source, Object creator ) throws IOException;
-
- /**
- * This must create a Phylogeny from source (e.g. an XML file, an alignment,
- * pairwise distances) by using creator (e.g. an XML file parser, an
- * algorithm implementation) with parameters listed in parameters.
- *
- * @param source
- * a source to create a Phylogeny from
- * @param creator
- * a means to create a Phylogeny
- * @param parameters
- * a List of parameters for Phylogeny creation
- * @return a Phylogeny[] based on argument source
- * @throws IOException
- */
- public Phylogeny[] create( Object source, Object creator, List<Object> parameters ) throws IOException;
-} // PhylogenyFactory
+}
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import org.forester.io.parsers.GeneralMsaParser;
import org.forester.io.parsers.HmmscanPerDomainTableParser;
import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
+import org.forester.io.parsers.PhylogenyParser;
import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
import org.forester.io.parsers.nexus.NexusCharactersParser;
import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
}
public static void main( final String[] args ) {
+ try {
+ String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
+ final URL u = new URL( s );
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ final PhylogenyParser parser = ParserUtils.createParserDependingOnUrlContents( u, true );
+ final Phylogeny[] phys = factory.create( u.openStream(), parser );
+ System.out.println( "results 1:" );
+ for( final Phylogeny phy : phys ) {
+ System.out.println( phy.toString() );
+ }
+ System.out.println( "" );
+ final Phylogeny[] phys3 = factory.create( "((a,b),c)", parser );
+ System.out.println( "results 3:" );
+ for( final Phylogeny phy : phys3 ) {
+ System.out.println( phy.toString() );
+ }
+ }
+ catch ( Exception e ) {
+ e.printStackTrace();
+ }
+ System.exit( 0 );
System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
+ "]" );
private static boolean testBasicTreeMethods() {
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final Phylogeny t1 = factory.create();
- if ( !t1.isEmpty() ) {
- return false;
- }
final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
if ( t2.getNumberOfExternalNodes() != 4 ) {
return false;