- final public static void collapseSpeciesSpecificSubtrees( final Phylogeny phy ) {
- boolean inferred = false;
- for( final PhylogenyNodeIterator it = phy.iteratorPreorder(); it.hasNext(); ) {
- final PhylogenyNode n = it.next();
- if ( !n.isExternal() && !n.isCollapse() && ( n.getNumberOfDescendants() > 1 ) ) {
- final Set<Taxonomy> taxs = PhylogenyMethods.obtainDistinctTaxonomies( n );
- if ( ( taxs != null ) && ( taxs.size() == 1 ) ) {
- AptxUtil.collapseSubtree( n, true );
- if ( !n.getNodeData().isHasTaxonomy() ) {
- n.getNodeData().setTaxonomy( ( Taxonomy ) n.getAllExternalDescendants().get( 0 ).getNodeData()
- .getTaxonomy().copy() );
- }
- inferred = true;
- }
- else {
- n.setCollapse( false );
- }
- }
- }
- if ( inferred ) {
- phy.setRerootable( false );
- }
- }
-
- final static void collapseSubtree( final PhylogenyNode node, final boolean collapse ) {
- node.setCollapse( collapse );
- if ( node.isExternal() ) {
- return;
- }
- final PhylogenyNodeIterator it = new PreorderTreeIterator( node );
- while ( it.hasNext() ) {
- it.next().setCollapse( collapse );
- }
- }
-
- final static void colorPhylogenyAccordingToConfidenceValues( final Phylogeny tree, final TreePanel tree_panel ) {
- double max_conf = 0.0;
- for( final PhylogenyNodeIterator it = tree.iteratorPreorder(); it.hasNext(); ) {
- final PhylogenyNode n = it.next();
- n.getBranchData().setBranchColor( null );
- if ( n.getBranchData().isHasConfidences() ) {
- final double conf = PhylogenyMethods.getConfidenceValue( n );
- if ( conf > max_conf ) {
- max_conf = conf;
- }
- }
- }
- if ( max_conf > 0.0 ) {
- final Color bg = tree_panel.getTreeColorSet().getBackgroundColor();
- final Color br = tree_panel.getTreeColorSet().getBranchColor();
- for( final PhylogenyNodeIterator it = tree.iteratorPreorder(); it.hasNext(); ) {
- final PhylogenyNode n = it.next();
- if ( n.getBranchData().isHasConfidences() ) {
- final double conf = PhylogenyMethods.getConfidenceValue( n );
- final BranchColor c = new BranchColor( ForesterUtil.calcColor( conf, 0.0, max_conf, bg, br ) );
- colorizeSubtree( n, c );
- }
- }
- }
- }
-
- final static int colorPhylogenyAccordingToRanks( final Phylogeny tree, final String rank, final TreePanel tree_panel ) {
- final Map<String, Color> true_lineage_to_color_map = new HashMap<String, Color>();
- int colorizations = 0;
- for( final PhylogenyNodeIterator it = tree.iteratorPostorder(); it.hasNext(); ) {
- final PhylogenyNode n = it.next();
- if ( n.getNodeData().isHasTaxonomy()
- && ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() )
- || !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getCommonName() ) || !ForesterUtil
- .isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) ) {
- if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getRank() )
- && n.getNodeData().getTaxonomy().getRank().equalsIgnoreCase( rank ) ) {
- final BranchColor c = new BranchColor( tree_panel.calculateTaxonomyBasedColor( n.getNodeData()
- .getTaxonomy() ) );
- colorizeSubtree( n, c );
- ++colorizations;
- if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
- true_lineage_to_color_map.put( n.getNodeData().getTaxonomy().getScientificName(), c.getValue() );
- }