-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcolMeans.pl
executable file
·80 lines (66 loc) · 1.35 KB
/
colMeans.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! /usr/bin/perl
####################
# colMeans.pl - for a file like id tab gene tab value1 tab value2... collapse genes with multiple probes (lines) into one, averaging the values.
# By Madelaine Gogol for Vikki Weake
# 12/2009
####################
#call the script with: perl colMeans.pl input.txt > output.txt
#for each line in the file
$in_gene = 'false';
$last_fbgn = '';
while(<>)
{
if($_ =~ /^FBgn ID/)
{
}
else
{
chomp;
#remove the end of line character
($fbgn,$gene_symbol,@probe_values) = split("\t",$_);
if($fbgn eq $last_fbgn)
{
#keep going
print "keep going...\n";
#push @AoA, [@probe_values];
@AoA = @probe_values;
$last_fbgn = $fbgn;
$last_symbol = $gene_symbol;
}
else
{
#new gene, average last one.
if($last_fbgn)
{
#print "avg last one\n";
print "$last_fbgn\t$last_symbol\t";
colMeans(\@AoA);
@AoA = ();
# push @AoA, [@probe_values];
@AoA = $probe_values;
$last_fbgn = $fbgn;
$last_symbol = $gene_symbol;
}
else
{
# push @AoA, [@probe_values];
@AoA = @probe_values;
$last_fbgn = $fbgn;
$last_symbol = $gene_symbol;
}
}
}
}
#average the columns
sub colMeans
{
my $arrayref = @_;
print "[1][1]:$arrayref->[1][1]\n";
}
sub mean
{
my $mean;
my @nums = @_;
$mean = sum(@nums)/scalar(@nums);
return($mean);
}