From: cmzmasek Date: Mon, 10 Dec 2012 06:01:27 +0000 (+0000) Subject: rio - gsdir work... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=877d1e4a2f3e2a937197dc57253ba2cead14a4d6;p=jalview.git rio - gsdir work... --- diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index a238164..0ff8a49 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -99,6 +99,7 @@ import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory; 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.SDIR; import org.forester.sequence.Sequence; import org.forester.util.BasicDescriptiveStatistics; @@ -204,6 +205,7 @@ public final class MainFrameApplication extends MainFrame { private JMenu _analysis_menu; private JMenuItem _load_species_tree_item; private JMenuItem _gsdi_item; + private JMenuItem _gsdir_item; private JMenuItem _root_min_dups_item; private JMenuItem _root_min_cost_l_item; private JMenuItem _lineage_inference; @@ -581,6 +583,12 @@ public final class MainFrameApplication extends MainFrame { } executeGSDI(); } + else if ( o == _gsdir_item ) { + if ( isSubtreeDisplayed() ) { + return; + } + executeGSDIR(); + } else if ( o == _root_min_dups_item ) { if ( isSubtreeDisplayed() ) { return; @@ -654,12 +662,15 @@ public final class MainFrameApplication extends MainFrame { void buildAnalysisMenu() { _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() ); _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) ); + _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (re-rooting)" ) ); + _analysis_menu.addSeparator(); _analysis_menu.add( _root_min_dups_item = new JMenuItem( "Root by Minimizing Duplications | Height (SDI)" ) ); _analysis_menu.add( _root_min_cost_l_item = new JMenuItem( "Root by Minimizing Cost L | Height (SDI)" ) ); _analysis_menu.addSeparator(); _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) ); customizeJMenuItem( _gsdi_item ); + customizeJMenuItem( _gsdir_item ); customizeJMenuItem( _root_min_dups_item ); customizeJMenuItem( _root_min_cost_l_item ); customizeJMenuItem( _load_species_tree_item ); @@ -1231,6 +1242,7 @@ public final class MainFrameApplication extends MainFrame { } catch ( final Exception e ) { JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE ); + return; } gene_tree.setRerootable( false ); _mainpanel.getCurrentTreePanel().setTree( gene_tree ); @@ -1251,6 +1263,46 @@ public final class MainFrameApplication extends MainFrame { + gsdi.getSpeciationsSum(), "GSDI successfully completed", JOptionPane.INFORMATION_MESSAGE ); } + void executeGSDIR() { + if ( !isOKforSDI( false, true ) ) { + return; + } + + final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy(); + gene_tree.setAllNodesToNotCollapse(); + gene_tree.recalculateNumberOfExternalDescendants( false ); + GSDIR gsdir = null; + try { + gsdir = new GSDIR( gene_tree, _species_tree.copy(), true, 1 ); + } + catch ( final Exception e ) { + JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDIR", JOptionPane.ERROR_MESSAGE ); + return; + } + final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTrees().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 ); + 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 ); + } + void executeFunctionAnalysis() { if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) { return; diff --git a/forester/java/src/org/forester/sdi/GSDI.java b/forester/java/src/org/forester/sdi/GSDI.java index 19e2b7d..71f4e45 100644 --- a/forester/java/src/org/forester/sdi/GSDI.java +++ b/forester/java/src/org/forester/sdi/GSDI.java @@ -69,8 +69,8 @@ public class GSDI extends SDI { private final boolean _most_parsimonious_duplication_model; private final boolean _strip_gene_tree; private final boolean _strip_species_tree; - private int _speciation_or_duplication_events_sum; - private int _speciations_sum; + protected int _speciation_or_duplication_events_sum; + protected int _speciations_sum; private final List _stripped_gene_tree_nodes; private final List _stripped_species_tree_nodes; private final Set _mapped_species_tree_nodes; diff --git a/forester/java/src/org/forester/sdi/GSDIR.java b/forester/java/src/org/forester/sdi/GSDIR.java index 8eeca62..34efda2 100644 --- a/forester/java/src/org/forester/sdi/GSDIR.java +++ b/forester/java/src/org/forester/sdi/GSDIR.java @@ -35,44 +35,53 @@ import org.forester.util.BasicDescriptiveStatistics; public class GSDIR extends GSDI { - private int _min_duplications_sum; - private final BasicDescriptiveStatistics _duplications_sum_stats; - private final List _min_duplications_sum_gene_trees; + private int _min_duplications_sum; + private final BasicDescriptiveStatistics _duplications_sum_stats; + private final List _min_duplications_sum_gene_trees; public GSDIR( final Phylogeny gene_tree, final Phylogeny species_tree, final boolean strip_gene_tree, final int x ) throws SDIException { super( gene_tree, species_tree, true, strip_gene_tree, true, 1 ); _min_duplications_sum = Integer.MAX_VALUE; _min_duplications_sum_gene_trees = new ArrayList(); - _duplications_sum_stats = new BasicDescriptiveStatistics(); + _duplications_sum_stats = new BasicDescriptiveStatistics(); linkNodesOfG(); final List gene_tree_nodes_post_order = new ArrayList(); for( final PhylogenyNodeIterator it = gene_tree.iteratorPostorder(); it.hasNext(); ) { gene_tree_nodes_post_order.add( it.next() ); } for( final PhylogenyNode root : gene_tree_nodes_post_order ) { - _gene_tree.reRoot( root ); + _duplications_sum = 0; + _speciation_or_duplication_events_sum = 0; + _speciations_sum = 0; + + _gene_tree.reRoot( root.getId() ); //TODO reRoot( root ) PhylogenyMethods.preOrderReId( getSpeciesTree() ); //TEST, remove later - for( final PhylogenyNodeIterator it = getGeneTree().iteratorPostorder(); it.hasNext(); ) { + for( final PhylogenyNodeIterator it = _gene_tree.iteratorPostorder(); it.hasNext(); ) { final PhylogenyNode g = it.next(); if ( g.isInternal() ) { g.setLink( null ); } } geneTreePostOrderTraversal(); - _duplications_sum_stats.addValue( getMinDuplicationsSum() ); - if ( getDuplicationsSum() < getMinDuplicationsSum() ) { - _min_duplications_sum = getDuplicationsSum(); + + if ( _duplications_sum < _min_duplications_sum ) { + _min_duplications_sum = _duplications_sum; _min_duplications_sum_gene_trees.clear(); _min_duplications_sum_gene_trees.add( getGeneTree().copy() ); } - else if ( getDuplicationsSum() == getMinDuplicationsSum() ) { + else if ( _duplications_sum == _min_duplications_sum ) { _min_duplications_sum_gene_trees.add( getGeneTree().copy() ); } + System.out.println( getDuplicationsSum() ); + _duplications_sum_stats.addValue( _duplications_sum ); } } + + + public int getMinDuplicationsSum() { return _min_duplications_sum; } diff --git a/forester/java/src/org/forester/sdi/TestGSDI.java b/forester/java/src/org/forester/sdi/TestGSDI.java index 8ad459e..54d5255 100644 --- a/forester/java/src/org/forester/sdi/TestGSDI.java +++ b/forester/java/src/org/forester/sdi/TestGSDI.java @@ -27,6 +27,7 @@ package org.forester.sdi; import java.io.IOException; +import org.forester.archaeopteryx.Archaeopteryx; import org.forester.development.DevelopmentTools; import org.forester.io.parsers.nhx.NHXParser; import org.forester.io.parsers.util.ParserUtils; @@ -97,7 +98,6 @@ public final class TestGSDI { private static boolean testGSDI_general() { try { - final String s2_ = "((" + "([&&NHX:S=a1],[&&NHX:S=a2],[&&NHX:S=a3],[&&NHX:S=a4])," + "([&&NHX:S=b1],[&&NHX:S=b2],[&&NHX:S=b3],[&&NHX:S=b4])," + "([&&NHX:S=c1],[&&NHX:S=c2],[&&NHX:S=c3],[&&NHX:S=c4])," @@ -1423,57 +1423,66 @@ public final class TestGSDI { } return true; } - + private static boolean testGSDIR_general() { try { - - final String s2_ = "((" + "([&&NHX:S=a1],[&&NHX:S=a2],[&&NHX:S=a3],[&&NHX:S=a4])," - + "([&&NHX:S=b1],[&&NHX:S=b2],[&&NHX:S=b3],[&&NHX:S=b4])," - + "([&&NHX:S=c1],[&&NHX:S=c2],[&&NHX:S=c3],[&&NHX:S=c4])," - + "([&&NHX:S=d1],[&&NHX:S=d2],[&&NHX:S=d3],[&&NHX:S=d4])),(" - + "([&&NHX:S=e1],[&&NHX:S=e2],[&&NHX:S=e3],[&&NHX:S=e4])," - + "([&&NHX:S=f1],[&&NHX:S=f2],[&&NHX:S=f3],[&&NHX:S=f4])," - + "([&&NHX:S=g1],[&&NHX:S=g2],[&&NHX:S=g3],[&&NHX:S=g4])," - + "([&&NHX:S=h1],[&&NHX:S=h2],[&&NHX:S=h3],[&&NHX:S=h4])),(" - + "([&&NHX:S=i1],[&&NHX:S=i2],[&&NHX:S=i3],[&&NHX:S=i4])," - + "([&&NHX:S=j1],[&&NHX:S=j2],[&&NHX:S=j3],[&&NHX:S=j4])," - + "([&&NHX:S=k1],[&&NHX:S=k2],[&&NHX:S=k3],[&&NHX:S=k4])," - + "([&&NHX:S=l1],[&&NHX:S=l2],[&&NHX:S=l3],[&&NHX:S=l4])),(" - + "([&&NHX:S=m1],[&&NHX:S=m2],[&&NHX:S=m3],[&&NHX:S=m4])," - + "([&&NHX:S=n1],[&&NHX:S=n2],[&&NHX:S=n3],[&&NHX:S=n4])," - + "([&&NHX:S=o1],[&&NHX:S=o2],[&&NHX:S=o3],[&&NHX:S=o4])," - + "([&&NHX:S=p1],[&&NHX:S=p2],[&&NHX:S=p3],[&&NHX:S=p4])" - + "),[&&NHX:S=x],[&&NHX:S=y],[&&NHX:S=z])"; - final Phylogeny s2 = ParserBasedPhylogenyFactory.getInstance().create( s2_, new NHXParser() )[ 0 ]; - s2.setRooted( true ); - final String s1_ = "((([&&NHX:S=A2],[&&NHX:S=A1]),[&&NHX:S=B],[&&NHX:S=C]),[&&NHX:S=D])"; - final Phylogeny s1 = ParserBasedPhylogenyFactory.getInstance().create( s1_, new NHXParser() )[ 0 ]; + final String s1str = "(((([&&NHX:S=HUMAN],([&&NHX:S=MOUSE],[&&NHX:S=RAT])),([&&NHX:S=CAEEL],[&&NHX:S=CAEBR])),[&&NHX:S=YEAST]),[&&NHX:S=ARATH])"; + final Phylogeny s1 = ParserBasedPhylogenyFactory.getInstance().create( s1str, new NHXParser() )[ 0 ]; s1.setRooted( true ); + // Archaeopteryx.createApplication( s1.copy() ); final Phylogeny g1 = TestGSDI - .createPhylogeny( "((((B[&&NHX:S=B],A1[&&NHX:S=A1]),C[&&NHX:S=C]),A2[&&NHX:S=A2]),D[&&NHX:S=D])" ); - final GSDIR sdi1 = new GSDIR( g1, s1, false, 1 ); - // Archaeopteryx.createApplication( g1 ); - // Archaeopteryx.createApplication( s1 ); - if ( sdi1.getDuplicationsSum() != 1 ) { - return false; - } - if ( !PhylogenyMethods.calculateLCA( g1.getNode( "B" ), g1.getNode( "A1" ) ).getNodeData().getEvent() - .isSpeciation() ) { - return false; - } - if ( !PhylogenyMethods.calculateLCA( g1.getNode( "C" ), g1.getNode( "A1" ) ).getNodeData().getEvent() - .isSpeciationOrDuplication() ) { + .createPhylogeny( "(HUMAN[&&NHX:S=HUMAN],(RAT[&&NHX:S=RAT],(CAEEL[&&NHX:T=:S=CAEEL],YEAST[&&NHX:S=YEAST])))" ); + final GSDIR sdi1 = new GSDIR( g1.copy(), s1.copy(), false, 1 ); + if ( sdi1.getMinDuplicationsSum() != 0 ) { return false; } - if ( !( PhylogenyMethods.calculateLCA( g1.getNode( "A2" ), g1.getNode( "A1" ) ).getNodeData().getEvent() - .isDuplication() ) ) { + System.out.println( sdi1.getDuplicationsSumStats().getSummaryAsString() ); + // Archaeopteryx.createApplication( sdi1.getMinDuplicationsSumGeneTrees().get( 0 ) ); + // + final Phylogeny g2 = TestGSDI + .createPhylogeny( "(((HUMAN[&&NHX:S=HUMAN],RAT[&&NHX:S=RAT]),CAEEL[&&NHX:T=:S=CAEEL]),YEAST[&&NHX:S=YEAST])" ); + final GSDIR sdi2 = new GSDIR( g2.copy(), s1.copy(), false, 1 ); + if ( sdi2.getMinDuplicationsSum() != 0 ) { return false; } - if ( !PhylogenyMethods.calculateLCA( g1.getNode( "D" ), g1.getNode( "A1" ) ).getNodeData().getEvent() - .isSpeciation() ) { + System.out.println( sdi2.getDuplicationsSumStats().getSummaryAsString() ); + // Archaeopteryx.createApplication( sdi2.getMinDuplicationsSumGeneTrees().get( 0 ) ); + // + final Phylogeny g3 = TestGSDI + .createPhylogeny( "(RAT[&&NHX:S=RAT],HUMAN[&&NHX:S=HUMAN],(YEAST[&&NHX:S=YEAST],CAEEL[&&NHX:T=:S=CAEEL]))" ); + // Archaeopteryx.createApplication( g3 ); + final GSDIR sdi3 = new GSDIR( g3.copy(), s1.copy(), false, 1 ); + if ( sdi3.getMinDuplicationsSum() != 0 ) { return false; } - + System.out.println( sdi3.getDuplicationsSumStats().getSummaryAsString() ); + // Archaeopteryx.createApplication( sdi3.getMinDuplicationsSumGeneTrees().get( 0 ) ); + // + final Phylogeny g4 = TestGSDI + .createPhylogeny( "(((((MOUSE[&&NHX:S=MOUSE],[&&NHX:S=RAT]),[&&NHX:S=HUMAN]),([&&NHX:S=ARATH],[&&NHX:S=YEAST])),[&&NHX:S=CAEEL]),[&&NHX:S=CAEBR])" ); + Archaeopteryx.createApplication( g4 ); + final GSDIR sdi4 = new GSDIR( g4.copy(), s1.copy(), false, 1 ); + if ( sdi4.getMinDuplicationsSum() != 0 ) { + return false; + } + System.out.println( sdi4.getDuplicationsSumStats().getSummaryAsString() ); + Archaeopteryx.createApplication( sdi4.getMinDuplicationsSumGeneTrees().get( 0 ) ); + // if ( !PhylogenyMethods.calculateLCA( g1.getNode( "B" ), g1.getNode( "A1" ) ).getNodeData().getEvent() + // .isSpeciation() ) { + // return false; + // } + // if ( !PhylogenyMethods.calculateLCA( g1.getNode( "C" ), g1.getNode( "A1" ) ).getNodeData().getEvent() + // .isSpeciationOrDuplication() ) { + // return false; + // } + // if ( !( PhylogenyMethods.calculateLCA( g1.getNode( "A2" ), g1.getNode( "A1" ) ).getNodeData().getEvent() + // .isDuplication() ) ) { + // return false; + // } + // if ( !PhylogenyMethods.calculateLCA( g1.getNode( "D" ), g1.getNode( "A1" ) ).getNodeData().getEvent() + // .isSpeciation() ) { + // return false; + // } } catch ( final Exception e ) { e.printStackTrace( System.out );