further reduction of NHX fields
[jalview.git] / forester / java / src / org / forester / archaeopteryx / Configuration.java
index a7e9379..7b440a8 100644 (file)
@@ -24,7 +24,7 @@
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 //
 // Contact: phylosoft @ gmail . com
-// WWW: www.phylosoft.org/forester
+// WWW: https://sites.google.com/site/cmzmasek/home/software/forester
 
 package org.forester.archaeopteryx;
 
@@ -47,6 +47,7 @@ import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
 import org.forester.archaeopteryx.Options.OVERVIEW_PLACEMENT_TYPE;
 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
+import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
 import org.forester.phylogeny.data.NodeData.NODE_DATA;
 import org.forester.phylogeny.data.NodeVisualization;
 import org.forester.phylogeny.data.NodeVisualization.NodeFill;
@@ -55,6 +56,9 @@ import org.forester.util.ForesterUtil;
 
 public final class Configuration {
 
+    public enum EXT_NODE_DATA_RETURN_ON {
+        CONSOLE, WINODW, BUFFER_ONLY;
+    }
     static final String                     VALIDATE_AGAINST_PHYLOXML_XSD_SCHEMA                   = "validate_against_phyloxml_xsd_schema";
     private static final String             WEB_LINK_KEY                                           = "web_link";
     private static final String             DISPLAY_COLOR_KEY                                      = "display_color";
@@ -83,7 +87,7 @@ public final class Configuration {
     private short                           _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
     private boolean                         _editable                                              = true;
     private boolean                         _nh_parsing_replace_underscores                        = false;
-    private boolean                         _nh_parsing_extract_pfam_taxonomy_codes                = false;
+    private TAXONOMY_EXTRACTION             _taxonomy_extraction                                   = TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY;
     private boolean                         _internal_number_are_confidence_for_nh_parsing         = false;
     private boolean                         _display_sequence_relations                            = false;
     private boolean                         _validate_against_phyloxml_xsd_schema                  = Constants.VALIDATE_AGAINST_PHYLOXML_XSD_SCJEMA_DEFAULT;
@@ -147,6 +151,7 @@ public final class Configuration {
     final static int                        edit_node_data                                         = 14;
     final static int                        sort_descendents                                       = 15;
     final static int                        get_ext_desc_data                                      = 16;
+    final static int                        select_nodes                                           = 17;
     // ---------------------------
     // Display options for trees
     // ---------------------------
@@ -158,24 +163,25 @@ public final class Configuration {
     String                                  default_config_filename                                = Constants.DEFAULT_CONFIGURATION_FILE_NAME;
     final static String                     display_options[][]                                    = {
             { "Phylogram", "display", "?" }, { "Node Name", "display", "yes" }, { "Taxonomy Code", "display", "yes" },
-            { "Annotation", "nodisplay", "no" }, { "Confidence Values", "display", "?" }, { "Event", "display", "?" },
-            { "Taxonomy Colorize", "display", "no" }, { "Colorize Branches", "display", "no" },
-            { "Use Branch-Widths", "display", "no" }, { "Show Custom Nodes", "display", "yes" },
-            { "Domains", "nodisplay", "no" }, { "Binary Characters", "nodisplay", "no" },
-            { "Binary Char Counts", "nodisplay", "no" }, { "Prot/Gene Name", "display", "yes" },
-            { "Prot/Gene Acc", "display", "no" }, { "Show Internal Data", "display", "yes" },
-            { "Dyna Hide", "display", "yes" }, { "Taxonomy Scientific", "display", "yes" },
-            { "Taxonomy Common", "display", "no" }, { "Annotation Colorize", "nodisplay", "no" },
-            { "Prot/Gene Symbol", "display", "yes" }, { "Rollover", "display", "yes" },
-            { "Relation Confidence", "display", "no" }, { "Vector Data", "display", "no" },
-            { "Taxonomy Images", "display", "no" }, { "Properties", "display", "no" }             };
+            { "Annotation", "nodisplay", "no" }, { "Confidence Values", "display", "?" },
+            { "Node Events", "display", "?" }, { "Taxonomy Colorize", "display", "yes" },
+            { "Colorize Branches", "display", "no" }, { "Use Branch-Widths", "display", "no" },
+            { "Show Custom Nodes", "display", "yes" }, { "Domains", "nodisplay", "no" },
+            { "Binary Characters", "nodisplay", "no" }, { "Binary Char Counts", "nodisplay", "no" },
+            { "Seq Name", "display", "yes" }, { "Seq Acc", "display", "no" },
+            { "Show Internal Data", "display", "yes" }, { "Dyna Hide", "display", "yes" },
+            { "Taxonomy Scientific", "display", "yes" }, { "Taxonomy Common", "display", "no" },
+            { "Annotation Colorize", "nodisplay", "no" }, { "Seq Symbol", "display", "yes" },
+            { "Rollover", "display", "yes" }, { "Relation Confidence", "nodisplay", "no" },
+            { "Vector Data", "nodisplay", "no" }, { "Taxonomy Images", "display", "no" },
+            { "Properties", "nodisplay", "no" }                                                   };
     final static String                     clickto_options[][]                                    = {
             { "Display Node Data", "display" }, { "Collapse/Uncollapse", "display" }, { "Root/Reroot", "display" },
             { "Sub/Super Tree", "display" }, { "Swap Descendants", "display" }, { "Colorize Subtree", "display" },
             { "Open Sequence Web", "display" }, { "Open Taxonomy Web", "display" }, { "Blast", "display" },
             { "Cut Subtree", "display" }, { "Copy Subtree", "display" }, { "Paste Subtree", "display" },
             { "Delete Subtree/Node", "display" }, { "Add New Node", "display" }, { "Edit Node Data", "display" },
-            { "Sort Descendants", "display" }, { "Get External Node Data", "display" }            };
+            { "Sort Descendants", "display" }, { "Return", "display" }, { "Select Node(s)", "display" } };
     // This option is selected in the dropdown
     int                                     default_clickto                                        = Configuration.display_node_data;
     // --------------
@@ -210,8 +216,11 @@ public final class Configuration {
     private Color                           _gui_button_border_color                               = Constants.BUTTON_BORDER_COLOR_DEFAULT;
     private Color                           _domain_structure_font_color                           = Constants.DOMAIN_STRUCTURE_FONT_COLOR_DEFAULT;
     private Color                           _domain_structure_base_color                           = Constants.DOMAIN_STRUCTURE_BASE_COLOR_DEFAULT;
-    private NODE_DATA                       _ext_desc_data_to_return;
-    private String _label_for_get_ext_descendents_data = "";
+    private NODE_DATA                       _ext_desc_data_to_return                               = NODE_DATA.UNKNOWN;
+    private String                          _label_for_get_ext_descendents_data                    = "";
+    private EXT_NODE_DATA_RETURN_ON         _ext_node_data_return_on                               = EXT_NODE_DATA_RETURN_ON.WINODW;
+    private int                             _frame_x_size;
+    private int                             _frame_y_size;
     private static String                   DEFAULT_FONT_FAMILY                                    = "";
     static {
         for( final String font_name : Constants.DEFAULT_FONT_CHOICES ) {
@@ -411,6 +420,9 @@ public final class Configuration {
         else if ( name.equals( "edit_node_data" ) ) {
             index = Configuration.edit_node_data;
         }
+        else if ( name.equals( "select_nodes" ) ) {
+            index = Configuration.select_nodes;
+        }
         else if ( name.equals( "display_node_popup" ) ) {
             ForesterUtil.printWarningMessage( Constants.PRG_NAME,
                                               "configuration key [display_node_popup] is deprecated" );
@@ -621,8 +633,8 @@ public final class Configuration {
         return _editable;
     }
 
-    boolean isExtractPfamTaxonomyCodesInNhParsing() {
-        return _nh_parsing_extract_pfam_taxonomy_codes;
+    final TAXONOMY_EXTRACTION getTaxonomyExtraction() {
+        return _taxonomy_extraction;
     }
 
     boolean isHasWebLink( final String source ) {
@@ -705,7 +717,7 @@ public final class Configuration {
     private double parseDouble( final String str ) {
         double d = 0.0;
         try {
-            d = Double.parseDouble( str );
+            d = Double.parseDouble( str.trim() );
         }
         catch ( final Exception e ) {
             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse double from [" + str + "]" );
@@ -717,7 +729,7 @@ public final class Configuration {
     private float parseFloat( final String str ) {
         float f = 0.0f;
         try {
-            f = Float.parseFloat( str );
+            f = Float.parseFloat( str.trim() );
         }
         catch ( final Exception e ) {
             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse float from [" + str + "]" );
@@ -729,7 +741,7 @@ public final class Configuration {
     private int parseInt( final String str ) {
         int i = -1;
         try {
-            i = Integer.parseInt( str );
+            i = Integer.parseInt( str.trim() );
         }
         catch ( final Exception e ) {
             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse integer from [" + str + "]" );
@@ -741,7 +753,7 @@ public final class Configuration {
     private short parseShort( final String str ) {
         short i = -1;
         try {
-            i = Short.parseShort( str );
+            i = Short.parseShort( str.trim() );
         }
         catch ( final Exception e ) {
             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse short from [" + str + "]" );
@@ -916,8 +928,8 @@ public final class Configuration {
         _editable = editable;
     }
 
-    public void setExtractPfamTaxonomyCodesInNhParsing( final boolean nh_parsing_extract_pfam_taxonomy_codes ) {
-        _nh_parsing_extract_pfam_taxonomy_codes = nh_parsing_extract_pfam_taxonomy_codes;
+    final void setTaxonomyExtraction( final TAXONOMY_EXTRACTION taxonomy_extraction ) {
+        _taxonomy_extraction = taxonomy_extraction;
     }
 
     private void setGraphicsExportX( final int graphics_export_x ) {
@@ -936,10 +948,10 @@ public final class Configuration {
      * Set a key-value(s) tuple
      */
     private void setKeyValue( final StringTokenizer st ) {
-        String key = ( String ) st.nextElement();
-        key = key.replace( ':', ' ' );
-        key = key.trim();
-        key = key.toLowerCase();
+        final String key = ( ( String ) st.nextElement() ).replace( ':', ' ' ).trim().toLowerCase();
+        if ( !st.hasMoreElements() ) {
+            return;
+        }
         // Handle single value settings first:
         if ( key.equals( "default_click_to" ) ) {
             final String clickto_name = ( String ) st.nextElement();
@@ -1019,17 +1031,23 @@ public final class Configuration {
         else if ( key.equals( "font_size" ) ) {
             final String size_str = ( ( String ) st.nextElement() ).trim();
             final int i = parseInt( size_str );
-            setBaseFontSize( i );
+            if ( i > 0 ) {
+                setBaseFontSize( i );
+            }
         }
         else if ( key.equals( "graphics_export_x" ) ) {
             final String str = ( ( String ) st.nextElement() ).trim();
             final int i = parseInt( str );
-            setGraphicsExportX( i );
+            if ( i > 0 ) {
+                setGraphicsExportX( i );
+            }
         }
         else if ( key.equals( "graphics_export_y" ) ) {
             final String str = ( ( String ) st.nextElement() ).trim();
             final int i = parseInt( str );
-            setGraphicsExportY( i );
+            if ( i > 0 ) {
+                setGraphicsExportY( i );
+            }
         }
         else if ( key.equals( "pdf_export_line_width" ) ) {
             final String str = ( ( String ) st.nextElement() ).trim();
@@ -1042,6 +1060,20 @@ public final class Configuration {
                                                   "value for [pdf_export_line_width] cannot be zero or negative" );
             }
         }
+        else if ( key.equals( "window_initial_size_x" ) ) {
+            final String str = ( ( String ) st.nextElement() ).trim();
+            final int i = parseInt( str );
+            if ( i > 0 ) {
+                setFrameXSize( i );
+            }
+        }
+        else if ( key.equals( "window_initial_size_y" ) ) {
+            final String str = ( ( String ) st.nextElement() ).trim();
+            final int i = parseInt( str );
+            if ( i > 0 ) {
+                setFrameYSize( i );
+            }
+        }
         else if ( key.equals( "default_number_of_bootstrap_resamples" ) ) {
             final String str = ( ( String ) st.nextElement() ).trim();
             final int i = parseInt( str );
@@ -1127,11 +1159,11 @@ public final class Configuration {
             _use_tabbed_display = parseBoolean( ( String ) st.nextElement() );
         }
         else if ( key.equals( "overview_width" ) ) {
-            final short i = parseShort( ( ( String ) st.nextElement() ).trim() );
+            final short i = parseShort( ( ( String ) st.nextElement() ) );
             setOvMaxWidth( i );
         }
         else if ( key.equals( "overview_height" ) ) {
-            final short i = parseShort( ( ( String ) st.nextElement() ).trim() );
+            final short i = parseShort( ( ( String ) st.nextElement() ) );
             setOvMaxHeight( i );
         }
         else if ( key.equals( "overview_placement_type" ) ) {
@@ -1196,7 +1228,7 @@ public final class Configuration {
         }
         else if ( key.equals( "replace_underscores_in_nh_parsing" ) ) {
             final boolean r = parseBoolean( ( String ) st.nextElement() );
-            if ( r && isExtractPfamTaxonomyCodesInNhParsing() ) {
+            if ( r && ( getTaxonomyExtraction() != TAXONOMY_EXTRACTION.NO ) ) {
                 ForesterUtil
                         .printWarningMessage( Constants.PRG_NAME,
                                               "attempt to extract taxonomies and replace underscores at the same time" );
@@ -1205,16 +1237,26 @@ public final class Configuration {
                 setReplaceUnderscoresInNhParsing( r );
             }
         }
-        else if ( key.equals( "extract_taxonomy_codes_in_nh_parsing" ) ) {
-            final boolean e = parseBoolean( ( String ) st.nextElement() );
-            if ( e && isReplaceUnderscoresInNhParsing() ) {
+        else if ( key.equals( "taxonomy_extraction_in_nh_parsing" ) ) {
+            final String s = ( String ) st.nextElement();
+            if ( s.equalsIgnoreCase( "no" ) ) {
+                setTaxonomyExtraction( TAXONOMY_EXTRACTION.NO );
+            }
+            else if ( s.equalsIgnoreCase( "yes" ) ) {
+                setTaxonomyExtraction( TAXONOMY_EXTRACTION.YES );
+            }
+            else if ( s.equalsIgnoreCase( "pfam" ) ) {
+                setTaxonomyExtraction( TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
+            }
+            else {
+                ForesterUtil.printWarningMessage( Constants.PRG_NAME,
+                                                  "unknown value for \"taxonomy_extraction_in_nh_parsing\": " + s );
+            }
+            if ( ( getTaxonomyExtraction() != TAXONOMY_EXTRACTION.NO ) && isReplaceUnderscoresInNhParsing() ) {
                 ForesterUtil
                         .printWarningMessage( Constants.PRG_NAME,
                                               "attempt to extract taxonomies and replace underscores at the same time" );
             }
-            else {
-                setExtractPfamTaxonomyCodesInNhParsing( e );
-            }
         }
         else if ( key.equals( "internal_labels_are_confidence_values" ) ) {
             setInternalNumberAreConfidenceForNhParsing( parseBoolean( ( String ) st.nextElement() ) );
@@ -1305,13 +1347,45 @@ public final class Configuration {
             else if ( s.equalsIgnoreCase( "sequence_symbol" ) ) {
                 setExtDescNodeDataToReturn( NODE_DATA.SEQUENCE_SYMBOL );
             }
+            else if ( s.equalsIgnoreCase( "taxonomy_scientific_name" ) ) {
+                setExtDescNodeDataToReturn( NODE_DATA.TAXONOMY_SCIENTIFIC_NAME );
+            }
+            else if ( s.equalsIgnoreCase( "taxonomy_code" ) ) {
+                setExtDescNodeDataToReturn( NODE_DATA.TAXONOMY_CODE );
+            }
+            else if ( s.equalsIgnoreCase( "user_selected" ) ) {
+                setExtDescNodeDataToReturn( NODE_DATA.UNKNOWN );
+            }
             else {
                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + s
                         + "] for [ext_descendents_data_to_return]" );
             }
         }
         else if ( key.equals( "label_for_get_ext_descendents_data" ) ) {
-           setLabelForGetExtDescendentsData( (( String ) st.nextElement() ).replaceAll( "_", " " ) );
+            final String s = ( ( String ) st.nextElement() ).trim();
+            if ( ForesterUtil.isEmpty( s ) || ( s.length() < 2 ) ) {
+                ForesterUtil.printWarningMessage( Constants.PRG_NAME, "illegal value [" + s
+                        + "] for [label_for_get_ext_descendents_data]" );
+            }
+            else {
+                setLabelForGetExtDescendentsData( s.replaceAll( "_", " " ) );
+            }
+        }
+        else if ( key.equals( "ext_descendents_data_to_return_on" ) ) {
+            final String s = ( ( String ) st.nextElement() ).trim().toLowerCase();
+            if ( s.equals( "console" ) ) {
+                setExtNodeDataReturnOn( EXT_NODE_DATA_RETURN_ON.CONSOLE );
+            }
+            else if ( s.equals( "window" ) ) {
+                setExtNodeDataReturnOn( EXT_NODE_DATA_RETURN_ON.WINODW );
+            }
+            else if ( s.equals( "buffer_only" ) ) {
+                setExtNodeDataReturnOn( EXT_NODE_DATA_RETURN_ON.BUFFER_ONLY );
+            }
+            else {
+                ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + s
+                        + "] for [ext_descendents_data_to_return_on]" );
+            }
         }
         else if ( st.countTokens() >= 2 ) { // counts the tokens that are not
             // yet retrieved!
@@ -1510,16 +1584,14 @@ public final class Configuration {
         }
     }
 
-    private void setLabelForGetExtDescendentsData( String label_for_get_ext_descendents_data ) {
+    private void setLabelForGetExtDescendentsData( final String label_for_get_ext_descendents_data ) {
         _label_for_get_ext_descendents_data = label_for_get_ext_descendents_data;
-       
     }
 
-    public String getLabelForGetExtDescendentsData( ) {
-        return _label_for_get_ext_descendents_data ;
-       
+    public String getLabelForGetExtDescendentsData() {
+        return _label_for_get_ext_descendents_data;
     }
-    
+
     public void setMinConfidenceValue( final double min_confidence_value ) {
         _min_confidence_value = min_confidence_value;
     }
@@ -1619,4 +1691,28 @@ public final class Configuration {
     public void setExtDescNodeDataToReturn( final NODE_DATA ext_desc_data_to_return ) {
         _ext_desc_data_to_return = ext_desc_data_to_return;
     }
+
+    public EXT_NODE_DATA_RETURN_ON getExtNodeDataReturnOn() {
+        return _ext_node_data_return_on;
+    }
+
+    private void setExtNodeDataReturnOn( final EXT_NODE_DATA_RETURN_ON ext_node_data_return_on ) {
+        _ext_node_data_return_on = ext_node_data_return_on;
+    }
+
+    public int getFrameXSize() {
+        return _frame_x_size;
+    }
+
+    public int getFrameYSize() {
+        return _frame_y_size;
+    }
+
+    public void setFrameXSize( final int frame_x_size ) {
+        _frame_x_size = frame_x_size;
+    }
+
+    public void setFrameYSize( final int frame_y_size ) {
+        _frame_y_size = frame_y_size;
+    }
 }