2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2013 Christian M. Zmasek
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Lesser General Public License for more details.
17 // You should have received a copy of the GNU Lesser General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 // Contact: phylosoft @ gmail . com
22 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
24 package org.forester.io.parsers.nhx;
26 import java.io.BufferedReader;
27 import java.io.ByteArrayInputStream;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.io.InputStreamReader;
34 import java.util.ArrayList;
35 import java.util.List;
36 import java.util.StringTokenizer;
37 import java.util.regex.Matcher;
38 import java.util.regex.Pattern;
40 import org.forester.io.parsers.IteratingPhylogenyParser;
41 import org.forester.io.parsers.PhylogenyParser;
42 import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;
43 import org.forester.io.parsers.util.ParserUtils;
44 import org.forester.io.parsers.util.PhylogenyParserException;
45 import org.forester.phylogeny.Phylogeny;
46 import org.forester.phylogeny.PhylogenyMethods;
47 import org.forester.phylogeny.PhylogenyNode;
48 import org.forester.phylogeny.data.Accession;
49 import org.forester.phylogeny.data.Confidence;
50 import org.forester.phylogeny.data.Event;
51 import org.forester.phylogeny.data.Identifier;
52 import org.forester.phylogeny.data.PhylogenyDataUtil;
53 import org.forester.phylogeny.data.Sequence;
54 import org.forester.phylogeny.data.Taxonomy;
55 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
56 import org.forester.util.ForesterUtil;
58 public final class NHXParser implements PhylogenyParser, IteratingPhylogenyParser {
60 public final static Pattern MB_BL_PATTERN = Pattern.compile( "length.median=([^,]+)" );
61 public final static Pattern MB_PROB_PATTERN = Pattern.compile( "prob=([^,]+)" );
62 public final static Pattern MB_PROB_SD_PATTERN = Pattern.compile( "prob.stddev=([^,]+)" );
63 public final static Pattern NUMBERS_ONLY_PATTERN = Pattern.compile( "^[0-9\\.]+$" );
64 final static public boolean REPLACE_UNDERSCORES_DEFAULT = false;
65 private static final boolean ALLOW_ERRORS_IN_DISTANCE_TO_PARENT_DEFAULT = false;
66 final static private byte BUFFERED_READER = 3;
67 final static private byte CHAR_ARRAY = 2;
68 final static private boolean GUESS_IF_SUPPORT_VALUES = true;
69 final static private boolean GUESS_ROOTEDNESS_DEFAULT = true;
70 final static private boolean IGNORE_QUOTES_DEFAULT = false;
72 final static private char BELL = 7;
73 public final static String UTF_8 = "UTF-8";
74 public final static String ISO_8859_1 = "ISO-8859-1";
75 private final static String ENCODING_DEFAULT = UTF_8;
76 private boolean _allow_errors_in_distance_to_parent;
77 private int _clade_level;
78 private StringBuilder _current_anotation;
79 private PhylogenyNode _current_node;
80 private Phylogeny _current_phylogeny;
81 private boolean _guess_rootedness;
83 private boolean _ignore_quotes;
84 private boolean _in_comment = false;
85 private boolean _in_double_quote = false;
86 private boolean _in_open_bracket = false;
87 private boolean _in_single_quote = false;
88 private byte _input_type;
89 private BufferedReader _my_source_br = null;
90 private char[] _my_source_charary = null;
91 private Phylogeny _next;
92 private Object _nhx_source;
93 private boolean _replace_underscores;
94 private boolean _saw_closing_paren;
95 private boolean _saw_colon = false;
96 private boolean _saw_open_bracket = false;
97 private Object _source;
98 private int _source_length;
99 private TAXONOMY_EXTRACTION _taxonomy_extraction;
100 private final String _encoding;
103 _encoding = ENCODING_DEFAULT;
107 public NHXParser( final String encoding ) {
108 _encoding = encoding;
113 public String getName() {
114 return "NH/NHX Parser";
117 public final TAXONOMY_EXTRACTION getTaxonomyExtraction() {
118 return _taxonomy_extraction;
122 public final boolean hasNext() {
123 return _next != null;
127 public final Phylogeny next() throws NHXFormatException, IOException {
128 final Phylogeny phy = _next;
134 public final Phylogeny[] parse() throws IOException {
135 final List<Phylogeny> l = new ArrayList<Phylogeny>();
136 while ( hasNext() ) {
139 final Phylogeny[] p = new Phylogeny[ l.size() ];
140 for( int i = 0; i < l.size(); ++i ) {
148 public final void reset() throws NHXFormatException, IOException {
153 _saw_open_bracket = false;
154 _in_open_bracket = false;
155 _in_double_quote = false;
156 _in_single_quote = false;
158 _current_anotation = new StringBuilder();
159 _current_phylogeny = null;
160 _current_node = null;
161 _my_source_charary = null;
162 determineAndProcessSourceType( _source );
163 switch ( _input_type ) {
165 _my_source_br = null;
166 _my_source_charary = ( char[] ) _nhx_source;
168 case BUFFERED_READER:
169 _my_source_br = ( BufferedReader ) _nhx_source;
172 throw new RuntimeException( "unknown input type" );
177 public final void setGuessRootedness( final boolean guess_rootedness ) {
178 _guess_rootedness = guess_rootedness;
181 public final void setIgnoreQuotes( final boolean ignore_quotes ) {
182 _ignore_quotes = ignore_quotes;
185 public final void setReplaceUnderscores( final boolean replace_underscores ) {
186 _replace_underscores = replace_underscores;
190 public final void setSource( final Object nhx_source ) throws NHXFormatException, IOException {
191 _source = nhx_source;
195 public final void setTaxonomyExtraction( final TAXONOMY_EXTRACTION taxonomy_extraction ) {
196 _taxonomy_extraction = taxonomy_extraction;
199 public final void setAllowErrorsInDistanceToParent( final boolean allow_errors_in_distance_to_parent ) {
200 _allow_errors_in_distance_to_parent = allow_errors_in_distance_to_parent;
203 private final void determineAndProcessSourceType( final Object nhx_source ) throws IOException {
204 if ( nhx_source == null ) {
205 throw new PhylogenyParserException( getClass() + ": attempt to parse null object." );
207 else if ( nhx_source instanceof String ) {
208 _nhx_source = nhx_source;
209 _input_type = NHXParser.BUFFERED_READER;
211 InputStream is = new ByteArrayInputStream( (( String ) nhx_source ).getBytes(getEncoding()));
212 final InputStreamReader isr = new InputStreamReader( is, getEncoding() );
213 _nhx_source = new BufferedReader( isr );
215 else if ( nhx_source instanceof char[] ) {
216 _input_type = NHXParser.CHAR_ARRAY;
217 _source_length = ( ( char[] ) nhx_source ).length;
218 _nhx_source = nhx_source;
220 else if ( nhx_source instanceof File ) {
221 _input_type = NHXParser.BUFFERED_READER;
223 if ( _my_source_br != null ) {
224 //I am REALLY not sure if it is a "good" idea NOT to close the stream...
226 // _my_source_br.close();
228 // catch ( final IOException e ) {
231 final File f = ( File ) nhx_source;
232 final String error = ForesterUtil.isReadableFile( f );
233 if ( !ForesterUtil.isEmpty( error ) ) {
234 throw new PhylogenyParserException( error );
236 final InputStream is = new FileInputStream( f );
237 final InputStreamReader isr = new InputStreamReader( is, getEncoding() );
238 _nhx_source = new BufferedReader( isr );
240 else if ( nhx_source instanceof URL ) {
241 _input_type = NHXParser.BUFFERED_READER;
243 if ( _my_source_br != null ) {
244 //I am REALLY not sure if it is a "good" idea NOT to close the stream...
246 // _my_source_br.close();
248 // catch ( final IOException e ) {
251 final InputStream is = ( ( URL ) nhx_source ).openStream();
252 final InputStreamReader isr = new InputStreamReader( is, getEncoding() );
253 _nhx_source = new BufferedReader( isr );
255 else if ( nhx_source instanceof InputStream ) {
256 _input_type = NHXParser.BUFFERED_READER;
258 if ( _my_source_br != null ) {
259 //I am REALLY not sure if it is a "good" idea NOT to close the stream...
261 // _my_source_br.close();
263 // catch ( final IOException e ) {
266 final InputStream is = ( InputStream ) nhx_source;
267 final InputStreamReader isr = new InputStreamReader( is, getEncoding() );
268 _nhx_source = new BufferedReader( isr );
271 throw new IllegalArgumentException( getClass() + " can only parse objects of type String,"
272 + " char[], File, InputStream, or URL "
273 + " [attempt to parse object of " + nhx_source.getClass() + "]." );
277 private final Phylogeny finishPhylogeny() throws PhylogenyParserException, NHXFormatException,
278 PhyloXmlDataFormatException {
279 if ( _current_phylogeny != null ) {
280 parseNHX( _current_anotation != null ? _current_anotation.toString() : "",
281 _current_phylogeny.getRoot(),
282 getTaxonomyExtraction(),
283 isReplaceUnderscores(),
284 isAllowErrorsInDistanceToParent(),
286 if ( GUESS_IF_SUPPORT_VALUES ) {
287 if ( isBranchLengthsLikeBootstrapValues( _current_phylogeny ) ) {
288 moveBranchLengthsToConfidenceValues( _current_phylogeny );
291 if ( isGuessRootedness() ) {
292 final PhylogenyNode root = _current_phylogeny.getRoot();
293 if ( ( root.getDistanceToParent() >= 0.0 ) || !ForesterUtil.isEmpty( root.getName() )
294 || !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( root ) ) || root.isHasAssignedEvent() ) {
295 _current_phylogeny.setRooted( true );
298 return _current_phylogeny;
303 private final Phylogeny finishSingleNodePhylogeny() throws PhylogenyParserException, NHXFormatException,
304 PhyloXmlDataFormatException {
305 final PhylogenyNode new_node = new PhylogenyNode();
306 parseNHX( _current_anotation.toString(),
308 getTaxonomyExtraction(),
309 isReplaceUnderscores(),
310 isAllowErrorsInDistanceToParent(),
312 _current_phylogeny = new Phylogeny();
313 _current_phylogeny.setRoot( new_node );
314 return _current_phylogeny;
317 private final void init() {
318 setTaxonomyExtraction( TAXONOMY_EXTRACTION.NO );
319 setReplaceUnderscores( REPLACE_UNDERSCORES_DEFAULT );
320 setGuessRootedness( GUESS_ROOTEDNESS_DEFAULT );
321 setIgnoreQuotes( IGNORE_QUOTES_DEFAULT );
322 setAllowErrorsInDistanceToParent( ALLOW_ERRORS_IN_DISTANCE_TO_PARENT_DEFAULT );
325 private final boolean isAllowErrorsInDistanceToParent() {
326 return _allow_errors_in_distance_to_parent;
329 private final boolean isGuessRootedness() {
330 return _guess_rootedness;
333 private final boolean isIgnoreQuotes() {
334 return _ignore_quotes;
337 private final boolean isReplaceUnderscores() {
338 return _replace_underscores;
341 private final void parseNext() throws IOException, NHXFormatException {
342 if ( _source == null ) {
343 throw new IOException( "source is not set" );
347 if ( _input_type == BUFFERED_READER ) {
348 final int ci = _my_source_br.read();
357 if ( _i >= _source_length ) {
360 c = _my_source_charary[ _i ];
362 if ( !_in_single_quote && !_in_double_quote ) {
366 else if ( !( ( c < 33 ) || ( c > 126 ) ) && _saw_colon
367 && ( ( c != '[' ) && ( c != '.' ) && ( ( c < 48 ) || ( c > 57 ) ) ) ) {
370 if ( _in_open_bracket && ( c == ']' ) ) {
371 _in_open_bracket = false;
374 // \n\t is always ignored,
375 // "=34 '=39 space=32
376 if ( ( c < 32 ) || ( c == 127 ) || ( isIgnoreQuotes() && ( ( c == 32 ) || ( c == 34 ) || ( c == 39 ) ) )
377 || ( ( c == 32 ) && ( !_in_single_quote && !_in_double_quote ) )
378 || ( ( _clade_level == 0 ) && ( c == ';' ) && ( !_in_single_quote && !_in_double_quote ) ) ) {
381 else if ( _in_comment ) {
386 else if ( _in_double_quote ) {
388 _in_double_quote = false;
391 _current_anotation.append( changeCharInParens( c ) );
394 else if ( ( c == '"' ) && !_in_single_quote ) {
395 _in_double_quote = true;
397 else if ( _in_single_quote ) {
399 _in_single_quote = false;
402 _current_anotation.append( changeCharInParens( c ) );
405 else if ( c == 39 ) {
406 _in_single_quote = true;
408 else if ( c == '[' ) {
409 _saw_open_bracket = true;
410 _in_open_bracket = true;
412 else if ( _saw_open_bracket ) {
414 // everything not starting with "[&" is considered a comment
415 // unless ":digits and/or . [bootstrap]":
417 _current_anotation.append( "[&" );
419 else if ( _saw_colon ) {
420 _current_anotation.append( "[" + c );
426 // comment consisting just of "[]":
427 _saw_open_bracket = false;
429 else if ( ( c == '(' ) && !_in_open_bracket ) {
430 final Phylogeny phy = processOpenParen();
437 else if ( ( c == ')' ) && !_in_open_bracket ) {
440 else if ( ( c == ',' ) && !_in_open_bracket ) {
444 _current_anotation.append( c );
448 if ( _clade_level != 0 ) {
449 throw new PhylogenyParserException( "error in NH (Newick) formatted data: most likely cause: number of open parens does not equal number of close parens" );
451 if ( _current_phylogeny != null ) {
452 _next = finishPhylogeny();
453 _current_phylogeny = null;
454 _current_anotation = null;
456 else if ( ( _current_anotation != null ) && ( _current_anotation.length() > 0 ) ) {
457 _next = finishSingleNodePhylogeny();
458 _current_anotation = null;
465 private final static char changeCharInParens( char c ) {
469 else if ( c == '[' ) {
472 else if ( c == ']' ) {
478 private final void processCloseParen() throws PhylogenyParserException, NHXFormatException,
479 PhyloXmlDataFormatException {
480 if ( _clade_level < 0 ) {
481 throw new PhylogenyParserException( "error in NH (Newick)/NHX formatted data: most likely cause: number of close parens is larger than number of open parens" );
484 if ( !_saw_closing_paren ) {
485 final PhylogenyNode new_node = new PhylogenyNode();
486 parseNHX( _current_anotation.toString(),
488 getTaxonomyExtraction(),
489 isReplaceUnderscores(),
490 isAllowErrorsInDistanceToParent(),
492 _current_anotation = new StringBuilder();
493 _current_node.addAsChild( new_node );
496 parseNHX( _current_anotation.toString(),
497 _current_node.getLastChildNode(),
498 getTaxonomyExtraction(),
499 isReplaceUnderscores(),
500 isAllowErrorsInDistanceToParent(),
502 _current_anotation = new StringBuilder();
504 if ( !_current_node.isRoot() ) {
505 _current_node = _current_node.getParent();
507 _saw_closing_paren = true;
510 private final void processComma() throws PhylogenyParserException, NHXFormatException, PhyloXmlDataFormatException {
511 if ( !_saw_closing_paren ) {
512 final PhylogenyNode new_node = new PhylogenyNode();
513 parseNHX( _current_anotation.toString(),
515 getTaxonomyExtraction(),
516 isReplaceUnderscores(),
517 isAllowErrorsInDistanceToParent(),
519 if ( _current_node == null ) {
520 throw new NHXFormatException( "format might not be NH or NHX" );
522 _current_node.addAsChild( new_node );
525 parseNHX( _current_anotation.toString(),
526 _current_node.getLastChildNode(),
527 getTaxonomyExtraction(),
528 isReplaceUnderscores(),
529 isAllowErrorsInDistanceToParent(),
532 _current_anotation = new StringBuilder();
533 _saw_closing_paren = false;
536 private final Phylogeny processOpenParen() throws PhylogenyParserException, NHXFormatException,
537 PhyloXmlDataFormatException {
538 Phylogeny phy = null;
539 final PhylogenyNode new_node = new PhylogenyNode();
540 if ( _clade_level == 0 ) {
541 if ( _current_phylogeny != null ) {
542 phy = finishPhylogeny();
545 _current_anotation = new StringBuilder();
546 _current_phylogeny = new Phylogeny();
547 _current_phylogeny.setRoot( new_node );
551 _current_node.addAsChild( new_node );
553 _current_node = new_node;
554 _saw_closing_paren = false;
558 private final static NHXParser createInstance( final Object nhx_source ) throws NHXFormatException, IOException {
559 final NHXParser parser = new NHXParser();
560 parser.setSource( nhx_source );
564 public final static Phylogeny[] parse( final Object nhx_source ) throws NHXFormatException, IOException {
565 return NHXParser.createInstance( nhx_source ).parse();
568 public final static void parseNHX( String s,
569 final PhylogenyNode node_to_annotate,
570 final TAXONOMY_EXTRACTION taxonomy_extraction,
571 final boolean replace_underscores,
572 final boolean allow_errors_in_distance_to_parent,
573 final boolean replace_bell ) throws NHXFormatException,
574 PhyloXmlDataFormatException {
575 if ( ( taxonomy_extraction != TAXONOMY_EXTRACTION.NO ) && replace_underscores ) {
576 throw new IllegalArgumentException( "cannot extract taxonomies and replace under scores at the same time" );
578 if ( ( s != null ) && ( s.length() > 0 ) ) {
579 if ( replace_underscores ) {
580 s = s.replaceAll( "_+", " " );
582 s = s.replaceAll( "\\s+", " " ).trim();
583 boolean is_nhx = false;
584 final int ob = s.indexOf( "[" );
588 final int cb = s.indexOf( "]" );
590 throw new NHXFormatException( "error in NHX formatted data: no closing \"]\" in \"" + s + "\"" );
592 if ( s.indexOf( "&&NHX" ) == ( ob + 1 ) ) {
593 b = s.substring( ob + 6, cb );
596 // No &&NHX and digits only: is likely to be a support value.
597 final String bracketed = s.substring( ob + 1, cb );
598 final Matcher numbers_only = NUMBERS_ONLY_PATTERN.matcher( bracketed );
599 if ( numbers_only.matches() ) {
600 b = ":" + NHXtags.SUPPORT + bracketed;
602 else if ( s.indexOf( "prob=" ) > -1 ) {
603 processMrBayes3Data( s, node_to_annotate );
606 s = s.substring( 0, ob ) + b;
607 if ( ( s.indexOf( "[" ) > -1 ) || ( s.indexOf( "]" ) > -1 ) ) {
608 throw new NHXFormatException( "error in NHX formatted data: more than one \"]\" or \"[\"" );
611 final StringTokenizer t = new StringTokenizer( s, ":" );
612 if ( t.countTokens() > 0 ) {
613 if ( !s.startsWith( ":" ) ) {
614 if ( ( s.indexOf( BELL ) <= -1 ) || !replace_bell ) {
615 node_to_annotate.setName( t.nextToken() );
618 node_to_annotate.setName( t.nextToken().replace( BELL, ':' ) );
620 if ( !replace_underscores && ( !is_nhx && ( taxonomy_extraction != TAXONOMY_EXTRACTION.NO ) ) ) {
621 ParserUtils.extractTaxonomyDataFromNodeName( node_to_annotate, taxonomy_extraction );
624 while ( t.hasMoreTokens() ) {
626 if ( ( s.indexOf( BELL ) > -1 ) && replace_bell ) {
627 s = s.replace( BELL, ':' );
629 if ( s.indexOf( '=' ) < 0 ) {
630 if ( ( node_to_annotate.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT )
631 && !allow_errors_in_distance_to_parent ) {
632 throw new NHXFormatException( "error in NHX formatted data: more than one distance to parent:"
635 node_to_annotate.setDistanceToParent( doubleValue( s, allow_errors_in_distance_to_parent ) );
637 else if ( s.startsWith( NHXtags.SPECIES_NAME ) ) {
638 if ( !node_to_annotate.getNodeData().isHasTaxonomy() ) {
639 node_to_annotate.getNodeData().setTaxonomy( new Taxonomy() );
641 node_to_annotate.getNodeData().getTaxonomy().setScientificName( s.substring( 2 ) );
643 else if ( s.startsWith( NHXtags.IS_DUPLICATION ) ) {
644 if ( ( s.charAt( 2 ) == 'Y' ) || ( s.charAt( 2 ) == 'T' ) ) {
645 node_to_annotate.getNodeData().setEvent( Event.createSingleDuplicationEvent() );
647 else if ( ( s.charAt( 2 ) == 'N' ) || ( s.charAt( 2 ) == 'F' ) ) {
648 node_to_annotate.getNodeData().setEvent( Event.createSingleSpeciationEvent() );
650 else if ( s.charAt( 2 ) == '?' ) {
651 node_to_annotate.getNodeData().setEvent( Event.createSingleSpeciationOrDuplicationEvent() );
654 throw new NHXFormatException( "error in NHX formatted data: :D=Y or :D=N or :D=?" );
657 else if ( s.startsWith( NHXtags.SUPPORT ) ) {
658 PhylogenyMethods.setConfidence( node_to_annotate, doubleValue( s.substring( 2 ), false ) );
660 else if ( s.startsWith( NHXtags.TAXONOMY_ID ) ) {
661 if ( !node_to_annotate.getNodeData().isHasTaxonomy() ) {
662 node_to_annotate.getNodeData().setTaxonomy( new Taxonomy() );
664 node_to_annotate.getNodeData().getTaxonomy().setIdentifier( new Identifier( s.substring( 2 ) ) );
666 else if ( s.startsWith( NHXtags.SEQUENCE_ACCESSION ) ) {
667 if ( !node_to_annotate.getNodeData().isHasSequence() ) {
668 node_to_annotate.getNodeData().setSequence( new Sequence() );
670 node_to_annotate.getNodeData().getSequence()
671 .setAccession( new Accession( s.substring( 3 ), "?" ) );
673 else if ( s.startsWith( NHXtags.GENE_NAME ) ) {
674 if ( !node_to_annotate.getNodeData().isHasSequence() ) {
675 node_to_annotate.getNodeData().setSequence( new Sequence() );
677 node_to_annotate.getNodeData().getSequence().setName( s.substring( 3 ) );
679 } // while ( t.hasMoreTokens() )
684 private final static double doubleValue( final String str, final boolean allow_errors ) throws NHXFormatException {
686 return Double.valueOf( str ).doubleValue();
688 catch ( final NumberFormatException ex ) {
689 if ( !allow_errors ) {
690 throw new NHXFormatException( "error in NH/NHX formatted data: failed to parse number from " + "\""
697 private final static boolean isBranchLengthsLikeBootstrapValues( final Phylogeny p ) {
698 final PhylogenyNodeIterator it = p.iteratorExternalForward();
699 final double d0 = it.next().getDistanceToParent();
700 if ( ( d0 < 10 ) || !it.hasNext() ) {
703 while ( it.hasNext() ) {
704 final double d = it.next().getDistanceToParent();
705 if ( ( d != d0 ) || ( d < 10 ) ) {
712 private final static void moveBranchLengthsToConfidenceValues( final Phylogeny p ) {
713 final PhylogenyNodeIterator it = p.iteratorPostorder();
714 while ( it.hasNext() ) {
715 final PhylogenyNode n = it.next();
716 PhylogenyMethods.setBootstrapConfidence( n, n.getDistanceToParent() );
717 n.setDistanceToParent( PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT );
721 private final static void processMrBayes3Data( final String s, final PhylogenyNode node_to_annotate )
722 throws NHXFormatException {
724 final Matcher mb_prob_sd_matcher = MB_PROB_SD_PATTERN.matcher( s );
725 if ( mb_prob_sd_matcher.find() ) {
727 sd = Double.parseDouble( mb_prob_sd_matcher.group( 1 ) );
729 catch ( final NumberFormatException e ) {
730 throw new NHXFormatException( "failed to parse probability standard deviation (Mr Bayes output) from \""
734 final Matcher mb_prob_matcher = MB_PROB_PATTERN.matcher( s );
735 if ( mb_prob_matcher.find() ) {
738 prob = Double.parseDouble( mb_prob_matcher.group( 1 ) );
740 catch ( final NumberFormatException e ) {
741 throw new NHXFormatException( "failed to parse probability (Mr Bayes output) from \"" + s + "\"" );
745 node_to_annotate.getBranchData()
746 .addConfidence( new Confidence( prob, "posterior probability", sd ) );
749 node_to_annotate.getBranchData().addConfidence( new Confidence( prob, "posterior probability" ) );
753 final Matcher mb_bl_matcher = MB_BL_PATTERN.matcher( s );
754 if ( mb_bl_matcher.find() ) {
757 bl = Double.parseDouble( mb_bl_matcher.group( 1 ) );
759 catch ( final NumberFormatException e ) {
760 throw new NHXFormatException( "failed to parse median branch length (Mr Bayes output) from \"" + s
764 node_to_annotate.setDistanceToParent( bl );
769 public String getEncoding() {
773 public static enum TAXONOMY_EXTRACTION {
774 AGGRESSIVE, NO, PFAM_STYLE_RELAXED, PFAM_STYLE_STRICT;