-
Notifications
You must be signed in to change notification settings - Fork 1
/
PileOMethByBedRegion.pl
48 lines (43 loc) · 972 Bytes
/
PileOMethByBedRegion.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
#!/usr/bin/perl
use strict;
my $fa="/home/shg047/oasis/db/hg19/hg19.fa";
my @bam=glob("CTR*bam");
my $bed=shift @ARGV;
my $output=shift @ARGV;
open F,$bed;
chomp (my @bed=<F>);
close F;
open OUT,">$output.amf";
my $header=join("\t",@bam);
print OUT "\t$header\n";
foreach my $bed(@bed){
my @tmp=split/\s+/,$bed;
my $cor="$tmp[0]:$tmp[1]-$tmp[2]";
print OUT "$cor";
foreach my $bam(@bam){
my ($sam,undef)=split /_/,$bam; # CTR84_trimmed.fq.gz_bismark_bt2.sort.bam
my $cmd="PileOMeth extract -r $cor --minDepth 5 --mergeContext $fa $bam -o $sam.$cor";
system($cmd);
open F2,"$sam.$cor\_CpG.bedGraph" || die "Can not open the file Tmp.txt_CpG.bedGraph";
my $data;
my $count;
while(<F2>){
next if /track/i;
exit if /^\s+$/;
chomp;
my @tmp=split/\s+/;
$data+= $tmp[3];
$count++;
}
close F2;
$data =$data/($count+0.0001);
$data=sprintf("%.2f", $data);
if($count>0){
print OUT "\t$data";
}else{
print OUT "\tNA";
}
system("rm $sam.$cor\_CpG.bedGraph");
}
print OUT "\n";
}