work on: add ability to perform GSDI in applets
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Tue, 12 Mar 2013 20:27:36 +0000 (20:27 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Tue, 12 Mar 2013 20:27:36 +0000 (20:27 +0000)
forester/java/src/org/forester/archaeopteryx/AptxUtil.java
forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java
forester/java/src/org/forester/archaeopteryx/Constants.java
forester/java/src/org/forester/archaeopteryx/MainFrame.java
forester/java/src/org/forester/phylogeny/Phylogeny.java
forester/java/src/org/forester/sdi/GSDIR.java
forester/java/src/org/forester/sdi/SDIR.java
forester/java/src/org/forester/sdi/TestGSDI.java

index a615cb9..89a0cda 100644 (file)
@@ -75,6 +75,7 @@ import org.forester.io.parsers.tol.TolParser;
 import org.forester.io.parsers.util.ParserUtils;
 import org.forester.phylogeny.Phylogeny;
 import org.forester.phylogeny.PhylogenyMethods;
+import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
 import org.forester.phylogeny.PhylogenyNode;
 import org.forester.phylogeny.data.Accession;
 import org.forester.phylogeny.data.BranchColor;
@@ -1061,6 +1062,7 @@ public final class AptxUtil {
         if ( midpoint_reroot ) {
             for( final Phylogeny phy : phys ) {
                 PhylogenyMethods.midpointRoot( phy );
+                PhylogenyMethods.orderAppearance( phy.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
             }
         }
         return phys;
index eaf7536..57a0532 100644 (file)
@@ -36,6 +36,7 @@ import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
 import org.forester.phylogeny.Phylogeny;
 import org.forester.phylogeny.PhylogenyMethods;
+import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
 import org.forester.phylogeny.data.SequenceRelation;
 import org.forester.sdi.GSDI;
 import org.forester.sdi.GSDIR;
@@ -981,6 +982,7 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
         result_gene_tree.setRerootable( false );
         result_gene_tree.clearHashIdToNodeMap();
         result_gene_tree.recalculateNumberOfExternalDescendants( true );
+        PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
         _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
         getMainPanel().getControlPanel().setShowEvents( true );
         showWhole();
index 4530066..bd7d1ac 100644 (file)
@@ -42,8 +42,8 @@ public final class Constants {
     public final static boolean __SYNTH_LF                                                    = false;                                                               // TODO remove me
     public final static boolean ALLOW_DDBJ_BLAST                                              = false;
     public final static String  PRG_NAME                                                      = "Archaeopteryx";
-    final static String         VERSION                                                       = "0.9807 A1ST";
-    final static String         PRG_DATE                                                      = "130311";
+    final static String         VERSION                                                       = "0.9808 A1ST";
+    final static String         PRG_DATE                                                      = "130312";
     final static String         DEFAULT_CONFIGURATION_FILE_NAME                               = "_aptx_configuration_file";
     final static String[]       DEFAULT_FONT_CHOICES                                          = { "Verdana", "Tahoma",
             "Arial", "Helvetica", "Dialog", "Lucida Sans", "SansSerif", "Sans-serif", "Sans" };
index 3c319d3..e0db7b3 100644 (file)
@@ -60,6 +60,7 @@ import org.forester.archaeopteryx.tools.ProcessRunning;
 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
 import org.forester.phylogeny.Phylogeny;
 import org.forester.phylogeny.PhylogenyMethods;
+import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
 import org.forester.phylogeny.PhylogenyNode;
 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
 import org.forester.phylogeny.data.Annotation;
@@ -889,6 +890,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         result_gene_tree.setRerootable( false );
         result_gene_tree.clearHashIdToNodeMap();
         result_gene_tree.recalculateNumberOfExternalDescendants( true );
+        PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
         _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
         getMainPanel().getControlPanel().setShowEvents( true );
         showWhole();
index db6804a..723fab8 100644 (file)
@@ -830,35 +830,6 @@ public class Phylogeny {
     }
 
     /**
-     * Places the root of this Phylogeny on Branch b. The new root is always
-     * placed on the middle of the branch b.
-     * 
-     */
-    public void reRoot( final PhylogenyBranch b ) {
-        final PhylogenyNode n1 = b.getFirstNode();
-        final PhylogenyNode n2 = b.getSecondNode();
-        if ( n1.isExternal() ) {
-            reRoot( n1 );
-        }
-        else if ( n2.isExternal() ) {
-            reRoot( n2 );
-        }
-        else if ( ( n2 == n1.getChildNode1() ) || ( n2 == n1.getChildNode2() ) ) {
-            reRoot( n2 );
-        }
-        else if ( ( n1 == n2.getChildNode1() ) || ( n1 == n2.getChildNode2() ) ) {
-            reRoot( n1 );
-        }
-        else if ( ( n1.getParent() != null ) && n1.getParent().isRoot()
-                && ( ( n1.getParent().getChildNode1() == n2 ) || ( n1.getParent().getChildNode2() == n2 ) ) ) {
-            reRoot( n1 );
-        }
-        else {
-            throw new IllegalArgumentException( "reRoot( Branch b ): b is not a branch." );
-        }
-    }
-
-    /**
      * Places the root of this Phylogeny on the parent branch PhylogenyNode n.
      * The new root is always placed on the middle of the branch.
      * <p>
index 80a0d3a..3615f31 100644 (file)
@@ -66,15 +66,19 @@ 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() && ( gene_tree.getRoot().getNumberOfDescendants() == 2 ) ) ) {\r
                 gene_tree_branches_post_order.add( new PhylogenyBranch( n, n.getParent() ) );\r
             }\r
         }\r
+        if ( gene_tree.getRoot().getNumberOfDescendants() == 2 ) {\r
+            gene_tree_branches_post_order.add( new PhylogenyBranch( gene_tree.getRoot().getChildNode1(), gene_tree\r
+                    .getRoot().getChildNode2() ) );\r
+        }\r
         int min_duplications_sum = Integer.MAX_VALUE;\r
         int speciations_sum = 0;\r
         _duplications_sum_stats = new BasicDescriptiveStatistics();\r
         for( final PhylogenyBranch branch : gene_tree_branches_post_order ) {\r
-            gene_tree.reRoot( branch );\r
+            reRoot( branch, gene_tree );\r
             PhylogenyMethods.preOrderReId( species_tree );\r
             //TEST, remove later\r
             //            for( final PhylogenyNodeIterator it = gene_tree.iteratorPostorder(); it.hasNext(); ) {\r
@@ -180,4 +184,34 @@ public class GSDIR implements GSDII {
         }\r
         return shortests;\r
     }\r
+\r
+    /**\r
+     * Places the root of this Phylogeny on Branch b. The new root is always\r
+     * placed on the middle of the branch b.\r
+     * \r
+     */\r
+    static final void reRoot( final PhylogenyBranch b, final Phylogeny phy ) {\r
+        final PhylogenyNode n1 = b.getFirstNode();\r
+        final PhylogenyNode n2 = b.getSecondNode();\r
+        if ( n1.isExternal() ) {\r
+            phy.reRoot( n1 );\r
+        }\r
+        else if ( n2.isExternal() ) {\r
+            phy.reRoot( n2 );\r
+        }\r
+        else if ( ( n2 == n1.getChildNode1() ) || ( n2 == n1.getChildNode2() ) ) {\r
+            phy.reRoot( n2 );\r
+        }\r
+        else if ( ( n1 == n2.getChildNode1() ) || ( n1 == n2.getChildNode2() ) ) {\r
+            phy.reRoot( n1 );\r
+        }\r
+        //        else if ( ( n1.getParent() != null ) && n1.getParent().isRoot()\r
+        //                && ( ( n1.getParent().getChildNode1() == n2 ) || ( n1.getParent().getChildNode2() == n2 ) ) ) {\r
+        //            phy.reRoot( n1 );\r
+        //           \r
+        //        }\r
+        else {\r
+            throw new IllegalArgumentException( "reRoot( Branch b ): b is not a branch." );\r
+        }\r
+    }\r
 }\r
index 88a2f2c..dbab226 100644 (file)
@@ -292,7 +292,7 @@ public class SDIR {
             prev_root_c2 = prev_root.getChildNode2();
             prev_root_was_dup = prev_root.isDuplication();
             final PhylogenyBranch current_branch = branches.get( j );
-            g.reRoot( current_branch );
+            GSDIR.reRoot( current_branch, g );
             if ( minimize_mapping_cost || minimize_sum_of_dup ) {
                 duplications = sdise.updateM( prev_root_was_dup, prev_root_c1, prev_root_c2 );
             }
index 3f84384..ed1e4d1 100644 (file)
@@ -1517,6 +1517,16 @@ public final class TestGSDI {
             if ( sdi4.getMinDuplicationsSum() != 0 ) {
                 return false;
             }
+            //
+            final String s2str = "(((([&&NHX:S=HUMAN],([&&NHX:S=MOUSE],[&&NHX:S=RAT])),([&&NHX:S=CAEEL],[&&NHX:S=CAEBR])),[&&NHX:S=YEAST]),([&&NHX:S=ARATH],[&&NHX:S=SOYBN]))";
+            final Phylogeny s2 = ParserBasedPhylogenyFactory.getInstance().create( s2str, new NHXParser() )[ 0 ];
+            s2.setRooted( true );
+            final Phylogeny g5 = TestGSDI.createPhylogeny( s2str );
+            final GSDIR sdi5 = new GSDIR( g5, s2, false, false );
+            if ( sdi5.getMinDuplicationsSum() != 0 ) {
+                System.out.println( sdi5.getMinDuplicationsSum() );
+                return false;
+            }
         }
         catch ( final Exception e ) {
             e.printStackTrace( System.out );