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();
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 ) {
_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;
}
return _background_color_gradient;
}
+ final boolean isColorByTaxonomicGroup() {
+ return _color_by_taxonomic_group;
+ }
+
final boolean isColorLabelsSameAsParentBranch() {
return _color_labels_same_as_parent_branch;
}
return _show_branch_length_values;
}
- final boolean isColorByTaxonomicGroup() {
- return _color_by_taxonomic_group;
- }
-
boolean isShowConfidenceStddev() {
return _show_confidence_stddev;
}
_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;
}
_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;
}
if ( configuration.getExtDescNodeDataToReturn() != null ) {
instance.setExtDescNodeDataToReturn( configuration.getExtDescNodeDataToReturn() );
}
+ instance.setAllowErrorsInDistanceToParent( false );
}
return instance;
}
}
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 {
}
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;
return toString().replaceAll( " ", "_" );
}
}
-
- public boolean isAllowFontSizeChange() {
- return true;
- }
}
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;
}
_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." );
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 );
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" );
}
}
- 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 ) {
--_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 );
}
parseNHX( _current_anotation.toString(),
_current_node.getLastChildNode(),
getTaxonomyExtraction(),
- isReplaceUnderscores() );
+ isReplaceUnderscores(),
+ isAllowErrorsInDistanceToParent() );
_current_anotation = new StringBuilder();
}
if ( !_current_node.isRoot() ) {
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" );
}
parseNHX( _current_anotation.toString(),
_current_node.getLastChildNode(),
getTaxonomyExtraction(),
- isReplaceUnderscores() );
+ isReplaceUnderscores(),
+ isAllowErrorsInDistanceToParent() );
}
_current_anotation = new StringBuilder();
_saw_closing_paren = false;
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" );
}
}
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() ) {
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 ) {
}
}
- 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;
}
}