}
}
+sub space_fill{
+ my ($value,$length,$right) = @_;
+ $right ||= 0;
+ if (length($value) > $length) {
+ $value =~ m/(.{$length})/;
+ return $1;
+ }
+ if (length($value) == $length) {
+ return $value
+ }
+ if ($right) {
+ return join('',
+ ' ' x ($length - length($value)),
+ $value,
+ );
+ }
+ else {
+ return join('',
+ $value,
+ ' ' x ($length - length($value)),
+ );
+ }
+}
+
+sub results_table_line {
+ my ($keyword,@fields) = @_;
+ return join( ' & ',
+ space_fill($keyword,23),
+ map {space_fill($_,11,1)} @fields
+ )."\n";
+}
+my @database_order = grep {lc($_) ne 'total'} keys %databases;
if (defined $results_table_fh) {
- our ($keyword,$weight,$autoweight,$gct,$hvt,$nct,$t) = ('Keyword','Weight','Autoweight','GeneCards','Harvester','NCBI','Total');
- format RESULTS_TABLE =
-@<<<<<<<<<<<<<<<<<<<<<< & @>>>>>>>>>> & @>>>>>>>>>> & @>>>>>>>>>> & @>>>>>>>>>> & @>>>>>>>>>> & @>>>>>>>>>> \\
-$keyword, $weight, $autoweight, $gct, $hvt, $nct, $t
-.
- $results_table_fh->format_name('RESULTS_TABLE');
- write $results_table_fh;
+ my $keyword;
+ print {$results_table_fh} results_table_line('Keyword','Weight','Autoweight',
+ map {ucfirst($_)} @database_order,
+ 'Total',
+ );
for $keyword (sort keys %terms) {
- ($gct,$hvt,$nct,$t) =
+ my @fields =
map {
if (not defined $_) {
'$-$';
$_->{unique} ||= 0;
"$_->{count} ($_->{unique})";
}
- } @{$terms{$keyword}}{qw(genecard harvester ncbi total)};
- $weight = $keyword_weight{$keyword} || 1;
- $autoweight = $auto_weight{$keyword};
- write $results_table_fh;
+ } @{$terms{$keyword}}{@database_order,'total'};
+ unshift @fields, $auto_weight{$keyword};
+ unshift @fields, $keyword_weight{$keyword} || 1;
+ print {$results_table_fh} results_table_line($keyword,
+ @fields
+ );
}
-
$keyword = 'Total';
- ($gct,$hvt,$nct,$t) =
+ my @fields = ('','');
+ push @fields,
map {
if (not defined $_) {
'$-$';
$_->{unique} ||= 0;
"$_->{count} ($_->{unique})";
}
- } map {$_->{total}} @databases{qw(genecard harvester ncbi total)};
- #($gct,$hvt,$nct,$t) = map {$_->{total}} @databases{qw(genecard harvester ncbi total)};
- $weight = '';
- $autoweight = '';
- write $results_table_fh;
+ } map {$_->{total}} @databases{@database_order,'total'};
+ print {$results_table_fh} results_table_line($keyword,
+ @fields
+ );
}
__END__