# Author: Robert Waterhouse #!/usr/local/bin/perl use strict; # tell this scrit which report file to use # e.g. perl place_CAFE_counts_on_tree.pl report_run1.cafe my $report=$ARGV[0]; open(IN,$report) || die $!; my @lines=; close(IN); my $tree=''; my $nodeorder=''; my $nodetree=''; my $expansions=''; my $contractions=''; foreach my $line (@lines) { if($line=~/^Tree:(\(\S+\))$/) { $tree=$1; print "$tree\n"; } if($line=~/\(node ID, node ID\): (.+)/) { $nodeorder=$1; print "$nodeorder\n"; } if($line=~/^# IDs of nodes:(\(\S+\>)$/) { $nodetree=$1; print "$nodetree\n"; } if($line=~/^Expansion :\s+(.+)/) { $expansions=$1; print "$expansions\n"; } if($line=~/^nDecrease :\s+(.+)/) { $contractions=$1; print "$contractions\n"; } } my @tree_parts=split(/[\(\)\,]/,$tree); my @nodetree_parts=split(/[\(\)\,]/,$nodetree); $nodeorder=~s/\s+//g; $expansions=~s/\s+//g; $contractions=~s/\s+//g; my @nodeorder_parts=split(/[\(\)\,]/,$nodeorder); my @expansions_parts=split(/[\(\)\,]/,$expansions); my @contractions_parts=split(/[\(\)\,]/,$contractions); print "Node order: $nodeorder\n"; print "Expansions: $expansions\n"; print "Contractis: $contractions\n"; undef my %branch2exp; undef my %branch2con; for (my $i=0; $i<=$#nodeorder_parts; $i++) { if($nodeorder_parts[$i]=~/\d+/) { $branch2exp{$nodeorder_parts[$i]}=$expansions_parts[$i]; $branch2con{$nodeorder_parts[$i]}=$contractions_parts[$i]; } } my @tree_structure=split(//,$tree); my @tree_struct=(); foreach my $ts (@tree_structure) { if($ts eq '(') { push(@tree_struct,$ts); } if($ts eq ')') { push(@tree_struct,$ts); } if($ts eq ',') { push(@tree_struct,$ts); } } my $ts_counter=0; my $lasti=0; for (my $i=0; $i<=$#tree_parts; $i++) { if($tree_parts[$i]!~/\S+/) { print $tree_struct[$ts_counter]; $ts_counter++; next; } #print "$tree_parts[$i]\n"; if($tree_parts[$i]=~/:/) { my($a,$b)=split(/:/,$tree_parts[$i]); my $nodeid=''; if($nodetree_parts[$i]=~/<(\d+)>/) { $nodeid=$1; } my $label=$nodetree_parts[$i] . "e" . $branch2exp{$nodeid} . ".c" . $branch2con{$nodeid}; print "$label:$b"; } print $tree_struct[$ts_counter]; $ts_counter++; $lasti=$i; } $lasti++; print "$nodetree_parts[$lasti]\n";