forked from pxulab/MRLR
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1st_split_sum.pl
More file actions
executable file
·137 lines (130 loc) · 4.81 KB
/
1st_split_sum.pl
File metadata and controls
executable file
·137 lines (130 loc) · 4.81 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/perl -w
#
use strict;
my $file=shift or die "Usage: $0 <haplotype_block_match.file>\n";
&test_file($file,13,14,"$file.10k.tmp");
&stat("$file.10k.tmp");
sub test_file{
my ($file,$n,$m,$out)=@_;
my ($start,$end)=(0,0);
my $block;
my $chr;
my ($o_o_m,$o_t_m,$t_o_m,$t_t_m)=(0,0,0,0); #$o_o_m:one-one-match;$o_t_m:one-two-match
my ($o_o_u,$o_t_u,$t_o_u,$t_t_u)=(0,0,0,0); #$o_o_u:one-one-unmatch;$o_t_u:one-two-unmatch
open my $fileh,'<', $file;
open my $outh,'>', $out;
while(<$fileh>){
my @line=split;
next if ($line[$n]eq"." or $line[$m]eq".");
if($start==0){
$start=$line[$n];
$end=$line[$m];
$chr=$line[0];
$block="$line[10]\t$line[11]";
my($a,$b,$c,$d,$e,$f,$g,$h)=&count(@line);
($o_o_m,$o_t_m,$t_o_m,$t_t_m,$o_o_u,$o_t_u,$t_o_u,$t_t_u)=($o_o_m+$a,$o_t_m+$b,$t_o_m+$c,$t_t_m+$d,$o_o_u+$e,$o_t_u+$f,$t_o_u+$g,$t_t_u+$h);
}
else{
if($line[0]eq$chr and $line[$n]eq$start and $line[$m]eq$end){
my($a,$b,$c,$d,$e,$f,$g,$h)=&count(@line);
($o_o_m,$o_t_m,$t_o_m,$t_t_m,$o_o_u,$o_t_u,$t_o_u,$t_t_u)=($o_o_m+$a,$o_t_m+$b,$t_o_m+$c,$t_t_m+$d,$o_o_u+$e,$o_t_u+$f,$t_o_u+$g,$t_t_u+$h);
}else{
my $sum=$o_o_m+$o_o_u;
print $outh "$chr\t$start\t$end\t$block\t";
print $outh "1-1:".$o_o_m.";".$o_o_u."\t";
print $outh "1-2:".$o_t_m.";".$o_t_u."\t";
print $outh "2-1:".$t_o_m.";".$t_o_u."\t";
print $outh "2-2:".$t_t_m.";".$t_t_u."\t";
printf $outh "%.3f\t%.3f\t%.3f\t%.3f\n",$o_o_m/$sum,$o_t_m/$sum,$t_o_m/$sum,$t_t_m/$sum;
$start=$line[$n];
$end=$line[$m];
$chr=$line[0];
$block="$line[10]\t$line[11]";
($o_o_m,$o_t_m,$t_o_m,$t_t_m)=(0,0,0,0);
($o_o_u,$o_t_u,$t_o_u,$t_t_u)=(0,0,0,0);
my($a,$b,$c,$d,$e,$f,$g,$h)=&count(@line);
($o_o_m,$o_t_m,$t_o_m,$t_t_m,$o_o_u,$o_t_u,$t_o_u,$t_t_u)=($o_o_m+$a,$o_t_m+$b,$t_o_m+$c,$t_t_m+$d,$o_o_u+$e,$o_t_u+$f,$t_o_u+$g,$t_t_u+$h);
}
}
}
if(eof($fileh)){
my $sum=$o_o_m+$o_o_u;
print $outh "$chr\t$start\t$end\t";
print $outh "1-1:".$o_o_m.";".$o_o_u."\t";
print $outh "1-2:".$o_t_m.";".$o_t_u."\t";
print $outh "2-1:".$t_o_m.";".$t_o_u."\t";
print $outh "2-2:".$t_t_m.";".$t_t_u."\t";
printf $outh "%.3f\t%.3f\t%.3f\t%.3f\n",$o_o_m/$sum,$o_t_m/$sum,$t_o_m/$sum,$t_t_m/$sum;
}
close $fileh;
close $outh;
}
sub count{
my @line=@_;
my ($o_o_m,$o_t_m,$t_o_m,$t_t_m,$o_o_u,$o_t_u,$t_o_u,$t_t_u)=(0,0,0,0,0,0,0,0);
if($line[6]eq"1-1"){
$o_o_m++;
}elsif($line[6]eq"0-0"){
$o_o_u++;
}
if($line[7]eq"1-2"){
$o_t_m++;
}elsif($line[7]eq"0-0"){
$o_t_u++;
}
if($line[8]eq"2-1"){
$t_o_m++;
}elsif($line[8]eq"0-0"){
$t_o_u++;
}
if($line[9]eq"2-2"){
$t_t_m++;
}elsif($line[9]eq"0-0"){
$t_t_u++;
}
return ($o_o_m,$o_t_m,$t_o_m,$t_t_m,$o_o_u,$o_t_u,$t_o_u,$t_t_u);
}
sub stat{
my ($file)=@_;
open my $fileh,'<',$file;
while(<$fileh>){
my @line=split;
my @num=($#line-3)..$#line;
my %info;
my @array=($line[$#line-3],$line[$#line-2],$line[$#line-1],$line[$#line]);
@array=sort {$b<=>$a} @array;
foreach my $n (0..$#array){
foreach my $i (@num){
if($line[$i] == $array[$n]){
$info{$n+1}=$i;
if(grep {$_ != $i} @num){
@num=grep {$_ != $i} @num;
}
last;
}
}
}
my ($num1,$num2,$num3,$id1,$id2,$id3);
if($line[$info{1}-4]=~/\d-(\d):(\d*);/){
$id1=$1;
$num1=$2;
}
if($line[$info{2}-4]=~/\d-(\d):(\d*);/){
$id2=$1;
$num2=$2;
}
if($line[$info{3}-4]=~/\d-(\d):(\d*);/){
$id3=$1;
$num3=$2;
}
if($num1-$num2 >=1 and $line[$info{1}]>0.6 and ($line[$info{1}]-$line[$info{2}])>0.1){
print "$line[0]\t$line[1]\t$line[2]\t$line[3]\t$line[4]\t$line[$info{1}-4]\t$line[$info{2}-4]\t$line[$info{3}-4]\t$line[$info{4}-4]\t$line[$info{1}]\t$line[$info{2}]\t$line[$info{3}]\t$line[$info{4}]\t$line[$info{1}-4]\n";
}elsif($num2-$num3 >=1 and $line[$info{2}]>0.6 and ($line[$info{1}]-$line[$info{2}])<=0.1 and $id1 eq $id2 and ($line[$info{1}]-$line[$info{3}])>0.1){
print "$line[0]\t$line[1]\t$line[2]\t$line[3]\t$line[4]\t$line[$info{1}-4]\t$line[$info{2}-4]\t$line[$info{3}-4]\t$line[$info{4}-4]\t$line[$info{1}]\t$line[$info{2}]\t$line[$info{3}]\t$line[$info{4}]\t","0-$id1\n";
}else{
print "$line[0]\t$line[1]\t$line[2]\t$line[3]\t$line[4]\t$line[$info{1}-4]\t$line[$info{2}-4]\t$line[$info{3}-4]\t$line[$info{4}-4]\t$line[$info{1}]\t$line[$info{2}]\t$line[$info{3}]\t$line[$info{4}]\t-\n";
}
}
close $fileh;
}
`rm *.tmp`;