inprogress
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Mon, 24 Feb 2014 21:14:45 +0000 (21:14 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Mon, 24 Feb 2014 21:14:45 +0000 (21:14 +0000)
forester/java/src/org/forester/archaeopteryx/MainFrame.java
forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java
forester/java/src/org/forester/archaeopteryx/Options.java
forester/java/src/org/forester/io/parsers/nhx/NHXParser.java
forester/java/src/org/forester/phylogeny/PhylogenyNode.java

index fc6bb32..6248f6d 100644 (file)
@@ -208,6 +208,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     JRadioButtonMenuItem        _extract_taxonomy_pfam_strict_rbmi;
     JRadioButtonMenuItem        _extract_taxonomy_pfam_relaxed_rbmi;
     JCheckBoxMenuItem           _replace_underscores_cbmi;
+    JCheckBoxMenuItem           _allow_errors_in_distance_to_parent_cbmi;
     JCheckBoxMenuItem           _use_brackets_for_conf_in_nh_export_cbmi;
     JCheckBoxMenuItem           _use_internal_names_for_conf_in_nh_export_cbmi;
     // _  search
@@ -1344,6 +1345,8 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         }
         options.setReplaceUnderscoresInNhParsing( ( _replace_underscores_cbmi != null )
                 && _replace_underscores_cbmi.isSelected() );
+        options.setAllowErrorsInDistanceToParent( ( _allow_errors_in_distance_to_parent_cbmi != null )
+                && _allow_errors_in_distance_to_parent_cbmi.isSelected() );
         options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
                 && _search_whole_words_only_cbmi.isSelected() );
         options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
index 218160f..a4cf12a 100644 (file)
@@ -531,6 +531,9 @@ public final class MainFrameApplication extends MainFrame {
                 }
                 updateOptions( getOptions() );
             }
