From da91573ed6cc107d27b2a18ec31c88a1447a4e80 Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Tue, 12 Mar 2013 20:27:36 +0000 Subject: [PATCH] work on: add ability to perform GSDI in applets --- .../src/org/forester/archaeopteryx/AptxUtil.java | 2 ++ .../org/forester/archaeopteryx/ArchaeopteryxE.java | 2 ++ .../src/org/forester/archaeopteryx/Constants.java | 4 +-- .../src/org/forester/archaeopteryx/MainFrame.java | 2 ++ .../java/src/org/forester/phylogeny/Phylogeny.java | 29 --------------- forester/java/src/org/forester/sdi/GSDIR.java | 38 ++++++++++++++++++-- forester/java/src/org/forester/sdi/SDIR.java | 2 +- forester/java/src/org/forester/sdi/TestGSDI.java | 10 ++++++ 8 files changed, 55 insertions(+), 34 deletions(-) diff --git a/forester/java/src/org/forester/archaeopteryx/AptxUtil.java b/forester/java/src/org/forester/archaeopteryx/AptxUtil.java index a615cb9..89a0cda 100644 --- a/forester/java/src/org/forester/archaeopteryx/AptxUtil.java +++ b/forester/java/src/org/forester/archaeopteryx/AptxUtil.java @@ -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; diff --git a/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java b/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java index eaf7536..57a0532 100644 --- a/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java +++ b/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java @@ -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(); diff --git a/forester/java/src/org/forester/archaeopteryx/Constants.java b/forester/java/src/org/forester/archaeopteryx/Constants.java index 4530066..bd7d1ac 100644 --- a/forester/java/src/org/forester/archaeopteryx/Constants.java +++ b/forester/java/src/org/forester/archaeopteryx/Constants.java @@ -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" }; diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrame.java b/forester/java/src/org/forester/archaeopteryx/MainFrame.java index 3c319d3..e0db7b3 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrame.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrame.java @@ -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(); diff --git a/forester/java/src/org/forester/phylogeny/Phylogeny.java b/forester/java/src/org/forester/phylogeny/Phylogeny.java index db6804a..723fab8 100644 --- a/forester/java/src/org/forester/phylogeny/Phylogeny.java +++ b/forester/java/src/org/forester/phylogeny/Phylogeny.java @@ -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. *

diff --git a/forester/java/src/org/forester/sdi/GSDIR.java b/forester/java/src/org/forester/sdi/GSDIR.java index 80a0d3a..3615f31 100644 --- a/forester/java/src/org/forester/sdi/GSDIR.java +++ b/forester/java/src/org/forester/sdi/GSDIR.java @@ -66,15 +66,19 @@ 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() && ( gene_tree.getRoot().getNumberOfDescendants() == 2 ) ) ) { gene_tree_branches_post_order.add( new PhylogenyBranch( n, n.getParent() ) ); } } + if ( gene_tree.getRoot().getNumberOfDescendants() == 2 ) { + gene_tree_branches_post_order.add( new PhylogenyBranch( gene_tree.getRoot().getChildNode1(), gene_tree + .getRoot().getChildNode2() ) ); + } int min_duplications_sum = Integer.MAX_VALUE; int speciations_sum = 0; _duplications_sum_stats = new BasicDescriptiveStatistics(); for( final PhylogenyBranch branch : gene_tree_branches_post_order ) { - gene_tree.reRoot( branch ); + reRoot( branch, gene_tree ); PhylogenyMethods.preOrderReId( species_tree ); //TEST, remove later // for( final PhylogenyNodeIterator it = gene_tree.iteratorPostorder(); it.hasNext(); ) { @@ -180,4 +184,34 @@ public class GSDIR implements GSDII { } return shortests; } + + /** + * Places the root of this Phylogeny on Branch b. The new root is always + * placed on the middle of the branch b. + * + */ + static final void reRoot( final PhylogenyBranch b, final Phylogeny phy ) { + final PhylogenyNode n1 = b.getFirstNode(); + final PhylogenyNode n2 = b.getSecondNode(); + if ( n1.isExternal() ) { + phy.reRoot( n1 ); + } + else if ( n2.isExternal() ) { + phy.reRoot( n2 ); + } + else if ( ( n2 == n1.getChildNode1() ) || ( n2 == n1.getChildNode2() ) ) { + phy.reRoot( n2 ); + } + else if ( ( n1 == n2.getChildNode1() ) || ( n1 == n2.getChildNode2() ) ) { + phy.reRoot( n1 ); + } + // else if ( ( n1.getParent() != null ) && n1.getParent().isRoot() + // && ( ( n1.getParent().getChildNode1() == n2 ) || ( n1.getParent().getChildNode2() == n2 ) ) ) { + // phy.reRoot( n1 ); + // + // } + else { + throw new IllegalArgumentException( "reRoot( Branch b ): b is not a branch." ); + } + } } diff --git a/forester/java/src/org/forester/sdi/SDIR.java b/forester/java/src/org/forester/sdi/SDIR.java index 88a2f2c..dbab226 100644 --- a/forester/java/src/org/forester/sdi/SDIR.java +++ b/forester/java/src/org/forester/sdi/SDIR.java @@ -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 ); } diff --git a/forester/java/src/org/forester/sdi/TestGSDI.java b/forester/java/src/org/forester/sdi/TestGSDI.java index 3f84384..ed1e4d1 100644 --- a/forester/java/src/org/forester/sdi/TestGSDI.java +++ b/forester/java/src/org/forester/sdi/TestGSDI.java @@ -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 ); -- 1.7.10.2