- }
- for( final PhylogenyNodeIterator it = tree.iteratorPostorder(); it.hasNext(); ) {
- final PhylogenyNode node = it.next();
- if ( ( node.getBranchData().getBranchColor() == null ) && node.getNodeData().isHasTaxonomy()
- && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getLineage() ) ) {
- boolean success = false;
- if ( !true_lineage_to_color_map.isEmpty() ) {
- for( final String lin : node.getNodeData().getTaxonomy().getLineage() ) {
- if ( true_lineage_to_color_map.containsKey( lin ) ) {
- colorizeSubtree( node, new BranchColor( true_lineage_to_color_map.get( lin ) ) );
- ++colorizations;
- success = true;
- break;
- }
- }
- }
- if ( !success ) {
- final Map<String, String> lineage_to_rank_map = MainPanel.getLineageToRankMap();
- for( final String lin : node.getNodeData().getTaxonomy().getLineage() ) {
- final Taxonomy temp_tax = new Taxonomy();
- temp_tax.setScientificName( lin );
- if ( lineage_to_rank_map.containsKey( lin )
- && !ForesterUtil.isEmpty( lineage_to_rank_map.get( lin ) )
- && lineage_to_rank_map.get( lin ).equalsIgnoreCase( rank ) ) {
- final BranchColor c = new BranchColor( tree_panel.calculateTaxonomyBasedColor( temp_tax ) );
- colorizeSubtree( node, c );
- ++colorizations;
- true_lineage_to_color_map.put( lin, c.getValue() );
- break;
- }
- else {
- UniProtTaxonomy up = null;
- try {
- up = TaxonomyDataObtainer.obtainUniProtTaxonomy( temp_tax, null, null );
- }
- catch ( final Exception e ) {
- e.printStackTrace();
- }
- if ( ( up != null ) && !ForesterUtil.isEmpty( up.getRank() ) ) {
- lineage_to_rank_map.put( lin, up.getRank() );
- if ( up.getRank().equalsIgnoreCase( rank ) ) {
- final BranchColor c = new BranchColor( tree_panel.calculateTaxonomyBasedColor( temp_tax ) );
- colorizeSubtree( node, c );
- ++colorizations;
- true_lineage_to_color_map.put( lin, c.getValue() );
- break;
- }
- }
- }
- }
- }
- }
- }
- return colorizations;
- }
-
- private static void colorizeSubtree( final PhylogenyNode node, final BranchColor c ) {
- node.getBranchData().setBranchColor( c );
- final List<PhylogenyNode> descs = PhylogenyMethods.getAllDescendants( node );
- for( final PhylogenyNode desc : descs ) {
- desc.getBranchData().setBranchColor( c );
- }
- }
-
- final static String[] getAllRanks( final Phylogeny tree ) {
- final SortedSet<String> ranks = new TreeSet<String>();
- for( final PhylogenyNodeIterator it = tree.iteratorPreorder(); it.hasNext(); ) {
- final PhylogenyNode n = it.next();
- if ( n.getNodeData().isHasTaxonomy() && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getRank() ) ) {
- ranks.add( n.getNodeData().getTaxonomy().getRank() );
- }
- }
- return ForesterUtil.stringSetToArray( ranks );
- }
-
- public static String[] getAllPossibleRanks() {
- final String[] str_array = new String[ PhyloXmlUtil.TAXONOMY_RANKS_LIST.size() - 2 ];
- int i = 0;
- for( final String e : PhyloXmlUtil.TAXONOMY_RANKS_LIST ) {
- if ( !e.equals( PhyloXmlUtil.UNKNOWN ) && !e.equals( PhyloXmlUtil.OTHER ) ) {
- str_array[ i++ ] = e;
- }
- }
- return str_array;
- }
-
- final static void colorPhylogenyAccordingToExternalTaxonomy( final Phylogeny tree, final TreePanel tree_panel ) {
- for( final PhylogenyNodeIterator it = tree.iteratorPreorder(); it.hasNext(); ) {
- it.next().getBranchData().setBranchColor( null );
- }
- for( final PhylogenyNodeIterator it = tree.iteratorPreorder(); it.hasNext(); ) {
- final PhylogenyNode n = it.next();
- if ( !n.getBranchData().isHasBranchColor() ) {
- final Taxonomy tax = PhylogenyMethods.getExternalDescendantsTaxonomy( n );
- if ( tax != null ) {
- n.getBranchData().setBranchColor( new BranchColor( tree_panel.calculateTaxonomyBasedColor( tax ) ) );
- final List<PhylogenyNode> descs = PhylogenyMethods.getAllDescendants( n );
- for( final PhylogenyNode desc : descs ) {
- desc.getBranchData()
- .setBranchColor( new BranchColor( tree_panel.calculateTaxonomyBasedColor( tax ) ) );
- }
- }
- }
- }
- }
-
- final static String createBasicInformation( final Phylogeny phy ) {
- final StringBuilder desc = new StringBuilder();
- if ( ( phy != null ) && !phy.isEmpty() ) {