#!/usr/local/bin/perl5 -w # # combine-scores [-sum|-min|-max] [-at] file.rdb file2.rdb ... # # merges several different rdb files that contain scores taking the # sum, minimum, or maximum of the scores. # # The resultant rdb file is sent to stdout. # If "-at" is specified with -min or -max, # then the output also has a column reporting which file produced the score. $tmp = "tmp-combine-$$"; # create empty tmp file open(TMP,">$tmp") || die "Can't write to $tmp\n"; $use_sum = 0; $use_max=0; $use_min=1; $do_at = 0; foreach $file (@ARGV) { if ($file eq "-sum") { $use_sum=1; $use_max=0; $use_min=0; } elsif ($file eq "-min") { $use_sum = 0; $use_max=0; $use_min=1; } elsif ($file eq "-max") { $use_sum = 0; $use_max=1; $use_min=0; } elsif ($file eq "-at") { $do_at=1; } else { $do_at = $do_at && !$use_sum; open(RDB_IN, "column TARGET HMM SCORE < $file | headchg -del |"); while() { /^(\S+\t\S+)\t(\S+)$/ && ($key = $1) && ($score = $2); if ($do_at) { print TMP "$key\t$score\t$file\n"; } else { print TMP "$key\t$score\n"; } } close(RDB_IN); } } close(TMP); if (!$do_at) { print "TARGET\tHMM\tSCORE\n10S\t6S\t10N\n"; } else { print "TARGET\tHMM\tSOURCE\tSCORE\n10S\t6S\t20S\t10N\n"; } $old1 = ""; $old0 = ""; $sum=0; $min=99999; $max=-99999; open(TMP, "sort $tmp|"); while() { chomp; @cols = split(/\t/); if ($cols[0] ne $old0 || $cols[1] ne $old1) { # new key print_key() if ($old0 ne ""); $sum=$cols[2]; $min=$sum; $old0=$cols[0]; $old1=$cols[1]; next; } $sum += $cols[2] if $use_sum; if ($use_min && $min>$cols[2]) { $min = $cols[2]; $at = $cols[3] if $do_at; } if ($use_max && $max<$cols[2]) { $max = $cols[2]; $at = $cols[3] if $do_at; } } print_key(); close TMP; unlink $tmp; exit 0; sub print_key() { if ($use_sum) { print "$old0\t$old1\t$sum\n"; } elsif ($do_at) { print "$old0\t$old1\t$at\t$min\n"; } else { print "$old0\t$old1\t$min\n"; } }