System.exit( -1 );
}
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final PhyloXmlParser xml_parser = new PhyloXmlParser();
+ final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
final Phylogeny phy = factory.create( intree, xml_parser )[ 0 ];
final BasicTable<String> t = BasicTableParser.parse( intable, '\t' );
final PhylogenyNodeIterator it = phy.iteratorExternalForward();
final File intree_file = cla.getFile( 2 );
final File species_groups_file = cla.getFile( 1 );
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final Phylogeny phy = factory.create( intree_file, new PhyloXmlParser() )[ 0 ];
+ final Phylogeny phy = factory.create( intree_file, PhyloXmlParser.createPhyloXmlParserXsdValidating() )[ 0 ];
ForesterUtil.programMessage( PRG_NAME, "Pattern string: " + pattern_str );
final Pattern pattern = Pattern.compile( pattern_str );
ForesterUtil.programMessage( PRG_NAME, "Pattern is: " + pattern );
}
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- gene_tree = factory.create( gene_tree_file, new PhyloXmlParser() )[ 0 ];
+ gene_tree = factory.create( gene_tree_file, PhyloXmlParser.createPhyloXmlParserXsdValidating() )[ 0 ];
}
catch ( final IOException e ) {
fatalError( "error",
final double depth = cla.getOptionValueAsDouble( DEPTH_OPTION );
final File intree_file = cla.getFile( 0 );
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final Phylogeny phy = factory.create( intree_file, new PhyloXmlParser() )[ 0 ];
+ final Phylogeny phy = factory.create( intree_file, PhyloXmlParser.createPhyloXmlParserXsdValidating() )[ 0 ];
execute( phy, depth );
}
catch ( final Exception e ) {
private static StringBuilder analyzeSubtree( final PhylogenyNode n, final double depth ) {
final PhylogenyNode node = moveUp( n, depth );
- for( final PhylogenyNode ext : node.getAllExternalDescendants() ) {
+ final List<PhylogenyNode> ext_descs = node.getAllExternalDescendants();
+ for( final PhylogenyNode ext : ext_descs ) {
+ if ( ext.getIndicator() != 0 ) {
+ throw new RuntimeException( "this should not have happened" );
+ }
ext.setIndicator( ( byte ) 1 );
}
int xray = 0;
PhylogenyNode first_node = null;
PhylogenyNode last_node = null;
int c = 0;
- for( final PhylogenyNode ext : node.getAllExternalDescendants() ) {
+ for( final PhylogenyNode ext : ext_descs ) {
if ( is_first ) {
first_node = ext;
is_first = false;
}
}
if ( xml_parser == null ) {
- xml_parser = new PhyloXmlParser();
+ xml_parser = PhyloXmlParser.createPhyloXmlParser();
}
return xml_parser;
}
if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
try {
- final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file );
+ final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( PhyloXmlParser
+ .createPhyloXmlParserXsdValidating(), file );
t = trees[ 0 ];
}
catch ( final Exception e ) {
// "*.*":
else {
try {
- final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file );
+ final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( PhyloXmlParser
+ .createPhyloXmlParserXsdValidating(), file );
t = trees[ 0 ];
}
catch ( final Exception e ) {
( ( NHXParser ) parser ).setGuessRootedness( true );
break;
case PHYLOXML:
- parser = new PhyloXmlParser();
+ parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
break;
default:
throw new IllegalArgumentException( "unknown format: " + client.getReturnFormat() );
private StringBuffer _error_messages;
private StringBuffer _warning_messages;
- public PhyloXmlParser() {
+ private PhyloXmlParser() {
init();
reset();
}
return xml_parser;
}
+ public static PhyloXmlParser createPhyloXmlParser() {
+ final PhyloXmlParser xml_parser = new PhyloXmlParser();
+ return xml_parser;
+ }
+
private class PhyloXmlParserErrorHandler extends DefaultHandler {
@Override
PhylogenyParser parser = null;
final String first_line = ForesterUtil.getFirstLine( file ).trim().toLowerCase();
if ( first_line.startsWith( "<" ) ) {
- parser = new PhyloXmlParser();
+ parser = PhyloXmlParser.createPhyloXmlParser();
if ( phyloxml_validate_against_xsd ) {
final ClassLoader cl = PhyloXmlParser.class.getClassLoader();
final URL xsd_url = cl.getResource( ForesterConstants.LOCAL_PHYLOXML_XSD_RESOURCE );
}
else if ( filename_lc.endsWith( ".xml" ) || filename_lc.endsWith( ".px" ) || filename_lc.endsWith( "phyloxml" )
|| filename_lc.endsWith( ".zip" ) ) {
- parser = new PhyloXmlParser();
+ parser = PhyloXmlParser.createPhyloXmlParser();
if ( phyloxml_validate_against_xsd ) {
final ClassLoader cl = PhyloXmlParser.class.getClassLoader();
final URL xsd_url = cl.getResource( ForesterConstants.LOCAL_PHYLOXML_XSD_RESOURCE );
if ( parser == null ) {
final String first_line = ForesterUtil.getFirstLine( url ).trim().toLowerCase();
if ( first_line.startsWith( "<" ) ) {
- parser = new PhyloXmlParser();
+ parser = PhyloXmlParser.createPhyloXmlParser();
if ( phyloxml_validate_against_xsd ) {
final ClassLoader cl = PhyloXmlParser.class.getClassLoader();
final URL xsd_url = cl.getResource( ForesterConstants.LOCAL_PHYLOXML_XSD_RESOURCE );
private static boolean testBasicPhyloXMLparsing() {
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final PhyloXmlParser xml_parser = new PhyloXmlParser();
+ final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
xml_parser );
if ( xml_parser.getErrorCount() > 0 ) {
private static boolean testBasicPhyloXMLparsingRoundtrip() {
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
- final PhyloXmlParser xml_parser = new PhyloXmlParser();
+ final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
}
// Do nothing -- means were not running from jar.
}
if ( xml_parser == null ) {
- xml_parser = new PhyloXmlParser();
+ xml_parser = PhyloXmlParser.createPhyloXmlParser();
if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
}
// Do nothing -- means were not running from jar.
}
if ( xml_parser == null ) {
- xml_parser = new PhyloXmlParser();
+ xml_parser = PhyloXmlParser.createPhyloXmlParser();
if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
}