- /**
- * Returns a String containg the names of orthologs of the PhylogenyNode
- * with seq name query_name. The String also contains how many times a
- * particular ortholog has been observed.
- * <p>
- * <ul>
- * The output order is (per line): Name, Ortholog, Subtree neighbor, Super
- * ortholog, Distance
- * </ul>
- * <p>
- * The sort priority of this is determined by sort in the following manner:
- * <ul>
- * <li>0 : Ortholog
- * <li>1 : Ortholog, Super ortholog
- * <li>2 : Super ortholog, Ortholog
- * </ul>
- * <p>
- * Returns "-" if no putative orthologs have been found (given
- * threshold_orthologs).
- * <p>
- * Orthologs are to be inferred by method "inferOrthologs".
- * <p>
- * (Last modified: 05/08/01)
- *
- * @param query_name
- * sequence name of a external node of the gene trees
- * @param sort
- * order and sort priority
- * @param threshold_orthologs
- * the minimal number of observations for a a sequence to be
- * reported as orthologous, in percents (0.0-100.0%)
- * @param threshold_subtreeneighborings
- * the minimal number of observations for a a sequence to be
- * reported as orthologous, in percents (0.0-100.0%)
- * @return String containing the inferred orthologs, String containing "-"
- * if no orthologs have been found null in case of error
- */
- public final StringBuffer inferredOrthologsToString( final String query_name, int sort, double threshold_orthologs ) {
- HashMap<String, Integer> o_hashmap = null;
- HashMap<String, Integer> s_hashmap = null;
- String name = "";
- double o = 0.0; // Orthologs.
- double s = 0.0; // Super orthologs.
- double value1 = 0.0;
- double value2 = 0.0;
- final ArrayList<ResultLine> nv = new ArrayList<ResultLine>();
- if ( ( _o_maps == null ) || ( _so_maps == null ) ) {
- throw new RuntimeException( "orthologs have not been calculated (successfully)" );
- }
- if ( ( sort < 0 ) || ( sort > 2 ) ) {
- sort = 1;
- }
- if ( threshold_orthologs < 0.0 ) {
- threshold_orthologs = 0.0;
- }
- else if ( threshold_orthologs > 100.0 ) {
- threshold_orthologs = 100.0;
- }
- o_hashmap = getInferredOrthologs( query_name );
- s_hashmap = getInferredSuperOrthologs( query_name );
- if ( ( o_hashmap == null ) || ( s_hashmap == null ) ) {
- throw new RuntimeException( "Orthologs for " + query_name + " were not established" );
- }
- final StringBuffer orthologs = new StringBuffer();
- if ( _seq_names.size() > 0 ) {
- I: for( int i = 0; i < _seq_names.size(); ++i ) {
- name = _seq_names.get( i );
- if ( name.equals( query_name ) ) {
- continue I;
- }
- o = getBootstrapValueFromHash( o_hashmap, name );
- if ( o < threshold_orthologs ) {
- continue I;
- }
- s = getBootstrapValueFromHash( s_hashmap, name );
- switch ( sort ) {
- case 0:
- nv.add( new ResultLine( name, o, 5 ) );
- break;
- case 1:
- nv.add( new ResultLine( name, o, s, 5 ) );
- break;
- case 2:
- nv.add( new ResultLine( name, s, o, 5 ) );
- break;
- default:
- nv.add( new ResultLine( name, o, 5 ) );
- }
- } // End of I for loop.
- if ( ( nv != null ) && ( nv.size() > 0 ) ) {
- orthologs.append( "seq name\t\tortho\ts-ortho" + ForesterUtil.LINE_SEPARATOR );
- final ResultLine[] nv_array = new ResultLine[ nv.size() ];
- for( int j = 0; j < nv.size(); ++j ) {
- nv_array[ j ] = nv.get( j );
- }
- Arrays.sort( nv_array );
- for( final ResultLine element : nv_array ) {
- name = element.getKey();
- value1 = element.getValue1();
- value2 = element.getValue2();
- orthologs.append( addNameAndValues( name, value1, value2, sort ) );
+ public final StringBuilder getLog() {
+ return _log;
+ }
+
+ public final List<PhylogenyNode> getRemovedGeneTreeNodes() {
+ return _removed_gene_tree_nodes;
+ }
+
+ private final void inferOrthologs( final Phylogeny[] gene_trees,
+ final Phylogeny species_tree,
+ final ALGORITHM algorithm,
+ final String outgroup,
+ final int first,
+ final int last ) throws SDIException, RIOException, FileNotFoundException,
+ IOException {
+ if ( algorithm == ALGORITHM.SDIR ) {
+ // Removes from species_tree all species not found in gene_tree.
+ PhylogenyMethods.taxonomyBasedDeletionOfExternalNodes( gene_trees[ 0 ], species_tree );
+ if ( species_tree.isEmpty() ) {
+ throw new RIOException( "failed to establish species based mapping between gene and species trees" );
+ }
+ }
+ final Phylogeny[] my_gene_trees;
+ if ( ( first >= 0 ) && ( last >= first ) && ( last < gene_trees.length ) ) {
+ my_gene_trees = new Phylogeny[ ( 1 + last ) - first ];
+ int c = 0;
+ for( int i = first; i <= last; ++i ) {
+ my_gene_trees[ c++ ] = gene_trees[ i ];
+ }
+ }
+ else {
+ my_gene_trees = gene_trees;
+ }
+ if ( log() ) {
+ preLog( gene_trees, species_tree, algorithm, outgroup, first, last );
+ }
+ if ( _verbose && ( my_gene_trees.length >= 4 ) ) {
+ System.out.println();
+ }
+ _analyzed_gene_trees = new Phylogeny[ my_gene_trees.length ];
+ int gene_tree_ext_nodes = 0;
+ for( int i = 0; i < my_gene_trees.length; ++i ) {
+ final Phylogeny gt = my_gene_trees[ i ];
+ if ( _verbose && ( my_gene_trees.length > 4 ) ) {
+ ForesterUtil.updateProgress( ( ( double ) i ) / my_gene_trees.length );
+ }
+ if ( i == 0 ) {
+ gene_tree_ext_nodes = gt.getNumberOfExternalNodes();
+ }
+ else if ( gene_tree_ext_nodes != gt.getNumberOfExternalNodes() ) {
+ throw new RIOException( "gene tree #" + ( i + 1 ) + " has a different number of external nodes ("
+ + gt.getNumberOfExternalNodes() + ") than the preceding gene trees (" + 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" );