X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Frio%2FRIO.java;h=0de8e9a04712e9ce9864ed9d0aa2b320fead6502;hb=299c529fea070487998aee60ed7810af57f3a071;hp=68256f4459c458324214a5976952cabd18e7c4f1;hpb=aafd947d5ebcf9ed3218c269f432be59781ce322;p=jalview.git diff --git a/forester/java/src/org/forester/rio/RIO.java b/forester/java/src/org/forester/rio/RIO.java index 68256f4..0de8e9a 100644 --- a/forester/java/src/org/forester/rio/RIO.java +++ b/forester/java/src/org/forester/rio/RIO.java @@ -89,7 +89,8 @@ public final class RIO { int first, int last, final boolean produce_log, - final boolean verbose ) throws IOException, SDIException, RIOException { + final boolean verbose, + final boolean transfer_taxonomy ) throws IOException, SDIException, RIOException { if ( ( last == DEFAULT_RANGE ) && ( first >= 0 ) ) { last = END_OF_GT; } @@ -110,7 +111,7 @@ public final class RIO { _removed_gene_tree_nodes = null; _duplications_stats = new BasicDescriptiveStatistics(); p.reset(); - inferOrthologs( p, species_tree, algorithm, outgroup, first, last ); + inferOrthologs( p, species_tree, algorithm, outgroup, first, last, transfer_taxonomy ); _species_tree = species_tree; } @@ -122,7 +123,8 @@ public final class RIO { int first, int last, final boolean produce_log, - final boolean verbose ) throws IOException, SDIException, RIOException { + final boolean verbose, + final boolean transfer_taxonomy ) throws IOException, SDIException, RIOException { if ( ( last == DEFAULT_RANGE ) && ( first >= 0 ) ) { last = gene_trees.length - 1; } @@ -141,7 +143,7 @@ public final class RIO { _analyzed_gene_trees = null; _removed_gene_tree_nodes = null; _duplications_stats = new BasicDescriptiveStatistics(); - inferOrthologs( gene_trees, species_tree, algorithm, outgroup, first, last ); + inferOrthologs( gene_trees, species_tree, algorithm, outgroup, first, last, transfer_taxonomy ); _species_tree = species_tree; } @@ -202,8 +204,9 @@ public final class RIO { final ALGORITHM algorithm, final String outgroup, int first, - final int last ) throws SDIException, RIOException, FileNotFoundException, - IOException { + final int last, + final boolean transfer_taxonomy ) throws SDIException, RIOException, + FileNotFoundException, IOException { if ( !parser.hasNext() ) { throw new RIOException( "no gene trees to analyze" ); } @@ -221,6 +224,12 @@ public final class RIO { 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 ) { ForesterUtil.updateProgress( i, pf ); } @@ -246,7 +255,12 @@ public final class RIO { 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 ); + final Phylogeny analyzed_gt = performOrthologInference( gt, + species_tree, + algorithm, + outgroup, + counter, + transfer_taxonomy ); RIO.calculateOrthologTable( analyzed_gt, true, counter ); ++counter; } @@ -272,8 +286,9 @@ public final class RIO { final ALGORITHM algorithm, final String outgroup, final int first, - final int last ) throws SDIException, RIOException, FileNotFoundException, - IOException { + final int last, + final boolean transfer_taxonomy ) 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 ); @@ -302,6 +317,12 @@ public final class RIO { int gene_tree_ext_nodes = 0; for( int i = 0; i < my_gene_trees.length; ++i ) { final Phylogeny gt = my_gene_trees[ i ]; + 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 && ( my_gene_trees.length > 4 ) ) { ForesterUtil.updateProgress( ( ( double ) i ) / my_gene_trees.length ); } @@ -320,7 +341,12 @@ public final class RIO { throw new RIOException( "failed to establish species based mapping between gene and species trees" ); } } - _analyzed_gene_trees[ i ] = performOrthologInference( gt, species_tree, algorithm, outgroup, i ); + _analyzed_gene_trees[ i ] = performOrthologInference( gt, + species_tree, + algorithm, + outgroup, + i, + transfer_taxonomy ); } if ( log() ) { postLog( species_tree, first, last ); @@ -370,7 +396,9 @@ public final class RIO { final Phylogeny species_tree, final ALGORITHM algorithm, final String outgroup, - final int i ) throws SDIException, RIOException { + final int i, + final boolean transfer_taxonomy ) throws SDIException, + RIOException { final Phylogeny assigned_tree; switch ( algorithm ) { case SDIR: { @@ -378,7 +406,7 @@ public final class RIO { break; } case GSDIR: { - assigned_tree = performOrthologInferenceByGSDI( gene_tree, species_tree, outgroup, i ); + assigned_tree = performOrthologInferenceByGSDI( gene_tree, species_tree, outgroup, i, transfer_taxonomy ); break; } default: { @@ -400,11 +428,13 @@ public final class RIO { private final Phylogeny performOrthologInferenceByGSDI( final Phylogeny gene_tree, final Phylogeny species_tree, final String outgroup, - final int i ) throws SDIException, RIOException { + final int i, + final boolean transfer_taxonomy ) throws SDIException, + RIOException { final Phylogeny assigned_tree; final int dups; if ( _rerooting == REROOTING.BY_ALGORITHM ) { - final GSDIR gsdir = new GSDIR( gene_tree, species_tree, true, i == 0 ); + final GSDIR gsdir = new GSDIR( gene_tree, species_tree, true, i == 0, transfer_taxonomy ); assigned_tree = gsdir.getMinDuplicationsSumGeneTree(); if ( i == 0 ) { _removed_gene_tree_nodes = gsdir.getStrippedExternalGeneTreeNodes(); @@ -428,7 +458,7 @@ public final class RIO { final PhylogenyNode n = gene_tree.getNode( outgroup ); gene_tree.reRoot( n ); } - final GSDI gsdi = new GSDI( gene_tree, species_tree, true, true, true ); + final GSDI gsdi = new GSDI( gene_tree, species_tree, true, true, true, transfer_taxonomy ); _removed_gene_tree_nodes = gsdi.getStrippedExternalGeneTreeNodes(); for( final PhylogenyNode r : _removed_gene_tree_nodes ) { if ( !r.getNodeData().isHasTaxonomy() ) { @@ -548,7 +578,9 @@ public final class RIO { final int first, final int last, final boolean produce_log, - final boolean verbose ) throws IOException, SDIException, RIOException { + final boolean verbose, + final boolean transfer_taxonomy ) throws IOException, SDIException, + RIOException { final Phylogeny[] gene_trees = parseGeneTrees( gene_trees_file ); if ( gene_trees.length < 1 ) { throw new RIOException( "\"" + gene_trees_file + "\" is devoid of appropriate gene trees" ); @@ -558,7 +590,16 @@ public final class RIO { false, true, TAXONOMY_EXTRACTION.NO ); - return new RIO( gene_trees, species_tree, algorithm, rerooting, outgroup, first, last, produce_log, verbose ); + return new RIO( gene_trees, + species_tree, + algorithm, + rerooting, + outgroup, + first, + last, + produce_log, + verbose, + transfer_taxonomy ); } public final static RIO executeAnalysis( final File gene_trees_file, @@ -567,7 +608,9 @@ public final class RIO { final REROOTING rerooting, final String outgroup, final boolean produce_log, - final boolean verbose ) throws IOException, SDIException, RIOException { + final boolean verbose, + final boolean transfer_taxonomy ) throws IOException, SDIException, + RIOException { return new RIO( parseGeneTrees( gene_trees_file ), species_tree, algorithm, @@ -576,7 +619,8 @@ public final class RIO { DEFAULT_RANGE, DEFAULT_RANGE, produce_log, - verbose ); + verbose, + transfer_taxonomy ); } public final static RIO executeAnalysis( final File gene_trees_file, @@ -587,7 +631,9 @@ public final class RIO { final int first, final int last, final boolean produce_log, - final boolean verbose ) throws IOException, SDIException, RIOException { + final boolean verbose, + final boolean transfer_taxonomy ) throws IOException, SDIException, + RIOException { return new RIO( parseGeneTrees( gene_trees_file ), species_tree, algorithm, @@ -596,7 +642,8 @@ public final class RIO { first, last, produce_log, - verbose ); + verbose, + transfer_taxonomy ); } public final static RIO executeAnalysis( final IteratingPhylogenyParser p, @@ -607,7 +654,9 @@ public final class RIO { final int first, final int last, final boolean produce_log, - final boolean verbose ) throws IOException, SDIException, RIOException { + final boolean verbose, + final boolean transfer_taxonomy ) throws IOException, SDIException, + RIOException { final Phylogeny g0 = p.next(); if ( ( g0 == null ) || g0.isEmpty() || ( g0.getNumberOfExternalNodes() < 2 ) ) { throw new RIOException( "input file does not seem to contain any gene trees" ); @@ -618,7 +667,16 @@ public final class RIO { true, TAXONOMY_EXTRACTION.NO ); p.reset(); - return new RIO( p, species_tree, algorithm, rerooting, outgroup, first, last, produce_log, verbose ); + return new RIO( p, + species_tree, + algorithm, + rerooting, + outgroup, + first, + last, + produce_log, + verbose, + transfer_taxonomy ); } public final static RIO executeAnalysis( final IteratingPhylogenyParser p, @@ -627,7 +685,9 @@ public final class RIO { final REROOTING rerooting, final String outgroup, final boolean produce_log, - final boolean verbose ) throws IOException, SDIException, RIOException { + final boolean verbose, + final boolean transfer_taxonomy ) throws IOException, SDIException, + RIOException { return new RIO( p, species_tree, algorithm, @@ -636,7 +696,8 @@ public final class RIO { DEFAULT_RANGE, DEFAULT_RANGE, produce_log, - verbose ); + verbose, + transfer_taxonomy ); } public final static RIO executeAnalysis( final IteratingPhylogenyParser p, @@ -647,8 +708,19 @@ public final class RIO { final int first, final int last, final boolean produce_log, - final boolean verbose ) throws IOException, SDIException, RIOException { - return new RIO( p, species_tree, algorithm, rerooting, outgroup, first, last, produce_log, verbose ); + final boolean verbose, + final boolean transfer_taxonomy ) throws IOException, SDIException, + RIOException { + return new RIO( p, + species_tree, + algorithm, + rerooting, + outgroup, + first, + last, + produce_log, + verbose, + transfer_taxonomy ); } public final static RIO executeAnalysis( final Phylogeny[] gene_trees, final Phylogeny species_tree ) @@ -661,6 +733,7 @@ public final class RIO { DEFAULT_RANGE, DEFAULT_RANGE, false, + false, false ); } @@ -670,7 +743,9 @@ public final class RIO { final REROOTING rerooting, final String outgroup, final boolean produce_log, - final boolean verbose ) throws IOException, SDIException, RIOException { + final boolean verbose, + final boolean transfer_taxonomy ) throws IOException, SDIException, + RIOException { return new RIO( gene_trees, species_tree, algorithm, @@ -679,7 +754,8 @@ public final class RIO { DEFAULT_RANGE, DEFAULT_RANGE, produce_log, - verbose ); + verbose, + transfer_taxonomy ); } public final static RIO executeAnalysis( final Phylogeny[] gene_trees, @@ -690,8 +766,19 @@ public final class RIO { final int first, final int last, final boolean produce_log, - final boolean verbose ) throws IOException, SDIException, RIOException { - return new RIO( gene_trees, species_tree, algorithm, rerooting, outgroup, first, last, produce_log, verbose ); + final boolean verbose, + final boolean transfer_taxonomy ) throws IOException, SDIException, + RIOException { + return new RIO( gene_trees, + species_tree, + algorithm, + rerooting, + outgroup, + first, + last, + produce_log, + verbose, + transfer_taxonomy ); } private final static void calculateOrthologTable( final Phylogeny g, final boolean sort, final int counter ) @@ -794,6 +881,10 @@ public final class RIO { else if ( n.getNodeData().isHasSequence() && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) { label = n.getNodeData().getSequence().getSymbol(); } + else if ( n.getNodeData().isHasSequence() + && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getGeneName() ) ) { + label = n.getNodeData().getSequence().getGeneName(); + } else if ( !ForesterUtil.isEmpty( n.getName() ) ) { label = n.getName(); } @@ -814,13 +905,13 @@ public final class RIO { final NHXParser nhx = ( NHXParser ) p; nhx.setReplaceUnderscores( false ); nhx.setIgnoreQuotes( true ); - nhx.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.YES ); + nhx.setTaxonomyExtraction( TAXONOMY_EXTRACTION.AGGRESSIVE ); } else if ( p instanceof NexusPhylogeniesParser ) { final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) p; nex.setReplaceUnderscores( false ); nex.setIgnoreQuotes( true ); - nex.setTaxonomyExtraction( TAXONOMY_EXTRACTION.YES ); + nex.setTaxonomyExtraction( TAXONOMY_EXTRACTION.AGGRESSIVE ); } return factory.create( gene_trees_file, p ); }