| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# Reads a list of numbers on stdin, computes a (blocked) histogram. |
| 4 |
# |
| 5 |
# If there are two numbers per line, they are assumed to be |
| 6 |
# a begin-end pair. |
| 7 |
|
| 8 |
# grep "M u " ATAC/atac.shift.atac | cut -d' ' -f 7 | perl run-length-histogram.pl > atac.histogram |
| 9 |
# grep "M u " ATAC/box2.shift.atac | cut -d' ' -f 7 | perl run-length-histogram.pl > box2.histogram |
| 10 |
|
| 11 |
my @histogram; |
| 12 |
my $blocksize = 1000; |
| 13 |
|
| 14 |
while (<STDIN>) { |
| 15 |
s/^\s+//; |
| 16 |
s/\s$//; |
| 17 |
s/\s+/ /; |
| 18 |
|
| 19 |
my @vals = split '\s+', $_; |
| 20 |
my $val; |
| 21 |
|
| 22 |
if (scalar(@vals) == 1) { |
| 23 |
$val = $vals[0]; |
| 24 |
} elsif (scalar(@vals) == 1) { |
| 25 |
$val = $vals[1] - $vals[0]; |
| 26 |
$val = $vals[0] - $vals[1] if ($val < 0); |
| 27 |
} else { |
| 28 |
} |
| 29 |
|
| 30 |
$val = ($val / $blocksize); |
| 31 |
$histogram[$val]++; |
| 32 |
} |
| 33 |
|
| 34 |
my $max = scalar(@histogram) + 1; |
| 35 |
for (my $i=0; $i<$max; $i++) { |
| 36 |
$histogram[$i] = 0 if ($histogram[$i] == 0); |
| 37 |
print "$i $histogram[$i]\n"; |
| 38 |
} |
| 39 |
|