"rio" work
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Fri, 14 Dec 2012 22:04:26 +0000 (22:04 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Fri, 14 Dec 2012 22:04:26 +0000 (22:04 +0000)
forester/java/src/org/forester/application/gsdi.java
forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java
forester/java/src/org/forester/phylogeny/iterators/ExternalForwardIterator.java
forester/java/src/org/forester/sdi/GSDI.java
forester/java/src/org/forester/sdi/GSDIR.java
forester/java/src/org/forester/sdi/SDIutil.java
forester/java/src/org/forester/test/Test.java

index 253bfcc..71bd6d9 100644 (file)
@@ -107,7 +107,6 @@ public final class gsdi {
                 System.exit( -1 );
             }
             final List<String> allowed_options = new ArrayList<String>();
-         
             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 );
index babcf6d..7c09e44 100644 (file)
@@ -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 );
index 4d4a602..4e6df65 100644 (file)
@@ -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;
index fd64970..f9cc14e 100644 (file)
@@ -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<PhylogenyNode> getMappedExternalSpeciesTreeNodes() {
         return _mapped_species_tree_nodes;
     }
 
+    @Override
     public final SortedSet<String> 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<PhylogenyNode> getStrippedExternalGeneTreeNodes() {
         return _stripped_gene_tree_nodes;
     }
 
+    @Override
     public List<PhylogenyNode> 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 );
                 }
index d51a803..611ef4a 100644 (file)
@@ -39,29 +39,25 @@ import org.forester.util.BasicDescriptiveStatistics;
 \r
 public class GSDIR implements GSDII {\r
 \r
-    private final int                        _min_duplications_sum;\r
+    private final int _min_duplications_sum;\r
     private final int _speciations_sum;\r
 \r
-    \r
     @Override\r
     public int getSpeciationsSum() {\r
         return _speciations_sum;\r
     }\r
-\r
     private final BasicDescriptiveStatistics _duplications_sum_stats;\r
     private final List<Phylogeny>            _min_duplications_sum_gene_trees;\r
-  \r
     private final List<PhylogenyNode>        _stripped_gene_tree_nodes;\r
     private final List<PhylogenyNode>        _stripped_species_tree_nodes;\r
     private final Set<PhylogenyNode>         _mapped_species_tree_nodes;\r
     private final TaxonomyComparisonBase     _tax_comp_base;\r
     private final SortedSet<String>          _scientific_names_mapped_to_reduced_specificity;\r
-   \r
+\r
     public GSDIR( final Phylogeny gene_tree,\r
                   final Phylogeny species_tree,\r
                   final boolean strip_gene_tree,\r
                   final boolean strip_species_tree ) throws SDIException {\r
-      \r
         final NodesLinkingResult nodes_linking_result = GSDI.linkNodesOfG( gene_tree,\r
                                                                            species_tree,\r
                                                                            null,\r
@@ -76,7 +72,7 @@ public class GSDIR implements GSDII {
         final List<PhylogenyBranch> gene_tree_branches_post_order = new ArrayList<PhylogenyBranch>();\r
         for( final PhylogenyNodeIterator it = gene_tree.iteratorPostorder(); it.hasNext(); ) {\r
             final PhylogenyNode n = it.next();\r
-            if ( !n.isRoot() && !( n.getParent().isRoot() && n.isFirstChildNode() ) ) {\r
+            if ( !n.isRoot() /*&& !( n.getParent().isRoot() && n.isFirstChildNode() )*/) {\r
                 gene_tree_branches_post_order.add( new PhylogenyBranch( n, n.getParent() ) );\r
             }\r
         }\r
@@ -85,7 +81,6 @@ public class GSDIR implements GSDII {
         _min_duplications_sum_gene_trees = new ArrayList<Phylogeny>();\r
         _duplications_sum_stats = new BasicDescriptiveStatistics();\r
         for( final PhylogenyBranch branch : gene_tree_branches_post_order ) {\r
-           \r
             gene_tree.reRoot( branch );\r
             PhylogenyMethods.preOrderReId( species_tree );\r
             //TEST, remove later\r
@@ -98,19 +93,18 @@ public class GSDIR implements GSDII {
             final GSDIsummaryResult gsdi_result = GSDI.geneTreePostOrderTraversal( gene_tree, true );\r
             if ( gsdi_result.getDuplicationsSum() < min_duplications_sum ) {\r
                 min_duplications_sum = gsdi_result.getDuplicationsSum();\r
-                speciations_sum =  gsdi_result.getSpeciationsSum();\r
+                speciations_sum = gsdi_result.getSpeciationsSum();\r
                 _min_duplications_sum_gene_trees.clear();\r
                 _min_duplications_sum_gene_trees.add( gene_tree.copy() );\r
                 //_speciations_sum\r
             }\r
-            else if ( gsdi_result.getDuplicationsSum()== min_duplications_sum ) {\r
+            else if ( gsdi_result.getDuplicationsSum() == min_duplications_sum ) {\r
                 _min_duplications_sum_gene_trees.add( gene_tree.copy() );\r
             }\r
             _duplications_sum_stats.addValue( gsdi_result.getDuplicationsSum() );\r
-           \r
         }\r
-        _min_duplications_sum = min_duplications_sum; \r
-        _speciations_sum =  speciations_sum;\r
+        _min_duplications_sum = min_duplications_sum;\r
+        _speciations_sum = speciations_sum;\r
     }\r
 \r
     public int getMinDuplicationsSum() {\r
index efe1830..5ddd905 100644 (file)
@@ -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;
index f739330..163bdb3 100644 (file)
@@ -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 );