rio
[jalview.git] / forester / java / src / org / forester / archaeopteryx / MainFrameApplication.java
index aa78613..14b480f 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,11 +1237,19 @@ public final class MainFrameApplication extends MainFrame {
         gene_tree.setAllNodesToNotCollapse();
         gene_tree.recalculateNumberOfExternalDescendants( false );
         GSDI gsdi = null;
+        final Phylogeny species_tree = _species_tree.copy();
         try {
-            gsdi = new GSDI( gene_tree, _species_tree.copy(), false, true, true );
+            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 );
@@ -1252,7 +1261,7 @@ public final class MainFrameApplication extends MainFrame {
         getControlPanel().setShowEvents( true );
         showWhole();
         final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
-        _mainpanel.addPhylogenyInNewTab( gsdi.getSpeciesTree(), getConfiguration(), "species tree", null );
+        _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
         showWhole();
         _mainpanel.getTabbedPane().setSelectedIndex( selected );
         showWhole();
@@ -1270,31 +1279,44 @@ public final class MainFrameApplication extends MainFrame {
         gene_tree.setAllNodesToNotCollapse();
         gene_tree.recalculateNumberOfExternalDescendants( false );
         GSDIR gsdir = null;
+        final Phylogeny species_tree = _species_tree.copy();
         try {
-            gsdir = new GSDIR( gene_tree, _species_tree.copy(), true, true );
+            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 );
+        final List<Phylogeny> assigned_trees = gsdir.getMinDuplicationsSumGeneTrees();
+        final List<Integer> shortests = GSDIR.getIndexesOfShortestTree( assigned_trees );
+        final Phylogeny result_gene_tree = assigned_trees.get( shortests.get( 0 ) );
         result_gene_tree.setRerootable( false );
         result_gene_tree.clearHashIdToNodeMap();
         result_gene_tree.recalculateNumberOfExternalDescendants( true );
         _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
-        //_mainpanel.getCurrentTreePanel().setTree( gene_tree );
-        // _mainpanel.getCurrentTreePanel().setEdited( true );
         getControlPanel().setShowEvents( true );
         showWhole();
         final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
-        _mainpanel.addPhylogenyInNewTab( gsdir.getSpeciesTree(), getConfiguration(), "species tree", null );
+        _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
         showWhole();
         _mainpanel.getTabbedPane().setSelectedIndex( selected );
         showWhole();
         _mainpanel.getCurrentTreePanel().setEdited( true );
-        JOptionPane.showMessageDialog( this, "Duplications: " + gsdir.getDuplicationsSum() + "\n"
-                + "Potential duplications: " + gsdir.getSpeciationOrDuplicationEventsSum() + "\n" + "Speciations: "
-                + gsdir.getSpeciationsSum(), "GSDI successfully completed", JOptionPane.INFORMATION_MESSAGE );
+        JOptionPane.showMessageDialog( this,
+                                       "Duplications (min): " + gsdir.getMinDuplicationsSum() + "\n" + "Speciations: "
+                                               + gsdir.getSpeciationsSum() + "\n"
+                                               + "Number of root positions minimizing duplications sum: "
+                                               + gsdir.getMinDuplicationsSumGeneTrees().size() + "\n"
+                                               + "Number of shortest trees: " + shortests.size(),
+                                       "GSDIR successfully completed",
+                                       JOptionPane.INFORMATION_MESSAGE );
     }
 
     void executeFunctionAnalysis() {