From a1114eb8610e592961a40e5c3d46d647c02b5108 Mon Sep 17 00:00:00 2001 From: cmzmasek Date: Fri, 1 Nov 2013 20:12:36 +0000 Subject: [PATCH] in progress --- .../org/forester/archaeopteryx/Configuration.java | 5 + .../src/org/forester/archaeopteryx/MainFrame.java | 15 +- .../archaeopteryx/MainFrameApplication.java | 13 +- .../src/org/forester/archaeopteryx/Options.java | 11 ++ .../org/forester/archaeopteryx/TaxonomyUtil.java | 5 + .../src/org/forester/archaeopteryx/TreePanel.java | 49 ++++-- .../surfacing/PrintableDomainSimilarity.java | 140 ++++++++++++----- .../src/org/forester/surfacing/SurfacingUtil.java | 76 +++++----- .../java/src/org/forester/util/ForesterUtil.java | 159 +++++++++++++------- 9 files changed, 326 insertions(+), 147 deletions(-) diff --git a/forester/java/src/org/forester/archaeopteryx/Configuration.java b/forester/java/src/org/forester/archaeopteryx/Configuration.java index 5cfceac..d423ac1 100644 --- a/forester/java/src/org/forester/archaeopteryx/Configuration.java +++ b/forester/java/src/org/forester/archaeopteryx/Configuration.java @@ -1692,4 +1692,9 @@ public final class Configuration { public boolean isShowAnnotationRefSource() { return _show_annotation_ref_source; } + + public boolean isColorByTaxonomicGroup() { + + return false; + } } diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrame.java b/forester/java/src/org/forester/archaeopteryx/MainFrame.java index cc2c9eb..4e76d1f 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrame.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrame.java @@ -97,13 +97,14 @@ public abstract class MainFrame extends JFrame implements ActionListener { static final String SEARCH_CASE_SENSITIVE_LABEL = "Case Sensitive"; static final String INVERSE_SEARCH_RESULT_LABEL = "Negate Result"; static final String DISPLAY_BRANCH_LENGTH_VALUES_LABEL = "Display Branch Length Values"; + static final String COLOR_BY_TAXONOMIC_GROUP = "Color by Taxonomic Group"; static final String DISPLAY_SCALE_LABEL = "Display Scale"; static final String NON_LINED_UP_CLADOGRAMS_LABEL = "Non-Lined Up Cladograms"; static final String UNIFORM_CLADOGRAMS_LABEL = "Total Node Sum Dependent Cladograms"; static final String LABEL_DIRECTION_LABEL = "Radial Labels"; static final String LABEL_DIRECTION_TIP = "To use radial node labels in radial and unrooted display types"; static final String SCREEN_ANTIALIAS_LABEL = "Antialias"; - static final String COLOR_LABELS_LABEL = "Colorize Labels Same as Parent Branch"; + static final String COLOR_LABELS_LABEL = "Color Labels Same as Parent Branch"; static final String BG_GRAD_LABEL = "Background Color Gradient"; static final String DISPLAY_NODE_BOXES_LABEL_EXT = "Show External Node Shapes"; static final String DISPLAY_NODE_BOXES_LABEL_INT = "Show Internal Node Shapes"; @@ -176,6 +177,8 @@ public abstract class MainFrame extends JFrame implements ActionListener { JRadioButtonMenuItem _uniform_cladograms_rbmi; JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi; JCheckBoxMenuItem _show_branch_length_values_cbmi; + JCheckBoxMenuItem _color_by_taxonomic_group_cbmi; + JCheckBoxMenuItem _show_scale_cbmi; //TODO fix me JCheckBoxMenuItem _show_overview_cbmi; JCheckBoxMenuItem _show_domain_labels; @@ -437,6 +440,10 @@ public abstract class MainFrame extends JFrame implements ActionListener { else if ( o == _show_branch_length_values_cbmi ) { updateOptions( getOptions() ); } + else if ( o == _color_by_taxonomic_group_cbmi ) { + updateOptions( getOptions() ); + } + else if ( o == _show_confidence_stddev_cbmi ) { updateOptions( getOptions() ); } @@ -1304,6 +1311,12 @@ public abstract class MainFrame extends JFrame implements ActionListener { if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) { options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() ); } + + if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) { + options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() ); + } + + options.setPrintUsingActualSize( ( _print_using_actual_size_cbmi != null ) && ( _print_using_actual_size_cbmi.isSelected() ) ); options.setGraphicsExportUsingActualSize( ( _graphics_export_using_actual_size_cbmi != null ) diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index 8f65e7b..c01828e 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -888,13 +888,20 @@ public final class MainFrameApplication extends MainFrame { _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) ); _options_jmenu .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) ); - _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( SHOW_CONF_STDDEV_LABEL ) ); + + _options_jmenu .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_INT ) ); _options_jmenu .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_EXT ) ); + + _options_jmenu + .add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( COLOR_BY_TAXONOMIC_GROUP ) ); + _options_jmenu .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) ); + _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( SHOW_CONF_STDDEV_LABEL ) ); + _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) ); _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) ); _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) ); @@ -978,7 +985,9 @@ public final class MainFrameApplication extends MainFrame { customizeJMenuItem( _cycle_node_fill_mi ); customizeJMenuItem( _choose_node_size_mi ); customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() ); - customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() ); + customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() ); + + customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() ); customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() ); customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() ); customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() ); diff --git a/forester/java/src/org/forester/archaeopteryx/Options.java b/forester/java/src/org/forester/archaeopteryx/Options.java index ca216c8..34a225e 100644 --- a/forester/java/src/org/forester/archaeopteryx/Options.java +++ b/forester/java/src/org/forester/archaeopteryx/Options.java @@ -42,6 +42,7 @@ import org.forester.util.ForesterUtil; final public class Options { static final double MIN_CONFIDENCE_DEFAULT = 0.0; + private boolean _color_by_taxonomic_group; private boolean _show_branch_length_values; private boolean _internal_number_are_confidence_for_nh_parsing; private boolean _show_scale; @@ -257,6 +258,11 @@ final public class Options { return _show_branch_length_values; } + final boolean isColorByTaxonomicGroup() { + return _color_by_taxonomic_group; + } + + boolean isShowConfidenceStddev() { return _show_confidence_stddev; } @@ -399,6 +405,10 @@ final public class Options { _show_branch_length_values = show_branch_length_values; } + final void setColorByTaxonomicGroup( final boolean color_by_taxonomic_group ) { + _color_by_taxonomic_group = color_by_taxonomic_group; + } + void setShowConfidenceStddev( final boolean show_confidence_stddev ) { _show_confidence_stddev = show_confidence_stddev; } @@ -493,6 +503,7 @@ final public class Options { instance.setShowScale( configuration.isShowScale() ); instance.setShowBranchLengthValues( configuration.isShowBranchLengthValues() ); instance.setShowOverview( configuration.isShowOverview() ); + instance.setColorByTaxonomicGroup( configuration.isColorByTaxonomicGroup() ); instance.setCladogramType( configuration.getCladogramType() ); instance.setOvPlacement( configuration.getOvPlacement() ); instance.setPrintLineWidth( configuration.getPrintLineWidth() ); diff --git a/forester/java/src/org/forester/archaeopteryx/TaxonomyUtil.java b/forester/java/src/org/forester/archaeopteryx/TaxonomyUtil.java index d7090ad..d136c9d 100644 --- a/forester/java/src/org/forester/archaeopteryx/TaxonomyUtil.java +++ b/forester/java/src/org/forester/archaeopteryx/TaxonomyUtil.java @@ -6,6 +6,11 @@ import java.util.Map; final class TaxonomyUtil { + static String getTaxGroupByTaxCode( String code ) { + return _default_taxcode_taxgroup_map.get( code ); + } + + private final static Map _default_taxcode_taxgroup_map = new HashMap(); static { _default_taxcode_taxgroup_map.put( "HUMAN", "deuterostomia" ); diff --git a/forester/java/src/org/forester/archaeopteryx/TreePanel.java b/forester/java/src/org/forester/archaeopteryx/TreePanel.java index 88c4d66..ca479f6 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreePanel.java +++ b/forester/java/src/org/forester/archaeopteryx/TreePanel.java @@ -702,27 +702,46 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } final Color calculateTaxonomyBasedColor( final Taxonomy tax ) { - if ( ForesterUtil.isEmpty( tax.getTaxonomyCode() ) && ForesterUtil.isEmpty( tax.getScientificName() ) ) { + if ( getOptions().isColorByTaxonomicGroup() && !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) { + boolean ex = false; + String group = null; + try { + group =TaxonomyUtil.getTaxGroupByTaxCode( tax.getTaxonomyCode() ); + } + catch ( Exception e ) { + ex = true; + } + if ( !ex && !ForesterUtil.isEmpty( group ) ) { + Color c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( group ); + if ( c != null ) { + return c; + } + } return getTreeColorSet().getTaxonomyColor(); } - Color c = null; - if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) { - c = getControlPanel().getSpeciesColors().get( tax.getTaxonomyCode() ); - } - if ( ( c == null ) && !ForesterUtil.isEmpty( tax.getScientificName() ) ) { - c = getControlPanel().getSpeciesColors().get( tax.getScientificName() ); - } - if ( c == null ) { + else { + if ( ForesterUtil.isEmpty( tax.getTaxonomyCode() ) && ForesterUtil.isEmpty( tax.getScientificName() ) ) { + return getTreeColorSet().getTaxonomyColor(); + } + Color c = null; if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) { - c = TreePanelUtil.calculateColorFromString( tax.getTaxonomyCode(), true ); - getControlPanel().getSpeciesColors().put( tax.getTaxonomyCode(), c ); + c = getControlPanel().getSpeciesColors().get( tax.getTaxonomyCode() ); } - else { - c = TreePanelUtil.calculateColorFromString( tax.getScientificName(), true ); - getControlPanel().getSpeciesColors().put( tax.getScientificName(), c ); + if ( ( c == null ) && !ForesterUtil.isEmpty( tax.getScientificName() ) ) { + c = getControlPanel().getSpeciesColors().get( tax.getScientificName() ); + } + if ( c == null ) { + if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) { + c = TreePanelUtil.calculateColorFromString( tax.getTaxonomyCode(), true ); + getControlPanel().getSpeciesColors().put( tax.getTaxonomyCode(), c ); + } + else { + c = TreePanelUtil.calculateColorFromString( tax.getScientificName(), true ); + getControlPanel().getSpeciesColors().put( tax.getScientificName(), c ); + } } + return c; } - return c; } void checkForVectorProperties( final Phylogeny phy ) { diff --git a/forester/java/src/org/forester/surfacing/PrintableDomainSimilarity.java b/forester/java/src/org/forester/surfacing/PrintableDomainSimilarity.java index 63db3b2..2734a29 100644 --- a/forester/java/src/org/forester/surfacing/PrintableDomainSimilarity.java +++ b/forester/java/src/org/forester/surfacing/PrintableDomainSimilarity.java @@ -26,9 +26,13 @@ package org.forester.surfacing; +import java.awt.Color; +import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeMap; @@ -374,68 +378,111 @@ public class PrintableDomainSimilarity implements DomainSimilarity { return sb; } - - private StringBuffer getTaxonomyGroupDistribution( Phylogeny tol ) { //TODO work on me - - final SortedMap> m = new TreeMap>(); + final SortedMap> domain_to_species_set_map = new TreeMap>(); for( final Species species : getSpeciesData().keySet() ) { for( final String combable_dom : getCombinableDomainIds( species ) ) { - if ( !m.containsKey( combable_dom ) ) { - m.put( combable_dom, new TreeSet() ); + if ( !domain_to_species_set_map.containsKey( combable_dom ) ) { + domain_to_species_set_map.put( combable_dom, new HashSet() ); } - m.get( combable_dom ).add( species.getSpeciesId() ); + domain_to_species_set_map.get( combable_dom ).add( species.getSpeciesId() ); } } - Map countz = new HashMap(); - for( final Map.Entry> e : m.entrySet() ) { - for( final String tax_code : e.getValue() ) { - final String group = SurfacingUtil.obtainTaxonomyGroup( tax_code, tol ); + final StringBuffer sb = new StringBuffer(); + for( final Map.Entry> domain_to_species_set : domain_to_species_set_map.entrySet() ) { + final Map countz = new HashMap(); + final ValueComparator bvc = new ValueComparator( countz ); + final SortedMap sorted_countz = new TreeMap( bvc ); + for( final String tax_code : domain_to_species_set.getValue() ) { + final String group = SurfacingUtil.obtainTaxonomyGroup( tax_code, tol ); if ( !ForesterUtil.isEmpty( group ) ) { if ( !countz.containsKey( group ) ) { countz.put( group, 1 ); } else { - countz.put( group, countz.get( group) + 1 ); + countz.put( group, countz.get( group ) + 1 ); } - } else { return null; } - } - - } - final StringBuffer sb = new StringBuffer(); - - // i am just a template and need to be modified for "printout" TODO - for( final Map.Entry> e : m.entrySet() ) { - sb.append( "" + e.getKey() + "" ); + sorted_countz.putAll( countz ); + sb.append( "" + domain_to_species_set.getKey() + "" ); sb.append( ": " ); sb.append( "" ); - for( final String tax : e.getValue() ) { - final String hex = SurfacingUtil.obtainHexColorStringDependingOnTaxonomyGroup( tax, null ); - if ( !ForesterUtil.isEmpty( hex ) ) { - sb.append( "" ); - sb.append( tax ); - sb.append( "" ); - } - else { - sb.append( tax ); - } + for( final Map.Entry group_to_counts : sorted_countz.entrySet() ) { + final String group = group_to_counts.getKey(); + final Color c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( group ); + if ( c == null ) { + throw new IllegalArgumentException( "no color found for taxonomy group\"" + group + "\"" ); + } + final String hex = String.format( "#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue() ); + + sb.append( "" ); + sb.append( group ); + sb.append( ": " ); + sb.append( group_to_counts.getValue() ); + sb.append( "" ); sb.append( " " ); + sb.append( "
\n" ); } sb.append( "
" ); - sb.append( "
\n" ); + } + // i am just a template and need to be modified for "printout" TODO + // for( final Map.Entry> e : m.entrySet() ) { + // sb.append( "" + e.getKey() + "" ); + // sb.append( ": " ); + // sb.append( "" ); + // for( final String tax : e.getValue() ) { + // final String hex = SurfacingUtil.obtainHexColorStringDependingOnTaxonomyGroup( tax, null ); + // if ( !ForesterUtil.isEmpty( hex ) ) { + // sb.append( "" ); + // sb.append( tax ); + // sb.append( "" ); + // } + // else { + // sb.append( tax ); + // } + // sb.append( " " ); + // } + // sb.append( "" ); + // sb.append( "
\n" ); + // } return sb; } - - + + /* + public class Testing { + + public static void main(String[] args) { + + HashMap map = new HashMap(); + ValueComparator bvc = new ValueComparator(map); + TreeMap sorted_map = new TreeMap(bvc); + + map.put("A",99.5); + map.put("B",67.4); + map.put("C",67.4); + map.put("D",67.3); + + System.out.println("unsorted map: "+map); + + sorted_map.putAll(map); + + System.out.println("results: "+sorted_map); + } + } + + + + */ private StringBuffer getSpeciesDataInAlphabeticalOrder( final boolean html, final Map tax_code_to_id_map, final Phylogeny phy ) { @@ -527,12 +574,15 @@ public class PrintableDomainSimilarity implements DomainSimilarity { sb.append( "" ); sb.append( getSpeciesDataInAlphabeticalOrder( true, tax_code_to_id_map, phy ) ); sb.append( getDomainDataInAlphabeticalOrder() ); + sb.append( getTaxonomyGroupDistribution( phy ) ); sb.append( "" ); } else { sb.append( "" ); sb.append( getSpeciesDataInCustomOrder( true, tax_code_to_id_map, phy ) ); sb.append( getDomainDataInAlphabeticalOrder() ); + sb.append( getTaxonomyGroupDistribution( phy ) ); + sb.append( "" ); } sb.append( "" ); @@ -551,4 +601,22 @@ public class PrintableDomainSimilarity implements DomainSimilarity { public static enum PRINT_OPTION { HTML, SIMPLE_TAB_DELIMITED; } + + class ValueComparator implements Comparator { + + final private Map _base; + + public ValueComparator( final Map base ) { + _base = base; + } + + public int compare( final String a, final String b ) { + if ( _base.get( a ) >= _base.get( b ) ) { + return -1; + } + else { + return 1; + } // returning 0 would merge keys + } + } } diff --git a/forester/java/src/org/forester/surfacing/SurfacingUtil.java b/forester/java/src/org/forester/surfacing/SurfacingUtil.java index f9fb313..00ee155 100644 --- a/forester/java/src/org/forester/surfacing/SurfacingUtil.java +++ b/forester/java/src/org/forester/surfacing/SurfacingUtil.java @@ -1347,32 +1347,34 @@ public final class SurfacingUtil { throws IllegalArgumentException { if ( !_TAXCODE_HEXCOLORSTRING_MAP.containsKey( tax_code ) ) { if ( ( phy != null ) && !phy.isEmpty() ) { - final List nodes = phy.getNodesViaTaxonomyCode( tax_code ); - Color c = null; - if ( ( nodes == null ) || nodes.isEmpty() ) { - throw new IllegalArgumentException( "code " + tax_code + " is not found" ); - } - if ( nodes.size() != 1 ) { - throw new IllegalArgumentException( "code " + tax_code + " is not unique" ); - } - PhylogenyNode n = nodes.get( 0 ); - while ( n != null ) { - if ( n.getNodeData().isHasTaxonomy() - && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) { - c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getNodeData().getTaxonomy() - .getScientificName(), tax_code ); - } - if ( ( c == null ) && !ForesterUtil.isEmpty( n.getName() ) ) { - c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getName(), tax_code ); - } - if ( c != null ) { - break; - } - n = n.getParent(); - } +// final List nodes = phy.getNodesViaTaxonomyCode( tax_code ); +// Color c = null; +// if ( ( nodes == null ) || nodes.isEmpty() ) { +// throw new IllegalArgumentException( "code " + tax_code + " is not found" ); +// } +// if ( nodes.size() != 1 ) { +// throw new IllegalArgumentException( "code " + tax_code + " is not unique" ); +// } +// PhylogenyNode n = nodes.get( 0 ); +// while ( n != null ) { +// if ( n.getNodeData().isHasTaxonomy() +// && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) { +// c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getNodeData().getTaxonomy() +// .getScientificName(), tax_code ); +// } +// if ( ( c == null ) && !ForesterUtil.isEmpty( n.getName() ) ) { +// c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getName(), tax_code ); +// } +// if ( c != null ) { +// break; +// } +// n = n.getParent(); +// } + final String group = obtainTaxonomyGroup( tax_code, phy ); + Color c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( group ); if ( c == null ) { throw new IllegalArgumentException( "no color found for taxonomy code \"" + tax_code + "\"" ); - } + } final String hex = String.format( "#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue() ); _TAXCODE_HEXCOLORSTRING_MAP.put( tax_code, hex ); } @@ -1385,11 +1387,11 @@ public final class SurfacingUtil { } - public static String obtainTaxonomyGroup( final String tax_code, final Phylogeny phy ) + public static String obtainTaxonomyGroup( final String tax_code, final Phylogeny species_tree ) throws IllegalArgumentException { if ( !_TAXCODE_TAXGROUP_MAP.containsKey( tax_code ) ) { - if ( ( phy != null ) && !phy.isEmpty() ) { - final List nodes = phy.getNodesViaTaxonomyCode( tax_code ); + if ( ( species_tree != null ) && !species_tree.isEmpty() ) { + final List nodes = species_tree.getNodesViaTaxonomyCode( tax_code ); if ( ( nodes == null ) || nodes.isEmpty() ) { throw new IllegalArgumentException( "code " + tax_code + " is not found" ); @@ -1399,27 +1401,25 @@ public final class SurfacingUtil { } PhylogenyNode n = nodes.get( 0 ); String group = null; - Color c = null; + while ( n != null ) { if ( n.getNodeData().isHasTaxonomy() && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) { - c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getNodeData().getTaxonomy() - .getScientificName(), tax_code ); + group = ForesterUtil.obtainNormalizedTaxonomyGroup( n.getNodeData().getTaxonomy() + .getScientificName() ); - group = n.getNodeData().getTaxonomy() - .getScientificName(); } - if ( ( c == null ) && !ForesterUtil.isEmpty( n.getName() ) ) { - c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getName(), tax_code ); - group = n.getName(); + if ( ForesterUtil.isEmpty( group ) && !ForesterUtil.isEmpty( n.getName() ) ) { + group = ForesterUtil.obtainNormalizedTaxonomyGroup( n.getName() ); + } - if ( c != null ) { + if ( !ForesterUtil.isEmpty( group ) ) { break; } - group = null; + n = n.getParent(); } - if ( c == null ) { + if ( ForesterUtil.isEmpty( group ) ) { throw new IllegalArgumentException( "no group found for taxonomy code \"" + tax_code + "\"" ); } diff --git a/forester/java/src/org/forester/util/ForesterUtil.java b/forester/java/src/org/forester/util/ForesterUtil.java index eef965f..eb1ea8d 100644 --- a/forester/java/src/org/forester/util/ForesterUtil.java +++ b/forester/java/src/org/forester/util/ForesterUtil.java @@ -1204,111 +1204,160 @@ public final class ForesterUtil { System.exit( -1 ); } - public final static Color obtainColorDependingOnTaxonomyGroup( final String tax, final String tax_code ) { + public final static Color obtainColorDependingOnTaxonomyGroup( final String tax_group ) { + if ( !ForesterUtil.isEmpty( tax_group ) ) { + if ( tax_group.equals( "deuterostomia" ) ) { + return TaxonomyColors.DEUTEROSTOMIA_COLOR; + } + else if ( tax_group.equals( "protostomia" ) ) { + return TaxonomyColors.PROTOSTOMIA_COLOR; + } + else if ( tax_group.equals( "cnidaria" ) ) { + return TaxonomyColors.CNIDARIA_COLOR; + } + else if ( tax_group.equals( "placozoa" ) ) { + return TaxonomyColors.PLACOZOA_COLOR; + } + else if ( tax_group.equals( "ctenophora" ) ) { + return TaxonomyColors.CTENOPHORA_COLOR; + } + else if ( tax_group.equals( "porifera" ) ) { + return TaxonomyColors.PORIFERA_COLOR; + } + else if ( tax_group.equals( "choanoflagellida" ) ) { + return TaxonomyColors.CHOANOFLAGELLIDA; + } + else if ( tax_group.equals( "ichthyophonida & filasterea" ) ) { + return TaxonomyColors.ICHTHYOSPOREA_AND_FILASTEREA; + } + else if ( tax_group.equals( "dikarya" ) ) { + return TaxonomyColors.DIKARYA_COLOR; + } + else if ( tax_group.equalsIgnoreCase( "fungi" ) || tax_group.equalsIgnoreCase( "other fungi" ) ) { + return TaxonomyColors.OTHER_FUNGI_COLOR; + } + else if ( tax_group.equals( "nucleariidae and fonticula" ) ) { + return TaxonomyColors.NUCLEARIIDAE_AND_FONTICULA_GROUP_COLOR; + } + else if ( tax_group.equals( "amoebozoa" ) ) { + return TaxonomyColors.AMOEBOZOA_COLOR; + } + else if ( tax_group.equals( "embryophyta" ) ) { + return TaxonomyColors.EMBRYOPHYTA_COLOR; + } + else if ( tax_group.equals( "chlorophyta" ) ) { + return TaxonomyColors.CHLOROPHYTA_COLOR; + } + else if ( tax_group.equals( "rhodophyta" ) ) { + return TaxonomyColors.RHODOPHYTA_COLOR; + } + else if ( tax_group.equals( "hacrobia" ) ) { + return TaxonomyColors.HACROBIA_COLOR; + } + else if ( tax_group.equals( "glaucocystophyceae" ) ) { + return TaxonomyColors.GLAUCOPHYTA_COLOR; + } + else if ( tax_group.equals( "stramenopiles" ) ) { + return TaxonomyColors.STRAMENOPILES_COLOR; + } + else if ( tax_group.equals( "alveolata" ) ) { + return TaxonomyColors.ALVEOLATA_COLOR; + } + else if ( tax_group.equals( "rhizaria" ) ) { + return TaxonomyColors.RHIZARIA_COLOR; + } + else if ( tax_group.equals( "excavata" ) ) { + return TaxonomyColors.EXCAVATA_COLOR; + } + else if ( tax_group.equals( "apusozoa" ) ) { + return TaxonomyColors.APUSOZOA_COLOR; + } + else if ( tax_group.equals( "archaea" ) ) { + return TaxonomyColors.ARCHAEA_COLOR; + } + else if ( tax_group.equals( "bacteria" ) ) { + return TaxonomyColors.BACTERIA_COLOR; + } + } + return null; + } + + public final static String obtainNormalizedTaxonomyGroup( final String tax ) { if ( tax.equalsIgnoreCase( "deuterostomia" ) ) { - printRel( tax_code, "deuterostomia" ); - return TaxonomyColors.DEUTEROSTOMIA_COLOR; + return "deuterostomia"; } else if ( tax.equalsIgnoreCase( "protostomia" ) ) { - printRel( tax_code, "protostomia" ); - return TaxonomyColors.PROTOSTOMIA_COLOR; + return "protostomia"; } else if ( tax.equalsIgnoreCase( "cnidaria" ) ) { - printRel( tax_code, "cnidaria" ); - return TaxonomyColors.CNIDARIA_COLOR; + return "cnidaria"; } else if ( tax.toLowerCase().startsWith( "trichoplax" ) || tax.equalsIgnoreCase( "placozoa" ) ) { - printRel( tax_code, "placozoa" ); - return TaxonomyColors.PLACOZOA_COLOR; + return "placozoa"; } else if ( tax.toLowerCase().startsWith( "mnemiopsis" ) || tax.equalsIgnoreCase( "ctenophora" ) ) { - printRel( tax_code, "ctenophora" ); - return TaxonomyColors.CTENOPHORA_COLOR; + return "ctenophora"; } else if ( tax.toLowerCase().startsWith( "amphimedon" ) || tax.equalsIgnoreCase( "porifera" ) ) { - printRel( tax_code, "porifera" ); - return TaxonomyColors.PORIFERA_COLOR; + return "porifera"; } else if ( tax.equalsIgnoreCase( "codonosigidae" ) || tax.equalsIgnoreCase( "choanoflagellida" ) ) { - printRel( tax_code, "choanoflagellida" ); - return TaxonomyColors.CHOANOFLAGELLIDA; + return "choanoflagellida"; } else if ( tax.toLowerCase().startsWith( "ichthyophonida & filasterea" ) || tax.toLowerCase().startsWith( "ichthyophonida and filasterea" ) || tax.toLowerCase().startsWith( "ichthyosporea & filasterea" ) || tax.toLowerCase().startsWith( "ichthyosporea and filasterea" ) ) { - printRel( tax_code, "ichthyophonida & filasterea" ); - return TaxonomyColors.ICHTHYOSPOREA_AND_FILASTEREA; + return "ichthyophonida & filasterea"; } else if ( tax.equalsIgnoreCase( "dikarya" ) ) { - printRel( tax_code, "dikarya" ); - return TaxonomyColors.DIKARYA_COLOR; + return "dikarya"; } - else if ( tax.equalsIgnoreCase( "fungi" ) || tax.equalsIgnoreCase( "other fungi" ) ) { - printRel( tax_code, "other fungi" ); - return TaxonomyColors.OTHER_FUNGI_COLOR; + else if ( tax.equalsIgnoreCase( "other fungi" ) ) { + return "other fungi"; } else if ( tax.toLowerCase().startsWith( "nucleariidae and fonticula" ) ) { - printRel( tax_code, "nucleariidae and fonticula group" ); - return TaxonomyColors.NUCLEARIIDAE_AND_FONTICULA_GROUP_COLOR; + return "nucleariidae and fonticula group"; } else if ( tax.equalsIgnoreCase( "amoebozoa" ) ) { - printRel( tax_code, "amoebozoa" ); - return TaxonomyColors.AMOEBOZOA_COLOR; + return "amoebozoa"; } else if ( tax.equalsIgnoreCase( "embryophyta" ) ) { - printRel( tax_code, "embryophyta" ); - return TaxonomyColors.EMBRYOPHYTA_COLOR; + return "embryophyta"; } else if ( tax.equalsIgnoreCase( "chlorophyta" ) ) { - printRel( tax_code, "chlorophyta" ); - return TaxonomyColors.CHLOROPHYTA_COLOR; + return "chlorophyta"; } else if ( tax.equalsIgnoreCase( "rhodophyta" ) ) { - printRel( tax_code, "rhodophyta" ); - return TaxonomyColors.RHODOPHYTA_COLOR; + return "rhodophyta"; } else if ( tax.toLowerCase().startsWith( "hacrobia" ) ) { - printRel( tax_code, "hacrobia" ); - return TaxonomyColors.HACROBIA_COLOR; + return "hacrobia"; } else if ( tax.equalsIgnoreCase( "glaucocystophyceae" ) || tax.equalsIgnoreCase( "glaucophyta" ) ) { - printRel( tax_code, "glaucocystophyceae" ); - return TaxonomyColors.GLAUCOPHYTA_COLOR; + return "glaucocystophyceae"; } else if ( tax.equalsIgnoreCase( "stramenopiles" ) ) { - printRel( tax_code, "stramenopiles" ); - return TaxonomyColors.STRAMENOPILES_COLOR; + return "stramenopiles"; } else if ( tax.equalsIgnoreCase( "alveolata" ) ) { - printRel( tax_code, "alveolata" ); - return TaxonomyColors.ALVEOLATA_COLOR; + return "alveolata"; } else if ( tax.equalsIgnoreCase( "rhizaria" ) ) { - printRel( tax_code, "rhizaria" ); - return TaxonomyColors.RHIZARIA_COLOR; + return "rhizaria"; } else if ( tax.equalsIgnoreCase( "excavata" ) ) { - printRel( tax_code, "excavata" ); - return TaxonomyColors.EXCAVATA_COLOR; + return "excavata"; } else if ( tax.equalsIgnoreCase( "apusozoa" ) ) { - printRel( tax_code, "apusozoa" ); - return TaxonomyColors.APUSOZOA_COLOR; + return "apusozoa"; } else if ( tax.equalsIgnoreCase( "archaea" ) ) { - printRel( tax_code, "archaea" ); - return TaxonomyColors.ARCHAEA_COLOR; + return "archaea"; } else if ( tax.equalsIgnoreCase( "bacteria" ) ) { - printRel( tax_code, "bacteria" ); - return TaxonomyColors.BACTERIA_COLOR; + return "bacteria"; } return null; } - - private final static void printRel( final String tax_code, final String group ) { - //System.out.println( tax_code + "->" + group ); - //System.out.println( "_default_taxcode_taxgroup_map.put( \"" + tax_code + "\", \"" + group + "\" );" ); - } } -- 1.7.10.2