System.exit( -1 );
}
final List<String> allowed_options = new ArrayList<String>();
-
allowed_options.add( gsdi.GSDIR_OPTION );
allowed_options.add( gsdi.GUESS_FORMAT_OF_SPECIES_TREE );
allowed_options.add( gsdi.MOST_PARSIMONIOUS_OPTION );
if ( cla.isOptionSet( gsdi.GSDIR_OPTION ) ) {
base_algorithm = ALGORITHM.GSDIR;
}
-
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" );
}
}
}
+ catch ( final SDIException e ) {
+ fatalError( "user error", e.getMessage(), log_writer );
+ }
catch ( final IOException e ) {
fatalError( "ERROR",
"Failed to read species tree from [" + species_tree_file + "]: " + e.getMessage(),
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 );
+ 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 );
log_writer.println( "Mapping based on : " + gsdii.getTaxCompBase() );
if ( ( base_algorithm == ALGORITHM.GSDIR ) ) {
final GSDIR gsdir = ( GSDIR ) gsdii;
- System.out.println( "Duplications sum statistics : " + gsdir.getMinDuplicationsSum() );
+ System.out.println( "Duplications sum statistics : " + gsdir.getMinDuplicationsSum() );
log_writer.println( "Duplications sum statistics : " + gsdir.getMinDuplicationsSum() );
}
try {
System.out.println( "Number of potential duplications : " + u );
log_writer.println( "Number of potential duplications : " + u );
}
-
}
log_writer.println();
printMappedNodesToLog( log_writer, gsdii );
import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
import org.forester.sdi.GSDI;
import org.forester.sdi.GSDIR;
+import org.forester.sdi.SDIException;
import org.forester.sdi.SDIR;
import org.forester.sequence.Sequence;
import org.forester.util.BasicDescriptiveStatistics;
gene_tree.setAllNodesToNotCollapse();
gene_tree.recalculateNumberOfExternalDescendants( false );
GSDI gsdi = null;
- Phylogeny species_tree = _species_tree.copy();
+ final Phylogeny species_tree = _species_tree.copy();
try {
gsdi = new GSDI( gene_tree, species_tree, false, true, true );
}
+ catch ( final SDIException e ) {
+ JOptionPane.showMessageDialog( this,
+ e.getLocalizedMessage(),
+ "Error during GSDI",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
catch ( final Exception e ) {
- JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE );
+ AptxUtil.unexpectedException( e );
return;
}
gene_tree.setRerootable( false );
gene_tree.setAllNodesToNotCollapse();
gene_tree.recalculateNumberOfExternalDescendants( false );
GSDIR gsdir = null;
- Phylogeny species_tree = _species_tree.copy();
+ final Phylogeny species_tree = _species_tree.copy();
try {
gsdir = new GSDIR( gene_tree, species_tree, true, true );
}
+ catch ( final SDIException e ) {
+ JOptionPane.showMessageDialog( this,
+ e.getLocalizedMessage(),
+ "Error during GSDIR",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
catch ( final Exception e ) {
- JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDIR", JOptionPane.ERROR_MESSAGE );
+ AptxUtil.unexpectedException( e );
return;
}
final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTrees().get( 0 );
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyNode;
-/*
- * @author Christian Zmasek
- */
public class ExternalForwardIterator implements PhylogenyNodeIterator {
private PhylogenyNode _current_node;
import org.forester.sdi.SDIutil.TaxonomyComparisonBase;
import org.forester.util.ForesterUtil;
-public final class GSDI implements GSDII {
+public final class GSDI implements GSDII {
private final boolean _most_parsimonious_duplication_model;
private final int _speciation_or_duplication_events_sum;
return _duplications_sum;
}
+ @Override
public Set<PhylogenyNode> getMappedExternalSpeciesTreeNodes() {
return _mapped_species_tree_nodes;
}
+ @Override
public final SortedSet<String> getReMappedScientificNamesFromGeneTree() {
return _scientific_names_mapped_to_reduced_specificity;
}
return _speciation_or_duplication_events_sum;
}
+ @Override
public final int getSpeciationsSum() {
return _speciations_sum;
}
+ @Override
public List<PhylogenyNode> getStrippedExternalGeneTreeNodes() {
return _stripped_gene_tree_nodes;
}
+ @Override
public List<PhylogenyNode> getStrippedSpeciesTreeNodes() {
return _stripped_species_tree_nodes;
}
+ @Override
public TaxonomyComparisonBase getTaxCompBase() {
return _tax_comp_base;
}
final String tax_str = SDIutil.taxonomyToString( s, res.getTaxCompBase() );
if ( !ForesterUtil.isEmpty( tax_str ) ) {
if ( species_to_node_map.containsKey( tax_str ) ) {
- throw new SDIException( "taxonomy \"" + s + "\" is not unique in species tree" );
+ throw new SDIException( "taxonomy \"" + tax_str + "\" is not unique in species tree (using "
+ + res.getTaxCompBase() + " for linking to gene tree)" );
}
species_to_node_map.put( tax_str, s );
}
\r
public class GSDIR implements GSDII {\r
\r
- private final int _min_duplications_sum;\r
+ private final int _min_duplications_sum;\r
private final int _speciations_sum;\r
\r
- \r
@Override\r
public int getSpeciationsSum() {\r
return _speciations_sum;\r
}\r
-\r
private final BasicDescriptiveStatistics _duplications_sum_stats;\r
private final List<Phylogeny> _min_duplications_sum_gene_trees;\r
- \r
private final List<PhylogenyNode> _stripped_gene_tree_nodes;\r
private final List<PhylogenyNode> _stripped_species_tree_nodes;\r
private final Set<PhylogenyNode> _mapped_species_tree_nodes;\r
private final TaxonomyComparisonBase _tax_comp_base;\r
private final SortedSet<String> _scientific_names_mapped_to_reduced_specificity;\r
- \r
+\r
public GSDIR( final Phylogeny gene_tree,\r
final Phylogeny species_tree,\r
final boolean strip_gene_tree,\r
final boolean strip_species_tree ) throws SDIException {\r
- \r
final NodesLinkingResult nodes_linking_result = GSDI.linkNodesOfG( gene_tree,\r
species_tree,\r
null,\r
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() && n.isFirstChildNode() )*/) {\r
gene_tree_branches_post_order.add( new PhylogenyBranch( n, n.getParent() ) );\r
}\r
}\r
_min_duplications_sum_gene_trees = new ArrayList<Phylogeny>();\r
_duplications_sum_stats = new BasicDescriptiveStatistics();\r
for( final PhylogenyBranch branch : gene_tree_branches_post_order ) {\r
- \r
gene_tree.reRoot( branch );\r
PhylogenyMethods.preOrderReId( species_tree );\r
//TEST, remove later\r
final GSDIsummaryResult gsdi_result = GSDI.geneTreePostOrderTraversal( gene_tree, true );\r
if ( gsdi_result.getDuplicationsSum() < min_duplications_sum ) {\r
min_duplications_sum = gsdi_result.getDuplicationsSum();\r
- speciations_sum = gsdi_result.getSpeciationsSum();\r
+ speciations_sum = gsdi_result.getSpeciationsSum();\r
_min_duplications_sum_gene_trees.clear();\r
_min_duplications_sum_gene_trees.add( gene_tree.copy() );\r
//_speciations_sum\r
}\r
- else if ( gsdi_result.getDuplicationsSum()== min_duplications_sum ) {\r
+ else if ( gsdi_result.getDuplicationsSum() == min_duplications_sum ) {\r
_min_duplications_sum_gene_trees.add( gene_tree.copy() );\r
}\r
_duplications_sum_stats.addValue( gsdi_result.getDuplicationsSum() );\r
- \r
}\r
- _min_duplications_sum = min_duplications_sum; \r
- _speciations_sum = speciations_sum;\r
+ _min_duplications_sum = min_duplications_sum;\r
+ _speciations_sum = speciations_sum;\r
}\r
\r
public int getMinDuplicationsSum() {\r
}
}
- public final static TaxonomyComparisonBase determineTaxonomyComparisonBase( final Phylogeny gene_tree ) {
+ public final static TaxonomyComparisonBase determineTaxonomyComparisonBase( final Phylogeny gene_tree )
+ throws SDIException {
int with_id_count = 0;
int with_code_count = 0;
int with_sn_count = 0;
}
}
if ( max == 0 ) {
- throw new IllegalArgumentException( "gene tree has no taxonomic data" );
+ throw new SDIException( "gene tree has no taxonomic data" );
}
else if ( max == 1 ) {
- throw new IllegalArgumentException( "gene tree has only one node with taxonomic data" );
+ throw new SDIException( "gene tree has only one node with taxonomic data" );
}
else if ( max == with_id_count ) {
return TaxonomyComparisonBase.ID;
import org.forester.rio.TestRIO;
import org.forester.sdi.SDI;
import org.forester.sdi.SDIR;
-import org.forester.sdi.SDI;
import org.forester.sdi.TestGSDI;
import org.forester.sequence.BasicSequence;
import org.forester.sequence.Sequence;
for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
final PhylogenyNode node = iter.next();
}
+ final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
+ final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
+ if ( !iter.next().getName().equals( "A" ) ) {
+ return false;
+ }
+ if ( !iter.next().getName().equals( "B" ) ) {
+ return false;
+ }
+ if ( !iter.next().getName().equals( "C" ) ) {
+ return false;
+ }
+ if ( !iter.next().getName().equals( "D" ) ) {
+ return false;
+ }
+ if ( !iter.next().getName().equals( "E" ) ) {
+ return false;
+ }
+ if ( !iter.next().getName().equals( "F" ) ) {
+ return false;
+ }
+ if ( iter.hasNext() ) {
+ return false;
+ }
}
catch ( final Exception e ) {
e.printStackTrace( System.out );