+            else if ( o == _allow_errors_in_distance_to_parent_cbmi ) {
+                updateOptions( getOptions() );
+            }
             else if ( o == _collapse_below_threshold ) {
                 if ( isSubtreeDisplayed() ) {
                     return;
@@ -937,6 +940,8 @@ public final class MainFrameApplication extends MainFrame {
         _options_jmenu
                 .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Node Names are Confidence Values" ) );
         _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );
+        _options_jmenu
+                .add( _allow_errors_in_distance_to_parent_cbmi = new JCheckBoxMenuItem( "Ignore Distance Value Format Errors" ) );
         //
         _options_jmenu.add( _extract_taxonomy_no_rbmi = new JRadioButtonMenuItem( "No Taxonomy Extraction" ) );
         _options_jmenu
@@ -1009,6 +1014,8 @@ public final class MainFrameApplication extends MainFrame {
         customizeRadioButtonMenuItem( _extract_taxonomy_agressive_rbmi,
                                       getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.AGGRESSIVE );
         customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
+        customizeCheckBoxMenuItem( _allow_errors_in_distance_to_parent_cbmi, getOptions()
+                .isReplaceUnderscoresInNhParsing() );
         customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
         customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
         customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
@@ -2338,6 +2345,7 @@ public final class MainFrameApplication extends MainFrame {
     private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
         nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
         nhx.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() );
+        nhx.setAllowErrorsInDistanceToParent( getOptions().isAllowErrorsInDistanceToParent() );
     }
 
     private void writeAllToFile() {
index a4c15b3..ec63ca6 100644 (file)
@@ -42,48 +42,49 @@ 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;
-    private boolean                           _show_overview;
-    private boolean                           _antialias_screen;
+    private boolean                           _abbreviate_scientific_names;
+    private boolean                           _allow_errors_in_distance_to_parent;
     private boolean                           _antialias_print;
+    private boolean                           _antialias_screen;
+    private boolean                           _background_color_gradient;
+    private Font                              _base_font;
+    private CLADOGRAM_TYPE                    _cladogram_type;
+    private boolean                           _color_by_taxonomic_group;
+    private boolean                           _color_labels_same_as_parent_branch;
+    private NodeVisualization.NodeFill        _default_node_fill;
+    private NodeVisualization.NodeShape       _default_node_shape;
+    private short                             _default_node_shape_size;
+    private boolean                           _editable;
+    private NODE_DATA                         _ext_desc_data_to_return;
+    private boolean                           _graphics_export_using_actual_size;
     private boolean                           _graphics_export_visible_only;
-    private int                               _print_size_x;
-    private int                               _print_size_y;
+    private boolean                           _internal_number_are_confidence_for_nh_parsing;
+    private boolean                           _inverse_search_result;
+    private boolean                           _match_whole_terms_only;
     private double                            _min_confidence_value;
-    private boolean                           _print_black_and_white;
-    private boolean                           _print_using_actual_size;
-    private boolean                           _graphics_export_using_actual_size;
-    private PHYLOGENY_GRAPHICS_TYPE           _phylogeny_graphics_type;
-    private CLADOGRAM_TYPE                    _cladogram_type;
-    private OVERVIEW_PLACEMENT_TYPE           _ov_placement;
+    private NH_CONVERSION_SUPPORT_VALUE_STYLE _nh_conversion_support_value_style;
+    private boolean                           _nh_parsing_replace_underscores;
     private NODE_LABEL_DIRECTION              _node_label_direction;
-    private Font                              _base_font;
-    private boolean                           _match_whole_terms_only;
-    private boolean                           _search_case_sensitive;
+    private short                             _number_of_digits_after_comma_for_branch_length_values;
+    private short                             _number_of_digits_after_comma_for_confidence_values;
+    private OVERVIEW_PLACEMENT_TYPE           _ov_placement;
+    private PHYLOGENY_GRAPHICS_TYPE           _phylogeny_graphics_type;
+    private boolean                           _print_black_and_white;
     private float                             _print_line_width;
-    private boolean                           _inverse_search_result;
+    private int                               _print_size_x;
+    private int                               _print_size_y;
+    private boolean                           _print_using_actual_size;
     private double                            _scale_bar_length;
-    private short                             _number_of_digits_after_comma_for_confidence_values;
-    private short                             _number_of_digits_after_comma_for_branch_length_values;
-    private boolean                           _nh_parsing_replace_underscores;
-    private TAXONOMY_EXTRACTION               _taxonomy_extraction;
-    private boolean                           _editable;
-    private boolean                           _background_color_gradient;
-    private boolean                           _show_domain_labels;
+    private boolean                           _search_case_sensitive;
     private boolean                           _show_annotation_ref_source;
-    private boolean                           _color_labels_same_as_parent_branch;
-    private boolean                           _abbreviate_scientific_names;
-    private NodeVisualization.NodeShape       _default_node_shape;
-    private NodeVisualization.NodeFill        _default_node_fill;
-    private short                             _default_node_shape_size;
-    private boolean                           _show_default_node_shapes_internal;
-    private boolean                           _show_default_node_shapes_external;
+    private boolean                           _show_branch_length_values;
     private boolean                           _show_confidence_stddev;
-    private NH_CONVERSION_SUPPORT_VALUE_STYLE _nh_conversion_support_value_style;
-    private NODE_DATA                         _ext_desc_data_to_return;
+    private boolean                           _show_default_node_shapes_external;
+    private boolean                           _show_default_node_shapes_internal;
+    private boolean                           _show_domain_labels;
+    private boolean                           _show_overview;
+    private boolean                           _show_scale;
+    private TAXONOMY_EXTRACTION               _taxonomy_extraction;
 
     private Options() {
         init();
@@ -93,16 +94,24 @@ final public class Options {
         return _ext_desc_data_to_return;
     }
 
-    public final boolean isShowDomainLabels() {
-        return _show_domain_labels;
+    public boolean isAllowErrorsInDistanceToParent() {
+        return _allow_errors_in_distance_to_parent;
+    }
+
+    public boolean isAllowFontSizeChange() {
+        return true;
     }
 
     public final boolean isShowAnnotationRefSource() {
         return _show_annotation_ref_source;
     }
 
-    public final void setShowAnnotationRefSource( final boolean show_annotation_ref_source ) {
-        _show_annotation_ref_source = show_annotation_ref_source;
+    public final boolean isShowDomainLabels() {
+        return _show_domain_labels;
+    }
+
+    public final void setAllowErrorsInDistanceToParent( final boolean allow_errors_in_distance_to_parent ) {
+        _allow_errors_in_distance_to_parent = allow_errors_in_distance_to_parent;
     }
 
     public void setBackgroundColorGradient( final boolean background_color_gradient ) {
@@ -117,6 +126,10 @@ final public class Options {
         _ext_desc_data_to_return = ext_desc_data_to_return;
     }
 
+    public final void setShowAnnotationRefSource( final boolean show_annotation_ref_source ) {
+        _show_annotation_ref_source = show_annotation_ref_source;
+    }
+
     public void setShowDomainLabels( final boolean show_domain_labels ) {
         _show_domain_labels = show_domain_labels;
     }
@@ -209,6 +222,10 @@ final public class Options {
         return _background_color_gradient;
     }
 
+    final boolean isColorByTaxonomicGroup() {
+        return _color_by_taxonomic_group;
+    }
+
     final boolean isColorLabelsSameAsParentBranch() {
         return _color_labels_same_as_parent_branch;
     }
@@ -257,10 +274,6 @@ final public class Options {
         return _show_branch_length_values;
     }
 
-    final boolean isColorByTaxonomicGroup() {
-        return _color_by_taxonomic_group;
-    }
-
     boolean isShowConfidenceStddev() {
         return _show_confidence_stddev;
     }
@@ -301,6 +314,10 @@ final public class Options {
         _cladogram_type = cladogram_type;
     }
 
+    final void setColorByTaxonomicGroup( final boolean color_by_taxonomic_group ) {
+        _color_by_taxonomic_group = color_by_taxonomic_group;
+    }
+
     final void setDefaultNodeFill( final NodeFill default_node_fill ) {
         _default_node_fill = default_node_fill;
     }
@@ -399,10 +416,6 @@ 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;
     }
@@ -548,6 +561,7 @@ final public class Options {
             if ( configuration.getExtDescNodeDataToReturn() != null ) {
                 instance.setExtDescNodeDataToReturn( configuration.getExtDescNodeDataToReturn() );
             }
+            instance.setAllowErrorsInDistanceToParent( false );
         }
         return instance;
     }
@@ -557,7 +571,7 @@ final public class Options {
     }
 
     public static enum CLADOGRAM_TYPE {
-        NON_LINED_UP, EXT_NODE_SUM_DEP, TOTAL_NODE_SUM_DEP;
+        EXT_NODE_SUM_DEP, NON_LINED_UP, TOTAL_NODE_SUM_DEP;
     }
 
     public static enum NODE_LABEL_DIRECTION {
@@ -565,14 +579,14 @@ final public class Options {
     }
 
     public static enum PHYLOGENY_GRAPHICS_TYPE {
-        RECTANGULAR, TRIANGULAR, EURO_STYLE, ROUNDED, CONVEX, CURVED, UNROOTED, CIRCULAR;
+        CIRCULAR, CONVEX, CURVED, EURO_STYLE, RECTANGULAR, ROUNDED, TRIANGULAR, UNROOTED;
     }
 
     static enum OVERVIEW_PLACEMENT_TYPE {
-        UPPER_LEFT( "upper left" ),
-        UPPER_RIGHT( "upper right" ),
         LOWER_LEFT( "lower left" ),
-        LOWER_RIGHT( "lower right" );
+        LOWER_RIGHT( "lower right" ),
+        UPPER_LEFT( "upper left" ),
+        UPPER_RIGHT( "upper right" );
 
         private final String _name;
 
@@ -589,8 +603,4 @@ final public class Options {
             return toString().replaceAll( " ", "_" );
         }
     }
-
-    public boolean isAllowFontSizeChange() {
-        return true;
-    }
 }
index 2ee184e..f87160f 100644 (file)
@@ -56,51 +56,62 @@ import org.forester.util.ForesterUtil;
 
 public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParser {
 
-    public static final TAXONOMY_EXTRACTION TAXONOMY_EXTRACTION_DEFAULT = TAXONOMY_EXTRACTION.NO;
-    public final static Pattern             NUMBERS_ONLY_PATTERN        = Pattern.compile( "^[0-9\\.]+$" );
-    public final static Pattern             MB_PROB_PATTERN             = Pattern.compile( "prob=([^,]+)" );
-    public final static Pattern             MB_PROB_SD_PATTERN          = Pattern.compile( "prob_stddev=([^,]+)" );
-    public final static Pattern             MB_BL_PATTERN               = Pattern.compile( "length_median=([^,]+)" );
-    final static private boolean            GUESS_ROOTEDNESS_DEFAULT    = true;
-    final static private boolean            GUESS_IF_SUPPORT_VALUES     = true;
-    final static private boolean            IGNORE_QUOTES_DEFAULT       = false;
-    final static public boolean             REPLACE_UNDERSCORES_DEFAULT = false;
-    final static private byte               STRING                      = 0;
-    final static private byte               STRING_BUFFER               = 1;
-    final static private byte               CHAR_ARRAY                  = 2;
-    final static private byte               BUFFERED_READER             = 3;
-    final static private byte               STRING_BUILDER              = 4;
+    public final static Pattern             MB_BL_PATTERN                              = Pattern
+                                                                                               .compile( "length_median=([^,]+)" );
+    public final static Pattern             MB_PROB_PATTERN                            = Pattern
+                                                                                               .compile( "prob=([^,]+)" );
+    public final static Pattern             MB_PROB_SD_PATTERN                         = Pattern
+                                                                                               .compile( "prob_stddev=([^,]+)" );
+    public final static Pattern             NUMBERS_ONLY_PATTERN                       = Pattern
+                                                                                               .compile( "^[0-9\\.]+$" );
+    final static public boolean             REPLACE_UNDERSCORES_DEFAULT                = false;
+    public static final TAXONOMY_EXTRACTION TAXONOMY_EXTRACTION_DEFAULT                = TAXONOMY_EXTRACTION.NO;
+    private static final boolean            ALLOW_ERRORS_IN_DISTANCE_TO_PARENT_DEFAULT = false;
+    final static private byte               BUFFERED_READER                            = 3;
+    final static private byte               CHAR_ARRAY                                 = 2;
+    final static private boolean            GUESS_IF_SUPPORT_VALUES                    = true;
+    final static private boolean            GUESS_ROOTEDNESS_DEFAULT                   = true;
+    final static private boolean            IGNORE_QUOTES_DEFAULT                      = false;
+    final static private byte               STRING                                     = 0;
+    final static private byte               STRING_BUFFER                              = 1;
+    final static private byte               STRING_BUILDER                             = 4;
+    private boolean                         _allow_errors_in_distance_to_parent;
+    private int                             _clade_level;
+    private StringBuilder                   _current_anotation;
+    private PhylogenyNode                   _current_node;
+    private Phylogeny                       _current_phylogeny;
     private boolean                         _guess_rootedness;
+    private int                             _i;
     private boolean                         _ignore_quotes;
+    private boolean                         _in_comment                                = false;
+    private boolean                         _in_double_quote                           = false;
+    private boolean                         _in_open_bracket                           = false;
+    private boolean                         _in_single_quote                           = false;
     private byte                            _input_type;
-    private int                             _source_length;
-    private PhylogenyNode                   _current_node;
-    private StringBuilder                   _current_anotation;
+    private BufferedReader                  _my_source_br                              = null;
+    private char[]                          _my_source_charary                         = null;
+    private StringBuffer                    _my_source_sbuff                           = null;
+    private StringBuilder                   _my_source_sbuil                           = null;
+    private String                          _my_source_str                             = null;
+    private Phylogeny                       _next;
     private Object                          _nhx_source;
-    private int                             _clade_level;
-    private Phylogeny                       _current_phylogeny;
-    private TAXONOMY_EXTRACTION             _taxonomy_extraction;
     private boolean                         _replace_underscores;
-    private boolean                         _in_comment                 = false;
-    private boolean                         _saw_colon                  = false;
     private boolean                         _saw_closing_paren;
-    private boolean                         _saw_open_bracket           = false;
-    private boolean                         _in_open_bracket            = false;
-    private boolean                         _in_double_quote            = false;
-    private boolean                         _in_single_quote            = false;
-    private String                          _my_source_str              = null;
-    private StringBuffer                    _my_source_sbuff            = null;
-    private StringBuilder                   _my_source_sbuil            = null;
-    private char[]                          _my_source_charary          = null;
-    private BufferedReader                  _my_source_br               = null;
-    private int                             _i;
-    private Phylogeny                       _next;
+    private boolean                         _saw_colon                                 = false;
+    private boolean                         _saw_open_bracket                          = false;
     private Object                          _source;
+    private int                             _source_length;
+    private TAXONOMY_EXTRACTION             _taxonomy_extraction;
 
     public NHXParser() {
         init();
     }
 
+    @Override
+    public String getName() {
+        return "NN/NHX Parser";
+    }
+
     public final TAXONOMY_EXTRACTION getTaxonomyExtraction() {
         return _taxonomy_extraction;
     }
@@ -200,6 +211,10 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse
         _taxonomy_extraction = taxonomy_extraction;
     }
 
+    public final void setAllowErrorsInDistanceToParent( final boolean allow_errors_in_distance_to_parent ) {
+        _allow_errors_in_distance_to_parent = allow_errors_in_distance_to_parent;
+    }
+
     private final void determineSourceType( final Object nhx_source ) throws IOException {
         if ( nhx_source == null ) {
             throw new PhylogenyParserException( getClass() + ": attempt to parse null object." );
@@ -285,7 +300,8 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse
             parseNHX( _current_anotation != null ? _current_anotation.toString() : "",
                       _current_phylogeny.getRoot(),
                       getTaxonomyExtraction(),
-                      isReplaceUnderscores() );
+                      isReplaceUnderscores(),
+                      isAllowErrorsInDistanceToParent() );
             if ( GUESS_IF_SUPPORT_VALUES ) {
                 if ( isBranchLengthsLikeBootstrapValues( _current_phylogeny ) ) {
                     moveBranchLengthsToConfidenceValues( _current_phylogeny );
@@ -306,12 +322,40 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse
     private final Phylogeny finishSingleNodePhylogeny() throws PhylogenyParserException, NHXFormatException,
             PhyloXmlDataFormatException {
         final PhylogenyNode new_node = new PhylogenyNode();
-        parseNHX( _current_anotation.toString(), new_node, getTaxonomyExtraction(), isReplaceUnderscores() );
+        parseNHX( _current_anotation.toString(),
+                  new_node,
+                  getTaxonomyExtraction(),
+                  isReplaceUnderscores(),
+                  isAllowErrorsInDistanceToParent() );
         _current_phylogeny = new Phylogeny();
         _current_phylogeny.setRoot( new_node );
         return _current_phylogeny;
     }
 
+    private final void init() {
+        setTaxonomyExtraction( TAXONOMY_EXTRACTION_DEFAULT );
+        setReplaceUnderscores( REPLACE_UNDERSCORES_DEFAULT );
+        setGuessRootedness( GUESS_ROOTEDNESS_DEFAULT );
+        setIgnoreQuotes( IGNORE_QUOTES_DEFAULT );
+        setAllowErrorsInDistanceToParent( ALLOW_ERRORS_IN_DISTANCE_TO_PARENT_DEFAULT );
+    }
+
+    private final boolean isAllowErrorsInDistanceToParent() {
+        return _allow_errors_in_distance_to_parent;
+    }
+
+    private final boolean isGuessRootedness() {
+        return _guess_rootedness;
+    }
+
+    private final boolean isIgnoreQuotes() {
+        return _ignore_quotes;
+    }
+
+    private final boolean isReplaceUnderscores() {
+        return _replace_underscores;
+    }
+
     private final void parseNext() throws IOException, NHXFormatException {
         if ( _source == null ) {
             throw new IOException( "source is not set" );
@@ -454,25 +498,6 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse
         }
     }
 
-    private final void init() {
-        setTaxonomyExtraction( TAXONOMY_EXTRACTION_DEFAULT );
-        setReplaceUnderscores( REPLACE_UNDERSCORES_DEFAULT );
-        setGuessRootedness( GUESS_ROOTEDNESS_DEFAULT );
-        setIgnoreQuotes( IGNORE_QUOTES_DEFAULT );
-    }
-
-    private final boolean isGuessRootedness() {
-        return _guess_rootedness;
-    }
-
-    private final boolean isIgnoreQuotes() {
-        return _ignore_quotes;
-    }
-
-    private final boolean isReplaceUnderscores() {
-        return _replace_underscores;
-    }
-
     private final void processCloseParen() throws PhylogenyParserException, NHXFormatException,
             PhyloXmlDataFormatException {
         if ( _clade_level < 0 ) {
@@ -481,7 +506,11 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse
         --_clade_level;
         if ( !_saw_closing_paren ) {
             final PhylogenyNode new_node = new PhylogenyNode();
-            parseNHX( _current_anotation.toString(), new_node, getTaxonomyExtraction(), isReplaceUnderscores() );
+            parseNHX( _current_anotation.toString(),
+                      new_node,
+                      getTaxonomyExtraction(),
+                      isReplaceUnderscores(),
+                      isAllowErrorsInDistanceToParent() );
             _current_anotation = new StringBuilder();
             _current_node.addAsChild( new_node );
         }
@@ -489,7 +518,8 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse
             parseNHX( _current_anotation.toString(),
                       _current_node.getLastChildNode(),
                       getTaxonomyExtraction(),
-                      isReplaceUnderscores() );
+                      isReplaceUnderscores(),
+                      isAllowErrorsInDistanceToParent() );
             _current_anotation = new StringBuilder();
         }
         if ( !_current_node.isRoot() ) {
@@ -501,7 +531,11 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse
     private final void processComma() throws PhylogenyParserException, NHXFormatException, PhyloXmlDataFormatException {
         if ( !_saw_closing_paren ) {
             final PhylogenyNode new_node = new PhylogenyNode();
-            parseNHX( _current_anotation.toString(), new_node, getTaxonomyExtraction(), isReplaceUnderscores() );
+            parseNHX( _current_anotation.toString(),
+                      new_node,
+                      getTaxonomyExtraction(),
+                      isReplaceUnderscores(),
+                      isAllowErrorsInDistanceToParent() );
             if ( _current_node == null ) {
                 throw new NHXFormatException( "format might not be NH or NHX" );
             }
@@ -511,7 +545,8 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse
             parseNHX( _current_anotation.toString(),
                       _current_node.getLastChildNode(),
                       getTaxonomyExtraction(),
-                      isReplaceUnderscores() );
+                      isReplaceUnderscores(),
+                      isAllowErrorsInDistanceToParent() );
         }
         _current_anotation = new StringBuilder();
         _saw_closing_paren = false;
@@ -539,10 +574,21 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse
         return phy;
     }
 
+    public final static NHXParser createInstance( final Object nhx_source ) throws NHXFormatException, IOException {
+        final NHXParser parser = new NHXParser();
+        parser.setSource( nhx_source );
+        return parser;
+    }
+
+    public final static Phylogeny[] parse( final Object nhx_source ) throws NHXFormatException, IOException {
+        return NHXParser.createInstance( nhx_source ).parse();
+    }
+
     public final static void parseNHX( String s,
                                        final PhylogenyNode node_to_annotate,
                                        final TAXONOMY_EXTRACTION taxonomy_extraction,
-                                       final boolean replace_underscores ) throws NHXFormatException,
+                                       final boolean replace_underscores,
+                                       final boolean allow_errors_in_distance_to_parent ) throws NHXFormatException,
             PhyloXmlDataFormatException {
         if ( ( taxonomy_extraction != TAXONOMY_EXTRACTION.NO ) && replace_underscores ) {
             throw new IllegalArgumentException( "cannot extract taxonomies and replace under scores at the same time" );
@@ -610,7 +656,7 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse
                         }
                     }
                     else if ( s.startsWith( NHXtags.SUPPORT ) ) {
-                        PhylogenyMethods.setConfidence( node_to_annotate, doubleValue( s.substring( 2 ) ) );
+                        PhylogenyMethods.setConfidence( node_to_annotate, doubleValue( s.substring( 2 ), false ) );
                     }
                     else if ( s.startsWith( NHXtags.TAXONOMY_ID ) ) {
                         if ( !node_to_annotate.getNodeData().isHasTaxonomy() ) {
@@ -636,21 +682,24 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse
                             throw new NHXFormatException( "error in NHX formatted data: more than one distance to parent:"
                                     + "\"" + s + "\"" );
                         }
-                        node_to_annotate.setDistanceToParent( doubleValue( s ) );
+                        node_to_annotate.setDistanceToParent( doubleValue( s, allow_errors_in_distance_to_parent ) );
                     }
                 } // while ( t.hasMoreTokens() ) 
             }
         }
     }
 
-    private final static double doubleValue( final String str ) throws NHXFormatException {
+    private final static double doubleValue( final String str, final boolean allow_errors ) throws NHXFormatException {
         try {
             return Double.valueOf( str ).doubleValue();
         }
         catch ( final NumberFormatException ex ) {
-            throw new NHXFormatException( "error in NH/NHX formatted data: failed to parse number from " + "\"" + str
-                    + "\"" );
+            if ( !allow_errors ) {
+                throw new NHXFormatException( "error in NH/NHX formatted data: failed to parse number from " + "\""
+                        + str + "\"" );
+            }
         }
+        return 0.0;
     }
 
     private final static boolean isBranchLengthsLikeBootstrapValues( final Phylogeny p ) {
@@ -725,22 +774,7 @@ public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParse
         }
     }
 
-    public final static NHXParser createInstance( final Object nhx_source ) throws NHXFormatException, IOException {
-        final NHXParser parser = new NHXParser();
-        parser.setSource( nhx_source );
-        return parser;
-    }
-
-    public final static Phylogeny[] parse( final Object nhx_source ) throws NHXFormatException, IOException {
-        return NHXParser.createInstance( nhx_source ).parse();
-    }
-
-    @Override
-    public String getName() {
-        return "NN/NHX Parser";
-    }
-
     public static enum TAXONOMY_EXTRACTION {
-        NO, PFAM_STYLE_RELAXED, PFAM_STYLE_STRICT, AGGRESSIVE;
+        AGGRESSIVE, NO, PFAM_STYLE_RELAXED, PFAM_STYLE_STRICT;
     }
 }
index 6b180ca..d17fd41 100644 (file)
@@ -86,7 +86,7 @@ public final class PhylogenyNode implements Comparable<PhylogenyNode> {
     private PhylogenyNode( final String nhx,
                            final NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction,
                            final boolean replace_underscores ) throws NHXFormatException, PhyloXmlDataFormatException {
-        NHXParser.parseNHX( nhx, this, taxonomy_extraction, replace_underscores );
+        NHXParser.parseNHX( nhx, this, taxonomy_extraction, replace_underscores, false );
         setId( PhylogenyNode.getNodeCount() );
         PhylogenyNode.increaseNodeCount();
         setSumExtNodes( 1 ); // For ext node, this number is 1 (not 0!!).