3 Author: Hu Xuesong @ BGI <huxuesong@genomics.org.cn>
4 Version: 1.0.0 @ 20180614
8 use Cwd
qw(abs_path cwd);
10 use List
::Util qw
[min max
];
11 use Statistics
::TTest
;
13 use Data
::Dump
qw(ddx);
15 my ($bedfn,$cgLfn,$cgRfn,$outfn) = @ARGV;
17 die "Usage: $0 <bed> <Left.cg> <Right.cg> <out.tsv>\n";;
20 my $cgLin = Parse
::CSV
->new(file
=> $cgLfn, names
=> 1, sep_char
=> "\t");
21 my $cgRin = Parse
::CSV
->new(file
=> $cgRfn, names
=> 1, sep_char
=> "\t");
23 open B
,'<',$bedfn or die $?
;
28 push @
{$Dbed{$L[0]}},[$L[1],$L[2]];
29 my @rng = $L[1] .. $L[2];
38 my ($rngD,$csvh) = @_;
40 while ( my $value = $csvh->fetch ) {
42 if (exists $rngD->{ $value->{'#CHROM'} }{ $value->{'POS'} }) {
43 my ($cgCnt,$cgC,$cgW,$flag)=(0,0,0,0);
44 if ($value->{'Crick-COVERAGE'} ne '.') {
45 if ($value->{'Crick-COVERAGE'} >= 5) {
46 $cgC = $value->{'Crick-METH'}/$value->{'Crick-COVERAGE'};
51 if ($value->{'Watson-COVERAGE'} ne '.') {
52 if ($value->{'Watson-COVERAGE'} >= 5) {
53 $cgW = $value->{'Watson-METH'}/$value->{'Watson-COVERAGE'};
59 $Dcg{$value->{'#CHROM'}}{$value->{'POS'}} = [$cgCnt/2, ($cgC+$cgW)/$cgCnt,$flag];
68 my %DcgL = %{ loadCG
(\
%Rbed,$cgLin) };
70 my %DcgR = %{ loadCG
(\
%Rbed,$cgRin) };
76 for my $p ($st .. $ed) {
77 if (exists $dat->{$p}) {
78 $ret{$p} = $dat->{$p};
84 open O
,'>',$outfn or die $?
;
85 print O
"# L:[$cgLfn], R:[$cgRfn].\n";
86 open B
,'<',$bedfn or die $?
;
90 print O
join("\t",@L[0..2]),"\t";
91 my %cgLr = getCG
($DcgL{$L[0]},$L[1],$L[2]);
92 my %cgRr = getCG
($DcgR{$L[0]},$L[1],$L[2]);
95 for (keys %cgLr,keys %cgRr) {
101 $dL = $cgLr{$_} if exists $cgLr{$_};
102 $dR = $cgRr{$_} if exists $cgRr{$_};
103 $cgR{$_} = [@
$dL,@
$dR];
107 my ($shared,$left,$right,$unioned)=(0,0,0,0);
108 my ($Lsum,$Lcnt,$Rsum,$Rcnt)=(0,0,0,0);
111 my @d = @
{ $cgR{$_} };
112 $shared += min
($d[0],$d[3]);
115 my $flag = $d[2] | $d[5];
120 } elsif ($flag==1 or $flag==2) {
124 $Lsum += $d[1]*$d[0]; $Lcnt += $d[0];
125 $Rsum += $d[4]*$d[3]; $Rcnt += $d[3];
128 if (@tL>1 and @tR>1) {
129 my $ttest = new Statistics
::TTest
;
130 $ttest->load_data(\
@tL,\
@tR);
131 $p = $ttest->{t_prob
};
133 my ($avgL,$avgR)=qw(NA NA);
134 $avgL = $Lsum/$Lcnt if $Lcnt;
135 $avgR = $Rsum/$Rcnt if $Rcnt;
136 print O
join(',',$shared,$left,$right,$unioned),"\t",join("\t",$avgL,$avgR,$p),"\n";
142 ./cdmr
.pl gencode
.v30
.annotation
.bed
.h B7B
.cg
.h Normal
.cg
.h o
.tsv