-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathema.pl
More file actions
40 lines (35 loc) · 679 Bytes
/
ema.pl
File metadata and controls
40 lines (35 loc) · 679 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
#!/usr/bin/env perl
use Data::Dumper;
use Getopt::Std;
$| = 1;
my %options={};
getopts("pdc:i:",\%options);
# -c4
my $DEBUG = defined $options{d} ? 1 : 0;
my $passthru = defined $options{p} ? 1 : 0;
my $col = $options{c};
my $intervals = $options{i};
print "col:$col\n" if $DEBUG;
my $lastrow = "";
my $emaLast = 0;
while(<>){
my $ema;
if(/^#/){
print $_ if $passthru;
}else{
print "#" . $_ if $passthru;
chomp;
###
my @cols = split(/\t/);
my $val = $cols[$col-1];
if($emaLast == 0){
$ema = $val;
}else{
my $k = 2/($intervals+1);
$ema = $val * $k + $emaLast * (1-$k);
}
$lastrow = "$_\t$ema";
print $lastrow . "\n";
$emaLast = $ema;
}
}