-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsma.pl
More file actions
42 lines (37 loc) · 757 Bytes
/
sma.pl
File metadata and controls
42 lines (37 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env perl
use Data::Dumper;
use Getopt::Std;
$| = 1;
my %options={};
getopts("pdc:",\%options);
# -c4
my $DEBUG = defined $options{d} ? 1 : 0;
my $passthru = defined $options{p} ? 1 : 0;
my $col = $options{c};
print "col:$col\n" if $DEBUG;
my @rows = ();
while(<>){
if(/^#/){
print $_ if $passthru;
}else{
print "#" . $_ if $passthru;
chomp;
push(@rows,$_);
my @cols = split(/\t/);
if (scalar(@rows)>10){
print "SHIFTING" if $DEBUG;
shift @rows;
}
my $tot = 0;
my $sma = 0;
for $r (@rows) {
print "ROW:[$r]\n" if $DEBUG;
my @c = split(/\t/,$r);
print "\@c" . Dumper(@c) . "\n" if $DEBUG;
$tot += $c[$col-1];
$sma = $tot/scalar(@rows);
print "sma:$sma\n" if $DEBUG;
}
print "$_\t$sma\n";
}
}