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;
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;
}
executeGSDI();
}
+ else if ( o == _gsdir_item ) {
+ if ( isSubtreeDisplayed() ) {
+ return;
+ }
+ executeGSDIR();
+ }
else if ( o == _root_min_dups_item ) {
if ( isSubtreeDisplayed() ) {
return;
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 );
}
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 );
+ 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;
\r
public class GSDIR extends GSDI {\r
\r
- private int _min_duplications_sum;\r
- private final BasicDescriptiveStatistics _duplications_sum_stats;\r
- private final List<Phylogeny> _min_duplications_sum_gene_trees;\r
+ private int _min_duplications_sum;\r
+ private final BasicDescriptiveStatistics _duplications_sum_stats;\r
+ private final List<Phylogeny> _min_duplications_sum_gene_trees;\r
\r
public GSDIR( final Phylogeny gene_tree, final Phylogeny species_tree, final boolean strip_gene_tree, final int x )\r
throws SDIException {\r
super( gene_tree, species_tree, true, strip_gene_tree, true, 1 );\r
_min_duplications_sum = Integer.MAX_VALUE;\r
_min_duplications_sum_gene_trees = new ArrayList<Phylogeny>();\r
- _duplications_sum_stats = new BasicDescriptiveStatistics();\r
+ _duplications_sum_stats = new BasicDescriptiveStatistics();\r
linkNodesOfG();\r
final List<PhylogenyNode> gene_tree_nodes_post_order = new ArrayList<PhylogenyNode>();\r
for( final PhylogenyNodeIterator it = gene_tree.iteratorPostorder(); it.hasNext(); ) {\r
gene_tree_nodes_post_order.add( it.next() );\r
}\r
for( final PhylogenyNode root : gene_tree_nodes_post_order ) {\r
- _gene_tree.reRoot( root );\r
+ _duplications_sum = 0;\r
+ _speciation_or_duplication_events_sum = 0;\r
+ _speciations_sum = 0;\r
+ \r
+ _gene_tree.reRoot( root.getId() ); //TODO reRoot( root )\r
PhylogenyMethods.preOrderReId( getSpeciesTree() );\r
//TEST, remove later\r
- for( final PhylogenyNodeIterator it = getGeneTree().iteratorPostorder(); it.hasNext(); ) {\r
+ for( final PhylogenyNodeIterator it = _gene_tree.iteratorPostorder(); it.hasNext(); ) {\r
final PhylogenyNode g = it.next();\r
if ( g.isInternal() ) {\r
g.setLink( null );\r
}\r
}\r
geneTreePostOrderTraversal();\r
- _duplications_sum_stats.addValue( getMinDuplicationsSum() );\r
- if ( getDuplicationsSum() < getMinDuplicationsSum() ) {\r
- _min_duplications_sum = getDuplicationsSum();\r
+ \r
+ if ( _duplications_sum < _min_duplications_sum ) {\r
+ _min_duplications_sum = _duplications_sum;\r
_min_duplications_sum_gene_trees.clear();\r
_min_duplications_sum_gene_trees.add( getGeneTree().copy() );\r
}\r
- else if ( getDuplicationsSum() == getMinDuplicationsSum() ) {\r
+ else if ( _duplications_sum == _min_duplications_sum ) {\r
_min_duplications_sum_gene_trees.add( getGeneTree().copy() );\r
}\r
+ System.out.println( getDuplicationsSum() );\r
+ _duplications_sum_stats.addValue( _duplications_sum );\r
}\r
}\r
\r
+ \r
+ \r
+\r
public int getMinDuplicationsSum() {\r
return _min_duplications_sum;\r
}\r
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;
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]),"
}
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 );