-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsimplify-stt.pl
executable file
·57 lines (50 loc) · 1018 Bytes
/
simplify-stt.pl
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
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use List::Util 'sum';
# process command line arguments
my $rootage = 549.3475;
my $window = 50;
my $sttfile;
GetOptions(
'sttfile=s' => \$sttfile,
'rootage=f' => \$rootage,
'window=f' => \$window,
);
# read table
my ( @values, @header, $scale, $cols );
open my $fh, '<', $sttfile or die $!;
while(<$fh>) {
chomp;
my @fields = split /\t/, $_;
if ( $fields[0] ne 'age' ) {
if ( not defined $scale ) {
$scale = $fields[0] / $rootage;
$cols = $#fields;
}
my $age = $fields[0] / $scale;
my $index = int( $age / $window );
$values[$index] = [] if not $values[$index];
push @{ $values[$index] }, \@fields;
}
else {
print join( "\t", @fields ), "\n";
}
}
for my $i ( 0 .. $#values ) {
print $i, "\t";
for my $j ( 1 .. $cols ) {
my @v;
for my $row ( @{ $values[$i] } ) {
push @v, $row->[$j];
}
if ( @v ) {
print (sum(@v)/scalar(@v));
}
else {
print 'NA';
}
$j == $cols ? print "\n" : print "\t";
}
}