+
+ public final static void performSpecialProcessing1( final Pattern query_pattern,
+ final Phylogeny p,
+ final String annotation_sep,
+ final Pattern special_pattern,
+ final boolean verbose )
+ throws UserException {
+ if ( verbose ) {
+ System.out.println();
+ System.out.println( "Special annotation processing:" );
+ }
+ final PhylogenyNodeIterator it = p.iteratorExternalForward();
+ while ( it.hasNext() ) {
+ final PhylogenyNode node = it.next();
+ final String name = node.getName().trim();
+ if ( ForesterUtil.isEmpty( name ) ) {
+ throw new UserException( "external node with empty name found" );
+ }
+ if ( !query_pattern.matcher( name ).find() ) {
+ final Matcher special_m = special_pattern.matcher( name );
+ if ( special_m.matches() ) {
+ final int c = special_m.groupCount();
+ if ( c < 1 ) {
+ throw new UserException( "illegal special pattern: " + special_pattern
+ + " (need at least one capturing group)" );
+ }
+ final StringBuilder sb = new StringBuilder();
+ for( int i = 1; i <= c; ++i ) {
+ final String g = special_m.group( i );
+ if ( !ForesterUtil.isEmpty( g ) ) {
+ if ( i > 1 ) {
+ sb.append( annotation_sep );
+ }
+ sb.append( special_m.group( i ) );
+ }
+ }
+ node.setName( sb.toString() );
+ if ( verbose ) {
+ System.out.println( name + " -> " + node.getName() );
+ }
+ }
+ else {
+ throw new UserException( "illegally formatted annotation for special processing: " + name
+ + " (expected pattern: " + special_pattern + ")" );
+ }
+ }
+ }
+ if ( verbose ) {
+ System.out.println();
+ }
+ }