import java.util.Date;
import java.util.List;
-import org.forester.archaeopteryx.Archaeopteryx;
+
import org.forester.io.parsers.PhylogenyParser;
import org.forester.io.parsers.phyloxml.PhyloXmlParser;
import org.forester.io.parsers.util.ParserUtils;
final static private String HELP_OPTION_2 = "h";
final static private String DEFAULT_OUTFILE = "gsdi_out.phylo.xml";
final static private String PRG_NAME = "gsdi";
- final static private String PRG_VERSION = "0.4";
- final static private String PRG_DATE = "120607";
+ final static private String PRG_VERSION = "0.5";
+ final static private String PRG_DATE = "120608";
final static private String PRG_DESC = "general speciation duplication inference";
final static private String E_MAIL = "phylosoft@gmail.com";
final static private String WWW = "www.phylosoft.org/forester";
System.out.println( "Using GSDI algorithm" );
System.out.println();
System.out.println( "Use most parsimonous duplication model: " + most_parsimonous_duplication_model );
- sdi = new GSDI( gene_tree, species_tree, most_parsimonous_duplication_model );
+ sdi = new GSDI( gene_tree, species_tree, most_parsimonous_duplication_model, true );
}
}
catch ( final Exception e ) {
System.out.println( " phyloXML (Newick, NHX, Nexus)" );
System.out.println();
System.out.println( "Species tree:" );
- System.out.println( " In phyloXML format (unless option " + gsdi.GUESS_FORMAT_OF_SPECIES_TREE
+ System.out.println( " In phyloXML format (unless option -" + gsdi.GUESS_FORMAT_OF_SPECIES_TREE
+ " is used), with taxonomy data in appropriate fields" );
System.out.println();
System.out.println( "Gene tree:" );
package org.forester.sdi;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyNode;
private final HashMap<PhylogenyNode, Integer> _transversal_counts;
private final boolean _most_parsimonious_duplication_model;
+ private final boolean _strip_gene_tree;
private int _speciation_or_duplication_events_sum;
private int _speciations_sum;
*/
public GSDI( final Phylogeny gene_tree,
final Phylogeny species_tree,
- final boolean most_parsimonious_duplication_model ) {
+ final boolean most_parsimonious_duplication_model,
+ final boolean strip_gene_tree ) {
super( gene_tree, species_tree );
_speciation_or_duplication_events_sum = 0;
_speciations_sum = 0;
_most_parsimonious_duplication_model = most_parsimonious_duplication_model;
_transversal_counts = new HashMap<PhylogenyNode, Integer>();
_duplications_sum = 0;
+ _strip_gene_tree = strip_gene_tree;
getSpeciesTree().preOrderReId();
linkNodesOfG();
geneTreePostOrderTraversal( getGeneTree().getRoot() );
}
+ public GSDI( final Phylogeny gene_tree,
+ final Phylogeny species_tree,
+ final boolean most_parsimonious_duplication_model ) {
+ this( gene_tree, species_tree, most_parsimonious_duplication_model, false );
+ }
+
private final Event createDuplicationEvent() {
final Event event = Event.createSingleDuplicationEvent();
++_duplications_sum;
*
*/
@Override
- final void linkNodesOfG() {
+ final void linkNodesOfG() {
final HashMap<Taxonomy, PhylogenyNode> speciestree_ext_nodes = new HashMap<Taxonomy, PhylogenyNode>();
for( final PhylogenyNodeIterator iter = _species_tree.iteratorLevelOrder(); iter.hasNext(); ) {
final PhylogenyNode n = iter.next();
speciestree_ext_nodes.put( n.getNodeData().getTaxonomy(), n );
}
}
- // Retrieve the reference to the PhylogenyNode with a matching species
- // name.
+ if ( _strip_gene_tree ) {
+ final Set<PhylogenyNode> to_delete = new HashSet<PhylogenyNode>();
+ for( final PhylogenyNodeIterator iter = _gene_tree.iteratorExternalForward(); iter.hasNext(); ) {
+ final PhylogenyNode g = iter.next();
+ if ( !g.getNodeData().isHasTaxonomy() ) {
+ throw new IllegalArgumentException( "gene tree node " + g + " has no taxonomic data" );
+ }
+ final PhylogenyNode s = speciestree_ext_nodes.get( g.getNodeData().getTaxonomy() );
+ if ( s == null ) {
+ // throw new IllegalArgumentException( "species " + g.getNodeData().getTaxonomy()
+ // + " not present in species tree" );
+ to_delete.add( g );
+ }
+ }
+ for( final PhylogenyNode n : to_delete ) {
+ _gene_tree.deleteSubtree( n, true );
+ System.out.println( "deleted" + n );
+ }
+ }
+ // Retrieve the reference to the PhylogenyNode with a matching species.
for( final PhylogenyNodeIterator iter = _gene_tree.iteratorExternalForward(); iter.hasNext(); ) {
final PhylogenyNode g = iter.next();
if ( !g.getNodeData().isHasTaxonomy() ) {
throw new IllegalArgumentException( "species " + g.getNodeData().getTaxonomy()
+ " not present in species tree" );
}
-
-
g.setLink( s );
}
}