@Override
final public String toString() {
- final StringBuilder sb = new StringBuilder();
- if ( !ForesterUtil.isEmpty( getName() ) ) {
+ StringBuilder sb = new StringBuilder();
+ if ( ForesterUtil.isEmpty( getName() ) ) {
sb.append( getName() );
sb.append( " " );
}
- sb.append( "[" );
- sb.append( getId() );
- sb.append( "]" );
- return sb.toString();
+ if ( getNodeData().isHasTaxonomy() ) {
+ if ( !ForesterUtil.isEmpty( getNodeData().getTaxonomy().getScientificName() ) ) {
+ sb.append( getNodeData().getTaxonomy().getScientificName() );
+ sb.append( " " );
+ }
+ else if ( !ForesterUtil.isEmpty( getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
+ sb.append( getNodeData().getTaxonomy().getTaxonomyCode() );
+ sb.append( " " );
+ }
+ else if ( getNodeData().getTaxonomy().getIdentifier() != null ) {
+ sb.append( getNodeData().getTaxonomy().getIdentifier().toString() );
+ sb.append( " " );
+ }
+ }
+ if ( getNodeData().isHasSequence() ) {
+ if ( !ForesterUtil.isEmpty( getNodeData().getSequence().getName() ) ) {
+ sb.append( getNodeData().getSequence().getName() );
+ sb.append( " " );
+ }
+ else if ( !ForesterUtil.isEmpty( getNodeData().getSequence().getSymbol() ) ) {
+ sb.append( getNodeData().getSequence().getSymbol() );
+ sb.append( " " );
+ }
+ else if ( getNodeData().getSequence().getAccession() != null ) {
+ sb.append( getNodeData().getTaxonomy().getIdentifier().toString() );
+ sb.append( " " );
+ }
+ }
+ if ( sb.length() <= 1 ) {
+ sb.append( "[" );
+ sb.append( getId() );
+ sb.append( "]" );
+ }
+ return sb.toString().trim();
}
/**
}
}
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 );
+ 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.
}
}
+ private final void stripGeneTree( final HashMap<Taxonomy, PhylogenyNode> speciestree_ext_nodes ) {
+ 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 ) {
+ 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();