-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmethylation.pl
executable file
·44 lines (43 loc) · 1.04 KB
/
methylation.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
use strict;
open IN, shift;
my $gene;
my $n = 0;
my %meth;
while ( <IN> ){
chomp;
my @cols = split /\t/;
if ($_ =~ /^#/) {
if ($gene ne '') {
if ($n > 0) { #print the old one
my $weighted;
my $alldepth;
foreach my $CpG (@{$meth{$gene}}) {
$alldepth += $CpG->{'depth'};
}
foreach my $CpG (@{$meth{$gene}}) {
my $depth = $CpG->{'depth'};
my $methy = $CpG->{'methy'};
$weighted += ($depth/$alldepth)*$methy;
}
$weighted = sprintf("%.8f", $weighted);
print "$gene\t$weighted\n";
} else {
print "$gene\t-1\n";
}
}
($gene = $_) =~ s/^[\#]+\t//;
$n = 0;
} else {
$cols[3] =~ /^\'(\d+)\/(\d+)\'$/;
my $methD = $1;
my $totD = $2;
next if $totD < 3; #skip exteremly low depth site
$totD = ($totD <= 25)? $totD : 25; #upper bound of depth
my %tmp;
$tmp{'depth'} = $totD;
$tmp{'methy'} = $cols[4]/1000;
push(@{$meth{$gene}}, \%tmp);
$n++;
}
}
close IN;