From: cmzmasek@gmail.com Date: Fri, 14 Dec 2012 22:04:26 +0000 (+0000) Subject: "rio" work X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=03001eb3d298d53e97e4194787fa21bcbc43c5d8;p=jalview.git "rio" work --- diff --git a/forester/java/src/org/forester/application/gsdi.java b/forester/java/src/org/forester/application/gsdi.java index 253bfcc..71bd6d9 100644 --- a/forester/java/src/org/forester/application/gsdi.java +++ b/forester/java/src/org/forester/application/gsdi.java @@ -107,7 +107,6 @@ public final class gsdi { System.exit( -1 ); } final List allowed_options = new ArrayList(); - allowed_options.add( gsdi.GSDIR_OPTION ); allowed_options.add( gsdi.GUESS_FORMAT_OF_SPECIES_TREE ); allowed_options.add( gsdi.MOST_PARSIMONIOUS_OPTION ); @@ -130,7 +129,6 @@ public final class gsdi { if ( cla.isOptionSet( gsdi.GSDIR_OPTION ) ) { base_algorithm = ALGORITHM.GSDIR; } - if ( cla.isOptionSet( gsdi.MOST_PARSIMONIOUS_OPTION ) ) { if ( base_algorithm == ALGORITHM.SDI ) { ForesterUtil.fatalError( gsdi.PRG_NAME, "Cannot use most parsimonious duplication mode with SDI" ); @@ -239,6 +237,9 @@ public final class gsdi { } } } + 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(), @@ -295,10 +296,10 @@ public final class gsdi { log_writer.flush(); if ( base_algorithm == ALGORITHM.GSDI ) { gsdii = new GSDI( gene_tree, - species_tree, - most_parsimonous_duplication_model, - allow_stripping_of_gene_tree, - true ); + species_tree, + most_parsimonous_duplication_model, + allow_stripping_of_gene_tree, + true ); } else if ( base_algorithm == ALGORITHM.GSDIR ) { gsdii = new GSDIR( gene_tree, species_tree, allow_stripping_of_gene_tree, true ); @@ -322,7 +323,7 @@ public final class gsdi { log_writer.println( "Mapping based on : " + gsdii.getTaxCompBase() ); if ( ( base_algorithm == ALGORITHM.GSDIR ) ) { final GSDIR gsdir = ( GSDIR ) gsdii; - System.out.println( "Duplications sum statistics : " + gsdir.getMinDuplicationsSum() ); + System.out.println( "Duplications sum statistics : " + gsdir.getMinDuplicationsSum() ); log_writer.println( "Duplications sum statistics : " + gsdir.getMinDuplicationsSum() ); } try { @@ -393,7 +394,6 @@ public final class gsdi { System.out.println( "Number of potential duplications : " + u ); log_writer.println( "Number of potential duplications : " + u ); } - } log_writer.println(); printMappedNodesToLog( log_writer, gsdii ); diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index babcf6d..7c09e44 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -100,6 +100,7 @@ import org.forester.phylogeny.factories.PhylogenyFactory; import org.forester.phylogeny.iterators.PhylogenyNodeIterator; import org.forester.sdi.GSDI; import org.forester.sdi.GSDIR; +import org.forester.sdi.SDIException; import org.forester.sdi.SDIR; import org.forester.sequence.Sequence; import org.forester.util.BasicDescriptiveStatistics; @@ -1236,12 +1237,19 @@ public final class MainFrameApplication extends MainFrame { gene_tree.setAllNodesToNotCollapse(); gene_tree.recalculateNumberOfExternalDescendants( false ); GSDI gsdi = null; - Phylogeny species_tree = _species_tree.copy(); + final Phylogeny species_tree = _species_tree.copy(); try { gsdi = new GSDI( gene_tree, species_tree, false, true, true ); } + catch ( final SDIException e ) { + JOptionPane.showMessageDialog( this, + e.getLocalizedMessage(), + "Error during GSDI", + JOptionPane.ERROR_MESSAGE ); + return; + } catch ( final Exception e ) { - JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE ); + AptxUtil.unexpectedException( e ); return; } gene_tree.setRerootable( false ); @@ -1271,12 +1279,19 @@ public final class MainFrameApplication extends MainFrame { gene_tree.setAllNodesToNotCollapse(); gene_tree.recalculateNumberOfExternalDescendants( false ); GSDIR gsdir = null; - Phylogeny species_tree = _species_tree.copy(); + final Phylogeny species_tree = _species_tree.copy(); try { gsdir = new GSDIR( gene_tree, species_tree, true, true ); } + catch ( final SDIException e ) { + JOptionPane.showMessageDialog( this, + e.getLocalizedMessage(), + "Error during GSDIR", + JOptionPane.ERROR_MESSAGE ); + return; + } catch ( final Exception e ) { - JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDIR", JOptionPane.ERROR_MESSAGE ); + AptxUtil.unexpectedException( e ); return; } final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTrees().get( 0 ); diff --git a/forester/java/src/org/forester/phylogeny/iterators/ExternalForwardIterator.java b/forester/java/src/org/forester/phylogeny/iterators/ExternalForwardIterator.java index 4d4a602..4e6df65 100644 --- a/forester/java/src/org/forester/phylogeny/iterators/ExternalForwardIterator.java +++ b/forester/java/src/org/forester/phylogeny/iterators/ExternalForwardIterator.java @@ -30,9 +30,6 @@ import java.util.NoSuchElementException; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyNode; -/* - * @author Christian Zmasek - */ public class ExternalForwardIterator implements PhylogenyNodeIterator { private PhylogenyNode _current_node; diff --git a/forester/java/src/org/forester/sdi/GSDI.java b/forester/java/src/org/forester/sdi/GSDI.java index fd64970..f9cc14e 100644 --- a/forester/java/src/org/forester/sdi/GSDI.java +++ b/forester/java/src/org/forester/sdi/GSDI.java @@ -41,7 +41,7 @@ import org.forester.phylogeny.iterators.PhylogenyNodeIterator; import org.forester.sdi.SDIutil.TaxonomyComparisonBase; import org.forester.util.ForesterUtil; -public final class GSDI implements GSDII { +public final class GSDI implements GSDII { private final boolean _most_parsimonious_duplication_model; private final int _speciation_or_duplication_events_sum; @@ -82,10 +82,12 @@ public final class GSDI implements GSDII { return _duplications_sum; } + @Override public Set getMappedExternalSpeciesTreeNodes() { return _mapped_species_tree_nodes; } + @Override public final SortedSet getReMappedScientificNamesFromGeneTree() { return _scientific_names_mapped_to_reduced_specificity; } @@ -94,18 +96,22 @@ public final class GSDI implements GSDII { return _speciation_or_duplication_events_sum; } + @Override public final int getSpeciationsSum() { return _speciations_sum; } + @Override public List getStrippedExternalGeneTreeNodes() { return _stripped_gene_tree_nodes; } + @Override public List getStrippedSpeciesTreeNodes() { return _stripped_species_tree_nodes; } + @Override public TaxonomyComparisonBase getTaxCompBase() { return _tax_comp_base; } @@ -189,7 +195,8 @@ public final class GSDI implements GSDII { final String tax_str = SDIutil.taxonomyToString( s, res.getTaxCompBase() ); if ( !ForesterUtil.isEmpty( tax_str ) ) { if ( species_to_node_map.containsKey( tax_str ) ) { - throw new SDIException( "taxonomy \"" + s + "\" is not unique in species tree" ); + throw new SDIException( "taxonomy \"" + tax_str + "\" is not unique in species tree (using " + + res.getTaxCompBase() + " for linking to gene tree)" ); } species_to_node_map.put( tax_str, s ); } diff --git a/forester/java/src/org/forester/sdi/GSDIR.java b/forester/java/src/org/forester/sdi/GSDIR.java index d51a803..611ef4a 100644 --- a/forester/java/src/org/forester/sdi/GSDIR.java +++ b/forester/java/src/org/forester/sdi/GSDIR.java @@ -39,29 +39,25 @@ import org.forester.util.BasicDescriptiveStatistics; public class GSDIR implements GSDII { - private final int _min_duplications_sum; + private final int _min_duplications_sum; private final int _speciations_sum; - @Override public int getSpeciationsSum() { return _speciations_sum; } - private final BasicDescriptiveStatistics _duplications_sum_stats; private final List _min_duplications_sum_gene_trees; - private final List _stripped_gene_tree_nodes; private final List _stripped_species_tree_nodes; private final Set _mapped_species_tree_nodes; private final TaxonomyComparisonBase _tax_comp_base; private final SortedSet _scientific_names_mapped_to_reduced_specificity; - + public GSDIR( final Phylogeny gene_tree, final Phylogeny species_tree, final boolean strip_gene_tree, final boolean strip_species_tree ) throws SDIException { - final NodesLinkingResult nodes_linking_result = GSDI.linkNodesOfG( gene_tree, species_tree, null, @@ -76,7 +72,7 @@ public class GSDIR implements GSDII { final List gene_tree_branches_post_order = new ArrayList(); for( final PhylogenyNodeIterator it = gene_tree.iteratorPostorder(); it.hasNext(); ) { final PhylogenyNode n = it.next(); - if ( !n.isRoot() && !( n.getParent().isRoot() && n.isFirstChildNode() ) ) { + if ( !n.isRoot() /*&& !( n.getParent().isRoot() && n.isFirstChildNode() )*/) { gene_tree_branches_post_order.add( new PhylogenyBranch( n, n.getParent() ) ); } } @@ -85,7 +81,6 @@ public class GSDIR implements GSDII { _min_duplications_sum_gene_trees = new ArrayList(); _duplications_sum_stats = new BasicDescriptiveStatistics(); for( final PhylogenyBranch branch : gene_tree_branches_post_order ) { - gene_tree.reRoot( branch ); PhylogenyMethods.preOrderReId( species_tree ); //TEST, remove later @@ -98,19 +93,18 @@ public class GSDIR implements GSDII { final GSDIsummaryResult gsdi_result = GSDI.geneTreePostOrderTraversal( gene_tree, true ); if ( gsdi_result.getDuplicationsSum() < min_duplications_sum ) { min_duplications_sum = gsdi_result.getDuplicationsSum(); - speciations_sum = gsdi_result.getSpeciationsSum(); + speciations_sum = gsdi_result.getSpeciationsSum(); _min_duplications_sum_gene_trees.clear(); _min_duplications_sum_gene_trees.add( gene_tree.copy() ); //_speciations_sum } - else if ( gsdi_result.getDuplicationsSum()== min_duplications_sum ) { + else if ( gsdi_result.getDuplicationsSum() == min_duplications_sum ) { _min_duplications_sum_gene_trees.add( gene_tree.copy() ); } _duplications_sum_stats.addValue( gsdi_result.getDuplicationsSum() ); - } - _min_duplications_sum = min_duplications_sum; - _speciations_sum = speciations_sum; + _min_duplications_sum = min_duplications_sum; + _speciations_sum = speciations_sum; } public int getMinDuplicationsSum() { diff --git a/forester/java/src/org/forester/sdi/SDIutil.java b/forester/java/src/org/forester/sdi/SDIutil.java index efe1830..5ddd905 100644 --- a/forester/java/src/org/forester/sdi/SDIutil.java +++ b/forester/java/src/org/forester/sdi/SDIutil.java @@ -55,7 +55,8 @@ public class SDIutil { } } - public final static TaxonomyComparisonBase determineTaxonomyComparisonBase( final Phylogeny gene_tree ) { + public final static TaxonomyComparisonBase determineTaxonomyComparisonBase( final Phylogeny gene_tree ) + throws SDIException { int with_id_count = 0; int with_code_count = 0; int with_sn_count = 0; @@ -82,10 +83,10 @@ public class SDIutil { } } if ( max == 0 ) { - throw new IllegalArgumentException( "gene tree has no taxonomic data" ); + throw new SDIException( "gene tree has no taxonomic data" ); } else if ( max == 1 ) { - throw new IllegalArgumentException( "gene tree has only one node with taxonomic data" ); + throw new SDIException( "gene tree has only one node with taxonomic data" ); } else if ( max == with_id_count ) { return TaxonomyComparisonBase.ID; diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index f739330..163bdb3 100644 --- a/forester/java/src/org/forester/test/Test.java +++ b/forester/java/src/org/forester/test/Test.java @@ -89,7 +89,6 @@ import org.forester.protein.Protein; import org.forester.rio.TestRIO; import org.forester.sdi.SDI; import org.forester.sdi.SDIR; -import org.forester.sdi.SDI; import org.forester.sdi.TestGSDI; import org.forester.sequence.BasicSequence; import org.forester.sequence.Sequence; @@ -2884,6 +2883,29 @@ public final class Test { for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) { final PhylogenyNode node = iter.next(); } + final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ]; + final PhylogenyNodeIterator iter = t6.iteratorExternalForward(); + if ( !iter.next().getName().equals( "A" ) ) { + return false; + } + if ( !iter.next().getName().equals( "B" ) ) { + return false; + } + if ( !iter.next().getName().equals( "C" ) ) { + return false; + } + if ( !iter.next().getName().equals( "D" ) ) { + return false; + } + if ( !iter.next().getName().equals( "E" ) ) { + return false; + } + if ( !iter.next().getName().equals( "F" ) ) { + return false; + } + if ( iter.hasNext() ) { + return false; + } } catch ( final Exception e ) { e.printStackTrace( System.out );