+ private final Phylogeny performOrthologInferenceByGSDI( final Phylogeny gene_tree,
+ final Phylogeny species_tree,
+ final String outgroup,
+ final int i ) throws SDIException, RIOException {
+ final Phylogeny assigned_tree;
+ if ( _rerooting == REROOTING.BY_ALGORITHM ) {
+ final GSDIR gsdir = new GSDIR( gene_tree, species_tree, true, i == 0 );
+ final List<Phylogeny> assigned_trees = gsdir.getMinDuplicationsSumGeneTrees();
+ if ( i == 0 ) {
+ _removed_gene_tree_nodes = gsdir.getStrippedExternalGeneTreeNodes();
+ for( final PhylogenyNode r : _removed_gene_tree_nodes ) {
+ if ( !r.getNodeData().isHasTaxonomy() ) {
+ throw new RIOException( "node with no (appropriate) taxonomic information found in gene tree #1: "
+ + r.toString() );
+ }
+ }
+ }
+ final List<Integer> shortests = GSDIR.getIndexesOfShortestTree( assigned_trees );
+ assigned_tree = assigned_trees.get( shortests.get( 0 ) );
+ if ( _produce_log ) {
+ writeStatsToLog( i, gsdir, shortests );
+ }
+ if ( i == 0 ) {
+ _gsdir_tax_comp_base = gsdir.getTaxCompBase();
+ }
+ _duplications_stats.addValue( gsdir.getMinDuplicationsSum() );
+ }
+ else {
+ if ( _rerooting == REROOTING.MIDPOINT ) {
+ PhylogenyMethods.midpointRoot( gene_tree );
+ }
+ else if ( _rerooting == REROOTING.OUTGROUP ) {
+ PhylogenyNode n;
+ try {
+ n = gene_tree.getNode( outgroup );
+ }
+ catch ( IllegalArgumentException e ) {
+ throw new RIOException( "failed to perform re-rooting by outgroup: " + e.getLocalizedMessage() );
+ }
+ gene_tree.reRoot( n );
+ }
+ final GSDI gsdi = new GSDI( gene_tree, species_tree, true, true, true );
+ _removed_gene_tree_nodes = gsdi.getStrippedExternalGeneTreeNodes();
+ for( final PhylogenyNode r : _removed_gene_tree_nodes ) {
+ if ( !r.getNodeData().isHasTaxonomy() ) {
+ throw new RIOException( "node with no (appropriate) taxonomic information found in gene tree #1: "
+ + r.toString() );
+ }
+ }
+ assigned_tree = gene_tree;
+ if ( i == 0 ) {
+ _gsdir_tax_comp_base = gsdi.getTaxCompBase();
+ }
+ _duplications_stats.addValue( gsdi.getDuplicationsSum() );
+ }
+ return assigned_tree;
+ }
+
+ private final Phylogeny performOrthologInferenceBySDI( final Phylogeny gene_tree, final Phylogeny species_tree )
+ throws SDIException {
+ final SDIR sdir = new SDIR();
+ return sdir.infer( gene_tree, species_tree, false, true, true, true, 1 )[ 0 ];
+ }
+