- private final static String obtainConfidence( final PhylogenyNode n ) {
- if ( n.getBranchData().getConfidences() != null && n.getBranchData().getConfidences().size() > 0 ) {
- final List<Confidence> confidences = n.getBranchData().getConfidences();
- boolean not_first = false;
- Collections.sort( confidences );
- final StringBuilder sb = new StringBuilder();
- for( final Confidence confidence : confidences ) {
- final double value = confidence.getValue();
- if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
- if ( not_first ) {
- sb.append( " / " );
+ public final static void performMapping( final Pattern pattern,
+ final SortedMap<String, String> map,
+ final Phylogeny p,
+ final boolean verbose )
+ throws UserException {
+ if ( verbose ) {
+ System.out.println();
+ System.out.println( "Id to annotation mapping:" );
+ }
+ 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" );
+ }
+ final Matcher m = pattern.matcher( name );
+ if ( !m.find() ) {
+ if ( !map.containsKey( name ) ) {
+ throw new UserException( "no mapping for \"" + name + "\" found" );
+ }
+ node.setName( map.get( name ).trim() );
+ if ( verbose ) {
+ System.out.println( name + " -> " + node.getName() );
+ }
+ }
+ }
+ if ( verbose ) {
+ System.out.println();
+ }
+ }
+
+ public final static void performExtraProcessing1( final Pattern query_pattern,
+ final Phylogeny p,
+ final String extra_sep,
+ final boolean keep,
+ final String annotation_sep,
+ final boolean verbose )
+ throws UserException {
+ if ( verbose ) {
+ System.out.println();
+ System.out.println( "Extra 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 StringBuilder sb = new StringBuilder();
+ final int last_index = name.lastIndexOf( extra_sep );
+ if ( last_index >= 0 ) {
+ final String annotation = name.substring( last_index + 1 ).trim();
+ if ( ForesterUtil.isEmptyTrimmed( annotation ) ) {
+ throw new UserException( "llegally formatted annotation: " + name );
+ }
+ if ( keep ) {
+ final String extra = name.substring( 0, last_index ).trim();
+ sb.append( annotation );
+ if ( !ForesterUtil.isEmpty( extra ) ) {
+ sb.append( annotation_sep );
+ sb.append( extra );
+ }