From 9956a18ae590422c0500a1770ff4cdaf8d787f82 Mon Sep 17 00:00:00 2001 From: cmzmasek Date: Fri, 14 Dec 2012 08:40:50 +0000 Subject: [PATCH] rio - gsdir work... --- .../java/src/org/forester/application/gsdi.java | 189 ++++++++------------ .../archaeopteryx/MainFrameApplication.java | 10 +- forester/java/src/org/forester/sdi/GSDI.java | 42 ++--- forester/java/src/org/forester/sdi/GSDII.java | 24 +++ forester/java/src/org/forester/sdi/GSDIR.java | 46 +++-- 5 files changed, 152 insertions(+), 159 deletions(-) create mode 100644 forester/java/src/org/forester/sdi/GSDII.java diff --git a/forester/java/src/org/forester/application/gsdi.java b/forester/java/src/org/forester/application/gsdi.java index 871658c..253bfcc 100644 --- a/forester/java/src/org/forester/application/gsdi.java +++ b/forester/java/src/org/forester/application/gsdi.java @@ -48,8 +48,8 @@ import org.forester.phylogeny.PhylogenyNode; import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory; import org.forester.phylogeny.factories.PhylogenyFactory; import org.forester.sdi.GSDI; +import org.forester.sdi.GSDII; import org.forester.sdi.GSDIR; -import org.forester.sdi.SDI; import org.forester.sdi.SDIException; import org.forester.sdi.SDIutil; import org.forester.sdi.SDIutil.ALGORITHM; @@ -63,7 +63,6 @@ public final class gsdi { final static public boolean REPLACE_UNDERSCORES_IN_NH_SPECIES_TREE = true; final static private String ALLOW_STRIPPING_OF_GENE_TREE_OPTION = "g"; - final static private String SDISE_OPTION = "b"; final static private String GSDIR_OPTION = "r"; final static private String MOST_PARSIMONIOUS_OPTION = "m"; final static private String GUESS_FORMAT_OF_SPECIES_TREE = "q"; @@ -108,7 +107,7 @@ public final class gsdi { System.exit( -1 ); } final List allowed_options = new ArrayList(); - allowed_options.add( gsdi.SDISE_OPTION ); + allowed_options.add( gsdi.GSDIR_OPTION ); allowed_options.add( gsdi.GUESS_FORMAT_OF_SPECIES_TREE ); allowed_options.add( gsdi.MOST_PARSIMONIOUS_OPTION ); @@ -131,9 +130,7 @@ public final class gsdi { if ( cla.isOptionSet( gsdi.GSDIR_OPTION ) ) { base_algorithm = ALGORITHM.GSDIR; } - else if ( cla.isOptionSet( gsdi.SDISE_OPTION ) ) { - base_algorithm = ALGORITHM.SDI; - } + if ( cla.isOptionSet( gsdi.MOST_PARSIMONIOUS_OPTION ) ) { if ( base_algorithm == ALGORITHM.SDI ) { ForesterUtil.fatalError( gsdi.PRG_NAME, "Cannot use most parsimonious duplication mode with SDI" ); @@ -280,40 +277,31 @@ public final class gsdi { + ( ForesterUtil.isEmpty( species_tree.getName() ) ? "" : gene_tree.getName() ) ); System.out.println( "Species tree name : " + ( ForesterUtil.isEmpty( species_tree.getName() ) ? "" : gene_tree.getName() ) ); - Object sdi = null; + GSDII gsdii = null; final long start_time = new Date().getTime(); try { - if ( ( base_algorithm == ALGORITHM.GSDI ) || ( base_algorithm == ALGORITHM.GSDIR ) ) { - if ( base_algorithm == ALGORITHM.GSDI ) { - System.out.println( "Algorithm : GSDI" ); - log_writer.println( "Algorithm : GSDI" ); - } - else if ( base_algorithm == ALGORITHM.GSDIR ) { - System.out.println( "Algorithm : GSDIR" ); - log_writer.println( "Algorithm : GSDIR" ); - } - System.out.println( "Use most parsimonous duplication model : " + most_parsimonous_duplication_model ); - System.out.println( "Allow stripping of gene tree nodes : " + allow_stripping_of_gene_tree ); - log_writer.println( "Use most parsimonous duplication model : " + most_parsimonous_duplication_model ); - log_writer.println( "Allow stripping of gene tree nodes : " + allow_stripping_of_gene_tree ); - log_writer.flush(); - if ( base_algorithm == ALGORITHM.GSDI ) { - sdi = new GSDI( gene_tree, - species_tree, - most_parsimonous_duplication_model, - allow_stripping_of_gene_tree, - true ); - } - else if ( base_algorithm == ALGORITHM.GSDIR ) { - sdi = new GSDIR( gene_tree, species_tree, allow_stripping_of_gene_tree, true ); - } + if ( base_algorithm == ALGORITHM.GSDI ) { + System.out.println( "Algorithm : GSDI" ); + log_writer.println( "Algorithm : GSDI" ); } - else { - System.out.println(); - System.out.println( "Algorithm : SDI" ); - log_writer.println( "Algorithm : SDI" ); - log_writer.flush(); - sdi = new SDI( gene_tree, species_tree ); + else if ( base_algorithm == ALGORITHM.GSDIR ) { + System.out.println( "Algorithm : GSDIR" ); + log_writer.println( "Algorithm : GSDIR" ); + } + System.out.println( "Use most parsimonous duplication model : " + most_parsimonous_duplication_model ); + System.out.println( "Allow stripping of gene tree nodes : " + allow_stripping_of_gene_tree ); + log_writer.println( "Use most parsimonous duplication model : " + most_parsimonous_duplication_model ); + log_writer.println( "Allow stripping of gene tree nodes : " + allow_stripping_of_gene_tree ); + log_writer.flush(); + if ( base_algorithm == ALGORITHM.GSDI ) { + gsdii = new GSDI( gene_tree, + species_tree, + most_parsimonous_duplication_model, + allow_stripping_of_gene_tree, + true ); + } + else if ( base_algorithm == ALGORITHM.GSDIR ) { + gsdii = new GSDIR( gene_tree, species_tree, allow_stripping_of_gene_tree, true ); } } catch ( final SDIException e ) { @@ -330,25 +318,18 @@ public final class gsdi { + "ms" ); log_writer.println( "Running time (excluding I/O) : " + ( new Date().getTime() - start_time ) + "ms" ); - if ( ( base_algorithm == ALGORITHM.GSDI ) ) { - final GSDI gsdi = ( GSDI ) sdi; - System.out.println( "Mapping based on : " + gsdi.getTaxCompBase() ); - log_writer.println( "Mapping based on : " + gsdi.getTaxCompBase() ); - } + System.out.println( "Mapping based on : " + gsdii.getTaxCompBase() ); + log_writer.println( "Mapping based on : " + gsdii.getTaxCompBase() ); if ( ( base_algorithm == ALGORITHM.GSDIR ) ) { - final GSDIR gsdir = ( GSDIR ) sdi; - System.out.println( "Mapping based on : " + gsdir.getTaxCompBase() ); - log_writer.println( "Mapping based on : " + gsdir.getTaxCompBase() ); - System.out.println( "Minimal duplications sum : " + gsdir.getMinDuplicationsSum() ); - log_writer.println( "Minimal duplications sum : " + gsdir.getMinDuplicationsSum() ); - System.out.println( "Duplications sum statistics : " + gsdir.getMinDuplicationsSum() ); + final GSDIR gsdir = ( GSDIR ) gsdii; + System.out.println( "Duplications sum statistics : " + gsdir.getMinDuplicationsSum() ); log_writer.println( "Duplications sum statistics : " + gsdir.getMinDuplicationsSum() ); } try { final PhylogenyWriter writer = new PhylogenyWriter(); if ( base_algorithm == ALGORITHM.GSDIR ) { writer.toPhyloXML( out_file, - ( ( GSDIR ) sdi ).getMinDuplicationsSumGeneTrees(), + ( ( GSDIR ) gsdii ).getMinDuplicationsSumGeneTrees(), 0, ForesterUtil.LINE_SEPARATOR ); } @@ -362,74 +343,62 @@ public final class gsdi { } System.out.println( "Wrote resulting gene tree to : " + out_file.getCanonicalPath() ); log_writer.println( "Wrote resulting gene tree to : " + out_file.getCanonicalPath() ); - if ( base_algorithm == ALGORITHM.SDI ) { - sdi = sdi; - sdi.computeMappingCostL(); - System.out.println( "Mapping cost : " + sdi.computeMappingCostL() ); - log_writer.println( "Mapping cost : " + sdi.computeMappingCostL() ); - } - else if ( ( base_algorithm == ALGORITHM.GSDI ) || ( base_algorithm == ALGORITHM.GSDIR ) ) { - final GSDI gsdi = ( GSDI ) sdi; - final File species_tree_used_file = new File( ForesterUtil.removeSuffix( out_file.toString() ) - + SUFFIX_FOR_SPECIES_TREE_USED ); - try { - final PhylogenyWriter writer = new PhylogenyWriter(); - writer.toPhyloXML( species_tree_used_file, gsdi.getSpeciesTree(), 0 ); - } - catch ( final IOException e ) { - ForesterUtil.fatalError( PRG_NAME, "Failed to write to [" + species_tree_used_file.getCanonicalPath() - + "]: " + e.getMessage() ); - } - System.out.println( "Wrote (stripped) species tree to : " - + species_tree_used_file.getCanonicalPath() ); - log_writer.println( "Wrote (stripped) species tree to : " - + species_tree_used_file.getCanonicalPath() ); - if ( ( gsdi.getReMappedScientificNamesFromGeneTree() != null ) - && !gsdi.getReMappedScientificNamesFromGeneTree().isEmpty() ) { - System.out.println( "Number of gene tree species remapped : " - + gsdi.getReMappedScientificNamesFromGeneTree().size() ); - log_writer.println( "Number of gene tree species remapped : " - + gsdi.getReMappedScientificNamesFromGeneTree().size() ); - writeToRemappedFile( out_file, gsdi.getReMappedScientificNamesFromGeneTree(), log_writer ); - } + final File species_tree_used_file = new File( ForesterUtil.removeSuffix( out_file.toString() ) + + SUFFIX_FOR_SPECIES_TREE_USED ); + try { + final PhylogenyWriter writer = new PhylogenyWriter(); + writer.toPhyloXML( species_tree_used_file, species_tree, 0 ); + } + catch ( final IOException e ) { + ForesterUtil.fatalError( PRG_NAME, "Failed to write to [" + species_tree_used_file.getCanonicalPath() + + "]: " + e.getMessage() ); + } + System.out.println( "Wrote (stripped) species tree to : " + species_tree_used_file.getCanonicalPath() ); + log_writer.println( "Wrote (stripped) species tree to : " + species_tree_used_file.getCanonicalPath() ); + if ( ( gsdii.getReMappedScientificNamesFromGeneTree() != null ) + && !gsdii.getReMappedScientificNamesFromGeneTree().isEmpty() ) { + System.out.println( "Number of gene tree species remapped : " + + gsdii.getReMappedScientificNamesFromGeneTree().size() ); + log_writer.println( "Number of gene tree species remapped : " + + gsdii.getReMappedScientificNamesFromGeneTree().size() ); + writeToRemappedFile( out_file, gsdii.getReMappedScientificNamesFromGeneTree(), log_writer ); } System.out.println( "Number of external nodes in gene tree : " + gene_tree.getNumberOfExternalNodes() ); log_writer.println( "Number of external nodes in gene tree : " + gene_tree.getNumberOfExternalNodes() ); - System.out.println( "Number of external nodes in species tree : " - + sdi.getSpeciesTree().getNumberOfExternalNodes() ); - log_writer.println( "Number of external nodes in species tree : " - + sdi.getSpeciesTree().getNumberOfExternalNodes() ); - if ( ( base_algorithm == ALGORITHM.GSDI ) ) { - final GSDI gsdi = ( GSDI ) sdi; - final int poly = PhylogenyMethods.countNumberOfPolytomies( gsdi.getSpeciesTree() ); - System.out.println( "Number of polytomies in species tree : " + poly ); - log_writer.println( "Number of polytomies in species tree : " + poly ); - System.out.println( "External nodes stripped from gene tree : " - + gsdi.getStrippedExternalGeneTreeNodes().size() ); - log_writer.println( "External nodes stripped from gene tree : " - + gsdi.getStrippedExternalGeneTreeNodes().size() ); - System.out.println( "External nodes stripped from species tree: " - + gsdi.getStrippedSpeciesTreeNodes().size() ); - log_writer.println( "External nodes stripped from species tree: " - + gsdi.getStrippedSpeciesTreeNodes().size() ); - } + System.out.println( "Number of external nodes in species tree : " + species_tree.getNumberOfExternalNodes() ); + log_writer.println( "Number of external nodes in species tree : " + species_tree.getNumberOfExternalNodes() ); + final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree ); + System.out.println( "Number of polytomies in species tree : " + poly ); + log_writer.println( "Number of polytomies in species tree : " + poly ); + System.out.println( "External nodes stripped from gene tree : " + + gsdii.getStrippedExternalGeneTreeNodes().size() ); + log_writer.println( "External nodes stripped from gene tree : " + + gsdii.getStrippedExternalGeneTreeNodes().size() ); + System.out.println( "External nodes stripped from species tree: " + gsdii.getStrippedSpeciesTreeNodes().size() ); + log_writer.println( "External nodes stripped from species tree: " + gsdii.getStrippedSpeciesTreeNodes().size() ); System.out.println(); - System.out.println( "Number of duplications : " + sdi.getDuplicationsSum() ); - log_writer.println( "Number of duplications : " + sdi.getDuplicationsSum() ); - if ( ( base_algorithm == ALGORITHM.GSDI ) ) { - final GSDI gsdi = ( GSDI ) sdi; + System.out.println( "Number of speciations : " + gsdii.getSpeciationsSum() ); + log_writer.println( "Number of speciations : " + gsdii.getSpeciationsSum() ); + if ( ( base_algorithm == ALGORITHM.GSDIR ) ) { + final GSDIR gsdir = ( GSDIR ) gsdii; + System.out.println( "Minimal number of duplications : " + gsdir.getMinDuplicationsSum() ); + log_writer.println( "Minimal number of duplications : " + gsdir.getMinDuplicationsSum() ); + } + else if ( ( base_algorithm == ALGORITHM.GSDI ) ) { + final GSDI gsdi = ( GSDI ) gsdii; + System.out.println( "Number of duplications : " + gsdi.getDuplicationsSum() ); + log_writer.println( "Number of duplications : " + gsdi.getDuplicationsSum() ); if ( !most_parsimonous_duplication_model ) { final int u = gsdi.getSpeciationOrDuplicationEventsSum(); System.out.println( "Number of potential duplications : " + u ); log_writer.println( "Number of potential duplications : " + u ); } - System.out.println( "Number of speciations : " + gsdi.getSpeciationsSum() ); - log_writer.println( "Number of speciations : " + gsdi.getSpeciationsSum() ); - log_writer.println(); - printMappedNodesToLog( log_writer, gsdi ); - log_writer.println(); - printStrippedGeneTreeNodesToLog( log_writer, gsdi ); + } + log_writer.println(); + printMappedNodesToLog( log_writer, gsdii ); + log_writer.println(); + printStrippedGeneTreeNodesToLog( log_writer, gsdii ); System.out.println(); System.out.println( "Wrote log to : " + log_file.getCanonicalPath() ); System.out.println(); @@ -449,7 +418,7 @@ public final class gsdi { log_writer.println( "Wrote remapped gene tree species to : " + file.getCanonicalPath() ); } - private static void printMappedNodesToLog( final EasyWriter log_writer, final GSDI gsdi ) throws IOException { + private static void printMappedNodesToLog( final EasyWriter log_writer, final GSDII gsdi ) throws IOException { final SortedSet ss = new TreeSet(); for( final PhylogenyNode n : gsdi.getMappedExternalSpeciesTreeNodes() ) { ss.add( n.toString() ); @@ -474,7 +443,7 @@ public final class gsdi { ForesterUtil.fatalError( gsdi.PRG_NAME, msg ); } - private static void printStrippedGeneTreeNodesToLog( final EasyWriter log_writer, final GSDI gsdi ) + private static void printStrippedGeneTreeNodesToLog( final EasyWriter log_writer, final GSDII gsdi ) throws IOException { final SortedMap sm = new TreeMap(); for( final PhylogenyNode n : gsdi.getStrippedExternalGeneTreeNodes() ) { @@ -511,8 +480,6 @@ public final class gsdi { System.out.println( " as potential duplications due to polytomies in the species tree" ); System.out.println( " -" + gsdi.GUESS_FORMAT_OF_SPECIES_TREE + ": to allow species tree in other formats than phyloXML (i.e. Newick, NHX, Nexus)" ); - System.out.println( " -" + gsdi.SDISE_OPTION - + ": to use SDIse algorithm instead of GSDI algorithm (for binary species trees)" ); System.out.println( " -" + gsdi.GSDIR_OPTION + ": to use GSDIR algorithm instead of GSDI algorithm (re-rooting)" ); System.out.println(); diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index 6a0846b..babcf6d 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -1236,8 +1236,9 @@ public final class MainFrameApplication extends MainFrame { gene_tree.setAllNodesToNotCollapse(); gene_tree.recalculateNumberOfExternalDescendants( false ); GSDI gsdi = null; + 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 Exception e ) { JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE ); @@ -1252,7 +1253,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,8 +1271,9 @@ public final class MainFrameApplication extends MainFrame { gene_tree.setAllNodesToNotCollapse(); gene_tree.recalculateNumberOfExternalDescendants( false ); GSDIR gsdir = null; + 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 Exception e ) { JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDIR", JOptionPane.ERROR_MESSAGE ); @@ -1287,7 +1289,7 @@ public final class MainFrameApplication extends MainFrame { 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(); diff --git a/forester/java/src/org/forester/sdi/GSDI.java b/forester/java/src/org/forester/sdi/GSDI.java index d6e6fb6..fd64970 100644 --- a/forester/java/src/org/forester/sdi/GSDI.java +++ b/forester/java/src/org/forester/sdi/GSDI.java @@ -41,7 +41,7 @@ import org.forester.phylogeny.iterators.PhylogenyNodeIterator; import org.forester.sdi.SDIutil.TaxonomyComparisonBase; import org.forester.util.ForesterUtil; -public final class GSDI { +public final class GSDI implements GSDII { private final boolean _most_parsimonious_duplication_model; private final int _speciation_or_duplication_events_sum; @@ -71,8 +71,8 @@ public final class GSDI { .getScientificNamesMappedToReducedSpecificity(); _tax_comp_base = nodes_linking_result.getTaxCompBase(); PhylogenyMethods.preOrderReId( species_tree ); - final GSDIsummaryResult gsdi_summary_result = new GSDIsummaryResult(); - geneTreePostOrderTraversal( gene_tree, _most_parsimonious_duplication_model, gsdi_summary_result ); + final GSDIsummaryResult gsdi_summary_result = geneTreePostOrderTraversal( gene_tree, + _most_parsimonious_duplication_model ); _speciation_or_duplication_events_sum = gsdi_summary_result.getSpeciationOrDuplicationEventsSum(); _speciations_sum = gsdi_summary_result.getSpeciationsSum(); _duplications_sum = gsdi_summary_result.getDuplicationsSum(); @@ -134,11 +134,12 @@ public final class GSDI { * Preconditions: Mapping M for external nodes must have been calculated and * the species tree must be labeled in preorder. *

+ * @return * */ - final static void geneTreePostOrderTraversal( final Phylogeny gene_tree, - final boolean most_parsimonious_duplication_model, - final GSDIsummaryResult res ) { + final static GSDIsummaryResult geneTreePostOrderTraversal( final Phylogeny gene_tree, + final boolean most_parsimonious_duplication_model ) { + final GSDIsummaryResult res = new GSDIsummaryResult(); for( final PhylogenyNodeIterator it = gene_tree.iteratorPostorder(); it.hasNext(); ) { final PhylogenyNode g = it.next(); if ( g.isInternal() ) { @@ -156,6 +157,7 @@ public final class GSDI { determineEvent( s1, g, most_parsimonious_duplication_model, res ); } } + return res; } /** @@ -245,7 +247,7 @@ public final class GSDI { } } if ( strip_species_tree ) { - stripSpeciesTree( species_tree, species_tree_ext_nodes, res.getMappedSpeciesTreeNodes() ); + stripSpeciesTree( species_tree, species_tree_ext_nodes, res ); } return res; } @@ -256,20 +258,6 @@ public final class GSDI { scientific_names_mapped_to_reduced_specificity.add( s1 + " -> " + s2 ); } - // Used by GSDIR - // protected GSDI( final Phylogeny gene_tree, final Phylogeny species_tree, final boolean strip_gene_tree ) - // throws SDIException { - // super( gene_tree, species_tree ); - // _speciation_or_duplication_events_sum = -1; - // _speciations_sum = 0; - // _most_parsimonious_duplication_model = true; - // _duplications_sum = 0; - // _stripped_gene_tree_nodes = new ArrayList(); - // _stripped_species_tree_nodes = new ArrayList(); - // _mapped_species_tree_nodes = new HashSet(); - // _scientific_names_mapped_to_reduced_specificity = new TreeSet(); - // } - // s is the node on the species tree g maps to. private final static void determineEvent( final PhylogenyNode s, final PhylogenyNode g, final boolean most_parsimonious_duplication_model, @@ -337,19 +325,17 @@ public final class GSDI { } } - private final static List stripSpeciesTree( final Phylogeny species_tree, - final List species_tree_ext_nodes, - final Set keep ) { - final List stripped_species_tree_nodes = new ArrayList(); + private final static void stripSpeciesTree( final Phylogeny species_tree, + final List species_tree_ext_nodes, + final NodesLinkingResult res ) { for( final PhylogenyNode s : species_tree_ext_nodes ) { - if ( !keep.contains( s ) ) { + if ( !res.getMappedSpeciesTreeNodes().contains( s ) ) { species_tree.deleteSubtree( s, true ); - stripped_species_tree_nodes.add( s ); + res.getStrippedSpeciesTreeNodes().add( s ); } } species_tree.clearHashIdToNodeMap(); species_tree.externalNodesHaveChanged(); - return stripped_species_tree_nodes; } private final static void stripTree( final Phylogeny phy, final List strip_nodes ) { diff --git a/forester/java/src/org/forester/sdi/GSDII.java b/forester/java/src/org/forester/sdi/GSDII.java new file mode 100644 index 0000000..f5f99e8 --- /dev/null +++ b/forester/java/src/org/forester/sdi/GSDII.java @@ -0,0 +1,24 @@ + +package org.forester.sdi; + +import java.util.List; +import java.util.Set; +import java.util.SortedSet; + +import org.forester.phylogeny.PhylogenyNode; +import org.forester.sdi.SDIutil.TaxonomyComparisonBase; + +public interface GSDII { + + public abstract int getSpeciationsSum(); + + public abstract Set getMappedExternalSpeciesTreeNodes(); + + public abstract SortedSet getReMappedScientificNamesFromGeneTree(); + + public abstract List getStrippedExternalGeneTreeNodes(); + + public abstract List getStrippedSpeciesTreeNodes(); + + public abstract TaxonomyComparisonBase getTaxCompBase(); +} \ No newline at end of file diff --git a/forester/java/src/org/forester/sdi/GSDIR.java b/forester/java/src/org/forester/sdi/GSDIR.java index 6c4d267..d51a803 100644 --- a/forester/java/src/org/forester/sdi/GSDIR.java +++ b/forester/java/src/org/forester/sdi/GSDIR.java @@ -37,25 +37,31 @@ import org.forester.phylogeny.iterators.PhylogenyNodeIterator; import org.forester.sdi.SDIutil.TaxonomyComparisonBase; import org.forester.util.BasicDescriptiveStatistics; -public class GSDIR { +public class GSDIR implements GSDII { + + private final int _min_duplications_sum; + private final int _speciations_sum; + + + @Override + public int getSpeciationsSum() { + return _speciations_sum; + } - private int _min_duplications_sum; private final BasicDescriptiveStatistics _duplications_sum_stats; private final List _min_duplications_sum_gene_trees; - protected int _speciations_sum; - protected int _duplications_sum; + private final List _stripped_gene_tree_nodes; private final List _stripped_species_tree_nodes; private final Set _mapped_species_tree_nodes; private final TaxonomyComparisonBase _tax_comp_base; private final SortedSet _scientific_names_mapped_to_reduced_specificity; - + public GSDIR( final Phylogeny gene_tree, final Phylogeny species_tree, final boolean strip_gene_tree, final boolean strip_species_tree ) throws SDIException { - _speciations_sum = 0; - _duplications_sum = 0; + final NodesLinkingResult nodes_linking_result = GSDI.linkNodesOfG( gene_tree, species_tree, null, @@ -74,12 +80,12 @@ public class GSDIR { gene_tree_branches_post_order.add( new PhylogenyBranch( n, n.getParent() ) ); } } - _min_duplications_sum = Integer.MAX_VALUE; + int min_duplications_sum = Integer.MAX_VALUE; + int speciations_sum = 0; _min_duplications_sum_gene_trees = new ArrayList(); _duplications_sum_stats = new BasicDescriptiveStatistics(); for( final PhylogenyBranch branch : gene_tree_branches_post_order ) { - _duplications_sum = 0; - _speciations_sum = 0; + gene_tree.reRoot( branch ); PhylogenyMethods.preOrderReId( species_tree ); //TEST, remove later @@ -89,19 +95,22 @@ public class GSDIR { // g.setLink( null ); // } // } - final GSDIsummaryResult gsdi_summary_result = new GSDIsummaryResult(); - GSDI.geneTreePostOrderTraversal( gene_tree, true, gsdi_summary_result ); - if ( _duplications_sum < _min_duplications_sum ) { - _min_duplications_sum = _duplications_sum; + final GSDIsummaryResult gsdi_result = GSDI.geneTreePostOrderTraversal( gene_tree, true ); + if ( gsdi_result.getDuplicationsSum() < min_duplications_sum ) { + min_duplications_sum = gsdi_result.getDuplicationsSum(); + speciations_sum = gsdi_result.getSpeciationsSum(); _min_duplications_sum_gene_trees.clear(); _min_duplications_sum_gene_trees.add( gene_tree.copy() ); //_speciations_sum } - else if ( _duplications_sum == _min_duplications_sum ) { + else if ( gsdi_result.getDuplicationsSum()== min_duplications_sum ) { _min_duplications_sum_gene_trees.add( gene_tree.copy() ); } - _duplications_sum_stats.addValue( _duplications_sum ); + _duplications_sum_stats.addValue( gsdi_result.getDuplicationsSum() ); + } + _min_duplications_sum = min_duplications_sum; + _speciations_sum = speciations_sum; } public int getMinDuplicationsSum() { @@ -116,22 +125,27 @@ public class GSDIR { return _duplications_sum_stats; } + @Override public Set getMappedExternalSpeciesTreeNodes() { return _mapped_species_tree_nodes; } + @Override public final SortedSet getReMappedScientificNamesFromGeneTree() { return _scientific_names_mapped_to_reduced_specificity; } + @Override public List getStrippedExternalGeneTreeNodes() { return _stripped_gene_tree_nodes; } + @Override public List getStrippedSpeciesTreeNodes() { return _stripped_species_tree_nodes; } + @Override public TaxonomyComparisonBase getTaxCompBase() { return _tax_comp_base; } -- 1.7.10.2