X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fclade_analysis%2FAnalysisMulti.java;h=3970e5d16310521b0fd7c34381aeb9d16fa3bd47;hb=1706deea223bc1a30d170596192d726b6847b7eb;hp=8096777acd659ef81647617d99caa30ed2196812;hpb=0d0b9cde030d50b153eb6d1ff7ce13bc273edc17;p=jalview.git diff --git a/forester/java/src/org/forester/clade_analysis/AnalysisMulti.java b/forester/java/src/org/forester/clade_analysis/AnalysisMulti.java index 8096777..3970e5d 100644 --- a/forester/java/src/org/forester/clade_analysis/AnalysisMulti.java +++ b/forester/java/src/org/forester/clade_analysis/AnalysisMulti.java @@ -97,7 +97,7 @@ public final class AnalysisMulti { while ( qnode_pp.getNumberOfDescendants() == 1 ) { qnode_pp = qnode_pp.getParent(); } - final List qnode_ext_nodes_names = new ArrayList<>(); + final List qnode_ext_nodes_names = new ArrayList(); for( final PhylogenyNode qnode_ext_node : qnode_pp.getAllExternalDescendants() ) { final String name = qnode_ext_node.getName(); final Matcher m = query.matcher( name ); @@ -202,7 +202,7 @@ public final class AnalysisMulti { final String separator, final Pattern query ) { final int child_index = child.getChildNodeIndex(); - final List ext_nodes_names = new ArrayList<>(); + final List ext_nodes_names = new ArrayList(); final List descs = parent.getDescendants(); for( int i = 0; i < descs.size(); ++i ) { if ( i != child_index ) { @@ -252,7 +252,7 @@ public final class AnalysisMulti { } } - public final static void performExtraProcessing1( final Pattern pattern, + public final static void performExtraProcessing1( final Pattern query_pattern, final Phylogeny p, final String extra_sep, final boolean keep, @@ -270,14 +270,13 @@ public final class AnalysisMulti { if ( ForesterUtil.isEmpty( name ) ) { throw new UserException( "external node with empty name found" ); } - final Matcher m = pattern.matcher( name ); - if ( !m.find() ) { + 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( "illegal format:" + name ); + throw new UserException( "llegally formatted annotation: " + name ); } if ( keep ) { final String extra = name.substring( 0, last_index ).trim(); @@ -301,4 +300,55 @@ public final class AnalysisMulti { System.out.println(); } } + + 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(); + } + } }