+ gene_trees = factory.create( gene_tree_file, PhyloXmlParser.createPhyloXmlParserXsdValidating() );
+ }
+ catch ( final IOException e ) {
+ fatalError( "error",
+ "failed to read gene tree from [" + gene_tree_file + "]: " + e.getMessage(),
+ log_writer );
+ }
+ int counter = 0;
+ final List<Phylogeny> out_trees = new ArrayList<Phylogeny>();
+ for( final Phylogeny gene_tree : gene_trees ) {
+ if ( !gene_tree.isEmpty() && gene_tree.getNumberOfExternalNodes() > 1 ) {
+ Phylogeny species_tree = null;
+ try {
+ species_tree = SDIutil.parseSpeciesTree( gene_tree,
+ species_tree_file,
+ REPLACE_UNDERSCORES_IN_NH_SPECIES_TREE,
+ true,
+ TAXONOMY_EXTRACTION.NO );
+ }
+ catch ( final PhyloXmlDataFormatException e ) {
+ fatalError( "user error",
+ "failed to transfer general node name, in [" + species_tree_file + "]: "
+ + e.getMessage(),
+ log_writer );
+ }
+ catch ( final SDIException e ) {
+ fatalError( "user error", e.getMessage(), log_writer );
+ }
+ catch ( final IOException e ) {
+ fatalError( "error",
+ "Failed to read species tree from [" + species_tree_file + "]: " + e.getMessage(),
+ log_writer );
+ }
+ gene_tree.setRooted( true );
+ species_tree.setRooted( true );
+ if ( !gene_tree.isCompletelyBinary() ) {
+ fatalError( "user error",
+ "gene tree [" + gene_tree_file + "] is not completely binary",
+ log_writer );
+ }
+ if ( base_algorithm == ALGORITHM.SDI ) {
+ if ( !species_tree.isCompletelyBinary() ) {
+ fatalError( "user error",
+ "species tree is not completely binary, use GSDI or GSDIR instead",
+ log_writer );
+ }
+ }
+ log_writer.print( gene_tree_file.getName() );
+ log_writer.print( "\t" );
+ log_writer.print( ( ForesterUtil.isEmpty( gene_tree.getName() ) ? "" : gene_tree.getName() ) );
+ if ( gene_trees.length > 1 ) {
+ log_writer.print( ( ForesterUtil.isEmpty( gene_tree.getName() ) ? Integer.toString( counter )
+ : ( ":" + Integer.toString( counter ) ) ) );
+ }
+ log_writer.print( "\t" );
+ GSDII gsdii = null;
+ try {
+ if ( base_algorithm == ALGORITHM.GSDI ) {
+ gsdii = new GSDI( gene_tree,
+ species_tree,
+ most_parsimonous_duplication_model,
+ allow_stripping_of_gene_tree,
+ true,
+ transfer_taxonomy );
+ }
+ else if ( base_algorithm == ALGORITHM.GSDIR ) {
+ gsdii = new GSDIR( gene_tree,
+ species_tree,
+ allow_stripping_of_gene_tree,
+ true,
+ transfer_taxonomy );
+ }
+ }
+ catch ( final SDIException e ) {
+ fatalError( "user error", e.getLocalizedMessage(), log_writer );
+ }
+ catch ( final OutOfMemoryError e ) {
+ ForesterUtil.outOfMemoryError( e );
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace();
+ fatalError( "unexpected error", e.toString(), log_writer );
+ }
+ if ( base_algorithm == ALGORITHM.GSDIR ) {
+ final Phylogeny gt = ( ( GSDIR ) gsdii ).getMinDuplicationsSumGeneTree();
+ gt.setRerootable( false );
+ out_trees.add( gt );
+ }
+ else {
+ gene_tree.setRerootable( false );
+ out_trees.add( gene_tree );
+ }
+ log_writer.print( gene_tree.getNumberOfExternalNodes() + "\t" );
+ log_writer.print( gsdii.getSpeciationsSum() + "\t" );
+ if ( ( base_algorithm == ALGORITHM.GSDIR ) ) {
+ final GSDIR gsdir = ( GSDIR ) gsdii;
+ log_writer.print( gsdir.getMinDuplicationsSum() + "\t" );
+ }
+ else if ( ( base_algorithm == ALGORITHM.GSDI ) ) {
+ final GSDI gsdi = ( GSDI ) gsdii;
+ log_writer.print( gsdi.getDuplicationsSum() + "\t" );
+ if ( !most_parsimonous_duplication_model ) {
+ log_writer.print( gsdi.getSpeciationOrDuplicationEventsSum() + "\t" );
+ }
+ }
+ if ( allow_stripping_of_gene_tree ) {
+ log_writer.print( gsdii.getStrippedExternalGeneTreeNodes().size() + "\t" );
+ }
+ log_writer.print( gsdii.getTaxCompBase().toString() );
+ log_writer.println();
+ ++counter;