Debian Codegraph @

rmark/rmark-hitlist.pl

raw
1 #! /usr/bin/perl -w
2
3 # Given a positive file (.pos) and an output (.out) file
4 # of an rmark benchmark run in positives-only mode, print
5 # the score and E-value of the best scoring hit for each
6 # positive sequence to separate files.
7 #
8 # Example usage: sort -g r3-po-inf-df/*out | perl rmark-hitlist.pl rmark3.ppos
9 #
10 my $usage = "Usage: perl rmark-hitlist.pl <pposfile> <output root> | <rmark outfile>\n";
11
12 my $pposfile = "";
13 $pposfile = shift;
14
15 if (! -e $pposfile) { die "$pposfile doesn't exist"; }
16
17 my ($line, $fam, $tmp, $fn, $fp, $mer, $fam_strlen, $sc, $match, $strand, $mer_fp, $mer_fn, $mer_sc);
18 my @fields = ();
19 my $npos = 0;
20
21 $famidx_strlen = length("family");
22 $target_strlen = length("target");
23 # count positives in each fam from posfile
24 open(PPOS, $pposfile) || die "ERROR, couldn't open pposfile $pposfile";
25 while ($line = <PPOS>)
26 {
27 chomp $line;
28 if ($line =~ m/^\#/) { next; }
29 @fields = split(' ', $line, 5);
30 $match = $fields[0];
31 $target = $fields[1];
32 $fam = $match;
33 $fam =~ s/\/\d+$//;
34 if($fam =~ m/\//) { die "ERROR family $fam from $tmp, contains two '/', it should only have 1!"; }
35 if(! exists($famH{$fam})) { push(@famA, $fam); $famH{$fam} = 1; }
36 if(exists($target2famH{$target})) { die "ERROR, $target exists twice\n"; }
37 $target2famH{$target} = $match;
38 push(@{$targetHA{$fam}}, $target);
39
40 $bitHH{$fam}{$target} = "none";
41 $evalHH{$fam}{$target} = "none";
42 if(length($match) > $famidx_strlen) { $famidx_strlen = length($match); }
43 if(length($target) > $target_strlen) { $target_strlen = length($target); }
44 $npos++;
45 }
46 close(PPOS);
47
48 $found_at_least_one = 0;
49 while ($line = <>)
50 {
51 chomp $line;
52 if ($line =~ m/^\#/) { next; }
53 @fields = split(' ', $line, 8);
54 if(scalar(@fields) != 8) { die "ERROR, incorrectly formatted output line $line"; }
55 $e = $fields[0];
56 $bit = $fields[1];
57 $target = $fields[4];
58 $fam = $fields[5];
59 $match = $fields[6];
60 $strand = $fields[7];
61
62 if($strand eq "same") {
63 if(exists($bitHH{$fam}{$target})) { #if target belongs to this fam
64 if(($bitHH{$fam}{$target} eq "none") || ($bit > $bitHH{$fam}{$target})) {
65 $bitHH{$fam}{$target} = $bit;
66 $evalHH{$fam}{$target} = $e;
67 $found_at_least_one = 1;
68 }
69 }
70 }
71 }
72 if($found_at_least_one == 0) { die "ERROR, no hits found. Is your input a positives-only benchmark?\n"; }
73 my $idx = 1;
74 foreach $fam (@famA) {
75 foreach $target (@{$targetHA{$fam}}) {
76 printf(" %3d %-*s %-*s", $idx++, $famidx_strlen, $target2famH{$target}, $target_strlen, $target);
77 if($bitHH{$fam}{$target} eq "none") { printf(" %8.2f", "-50.0"); }
78 else { printf(" %8.2f", $bitHH{$fam}{$target}); }
79 if($evalHH{$fam}{$target} eq "none") { printf(" %8g\n", "987654321"); }
80 else { printf(" %8g\n", $evalHH{$fam}{$target}); }
81 }
82 }
83