From 9794a064aff842558c2afd65c884127f33b2fd5e Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Fri, 8 Jun 2012 17:01:13 +0000 Subject: [PATCH] phylotastic hackathon at NESCENT 120608 --- .../src/org/forester/phylogeny/PhylogenyNode.java | 42 +++++++++++++++++--- forester/java/src/org/forester/sdi/GSDI.java | 38 ++++++++++-------- 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/forester/java/src/org/forester/phylogeny/PhylogenyNode.java b/forester/java/src/org/forester/phylogeny/PhylogenyNode.java index 71dec09..4045537 100644 --- a/forester/java/src/org/forester/phylogeny/PhylogenyNode.java +++ b/forester/java/src/org/forester/phylogeny/PhylogenyNode.java @@ -1051,15 +1051,45 @@ public final class PhylogenyNode implements PhylogenyNodeI, Comparable to_delete = new HashSet(); - 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 ); + stripGeneTree( speciestree_ext_nodes ); + if ( ( _gene_tree == null ) || ( _gene_tree.getNumberOfExternalNodes() < 2 ) ) { + throw new IllegalArgumentException( "species tree does not contain any" + + " nodes matching species in the gene tree" ); } } // Retrieve the reference to the PhylogenyNode with a matching species. @@ -307,6 +295,24 @@ public final class GSDI extends SDI { } } + private final void stripGeneTree( final HashMap speciestree_ext_nodes ) { + final Set to_delete = new HashSet(); + 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 ) { + to_delete.add( g ); + } + } + for( final PhylogenyNode n : to_delete ) { + _gene_tree.deleteSubtree( n, true ); + System.out.println( "deleted node from gene tree: " + n ); + } + } + @Override public final String toString() { final StringBuffer sb = new StringBuffer(); -- 1.7.10.2