+ public final Phylogeny getSpeciesTree() {
+ return _species_tree;
+ }
+
+ private final void inferOrthologs( final IteratingPhylogenyParser parser,
+ final Phylogeny species_tree,
+ final ALGORITHM algorithm,
+ final String outgroup,
+ int first,
+ final int last,
+ final boolean transfer_taxonomy ) throws SDIException, RIOException,
+ FileNotFoundException, IOException {
+ if ( !parser.hasNext() ) {
+ throw new RIOException( "no gene trees to analyze" );
+ }
+ if ( log() ) {
+ preLog( -1, species_tree, algorithm, outgroup );
+ }
+ if ( _verbose ) {
+ System.out.println();
+ }
+ int gene_tree_ext_nodes = 0;
+ int i = 0;
+ int counter = 0;
+ final boolean no_range = ( first < 0 ) || ( last < first );
+ while ( parser.hasNext() ) {
+ final Phylogeny gt = parser.next();
+ if ( no_range || ( ( i >= first ) && ( i <= last ) ) ) {
+ if ( gt.isEmpty() ) {
+ throw new RIOException( "gene tree #" + i + " is empty" );
+ }
+ if ( gt.getNumberOfExternalNodes() == 1 ) {
+ throw new RIOException( "gene tree #" + i + " has only one external node" );
+ }
+ if ( _verbose ) {
+ System.out.print( "\r" + i );
+ }
+ if ( counter == 0 ) {
+ if ( algorithm == ALGORITHM.SDIR ) {
+ // Removes from species_tree all species not found in gene_tree.
+ PhylogenyMethods.taxonomyBasedDeletionOfExternalNodes( gt, species_tree );
+ if ( species_tree.isEmpty() ) {
+ throw new RIOException( "failed to establish species based mapping between gene and species trees" );
+ }
+ }
+ gene_tree_ext_nodes = gt.getNumberOfExternalNodes();
+ }
+ else if ( gene_tree_ext_nodes != gt.getNumberOfExternalNodes() ) {
+ throw new RIOException( "gene tree #" + i + " has a different number of external nodes ("
+ + gt.getNumberOfExternalNodes() + ") than the preceding gene tree(s) ("
+ + gene_tree_ext_nodes + ")" );
+ }
+ if ( algorithm == ALGORITHM.SDIR ) {
+ // Removes from gene_tree all species not found in species_tree.
+ PhylogenyMethods.taxonomyBasedDeletionOfExternalNodes( species_tree, gt );
+ if ( gt.isEmpty() ) {
+ throw new RIOException( "failed to establish species based mapping between gene and species trees" );
+ }
+ }
+ final Phylogeny analyzed_gt = performOrthologInference( gt,
+ species_tree,
+ algorithm,
+ outgroup,
+ counter,
+ transfer_taxonomy );
+ RIO.calculateOrthologTable( analyzed_gt, true, counter );
+ ++counter;
+ }
+ ++i;
+ }
+ if ( _verbose ) {
+ System.out.print( "\rGene trees analyzed :\t" + counter );
+ }
+ if ( ( first >= 0 ) && ( counter == 0 ) && ( i > 0 ) ) {
+ throw new RIOException( "attempt to analyze first gene tree #" + first + " in a set of " + i );
+ }
+ if ( no_range ) {
+ first = 0;
+ }
+ if ( log() ) {
+ postLog( species_tree, first, ( first + counter ) - 1 );
+ }
+ if ( _verbose ) {
+ System.out.println();
+ System.out.println();
+ }
+ }
+