-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDeal_solar_multi.pl
135 lines (108 loc) · 3.13 KB
/
Deal_solar_multi.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
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
($F_in,$F_out_best,$F_out_best_tab) = @ARGV;
#0610007F03 524 1 504 - chr5 0 10727208 161651071 6 378 1,134;132,155;154,318;317,389;435,480;484,504; 161650935,161651071;161646457,161646480;161645591,161645755;161643035,161643107;161642944,161642990;10727208,10727228;
#NM_024406 133 62 131 + chrX_random 1719168 992811 993017 1 50 62,131; 992811,993017; +50;
#BC058192,1 1980 1 1980 + NM_023898 371353 91979 94590 2 1636 1,1533;1239,1980; 91979,93526;93832,94590; +1275;+606;
open(I,$F_in);
open(OB,">$F_out_best");
open(OT,">$F_out_best_tab");
while(<I>)
{
@tmp = ();
$size0 = 0;
$rough = 0;
chomp;
@temp = split(/\s+/,$_);
$name = $temp[0];
$length = $temp[1];
$exact = $temp[10];
chop($temp[11]);
@tmp = split(/[\,\;]/,$temp[11]);
for($i=0;$i<$#tmp;$i+=2)
{
$size0 += $tmp[$i+1] - $tmp[$i] + 1; #$size0是各个片断的总长,含有overlap的
}
unshift(@tmp,"1");
@tmp = &cat(@tmp);
#print "@tmp\n";
for($i=0;$i<$#tmp;$i+=2)
{
$rough += $tmp[$i+1] - $tmp[$i] + 1; #去除每个片段overlap的比到的实际长度
}
$over = $size0 - $rough; #overlap的大小
#$exact = $exact - $over; #去除overlap的实际的精确比到的长度
my @match_len=split /;/,$temp[13];
$match_total=0;
for ($i=0;$i<=@match_len-1 ;$i++) {
#print ">>>>>>>",$match_len[$i],"\n";
$match_len[$i]=~s/\+//;
$match_len[$i]=~s/-//;
#print $match_len[$i],"\n";
$match_total+=$match_len[$i];
}
$cutoff = int($rough/$length*10000)/100;
$identity = int($exact/$rough*10000)/100;
#$identity_lixin=int($match_total/$size0*10000)/100;
#if ($match_total!=$temp[10]) {$identity=$identity_lixin;}
#print "$match_total\t$identity\t$identity_lixin\n";
#大于比对要求的都留下
if (($cutoff>70 and $identity>50) ) {
print OB "$_\n";
print OT "$tmp[0]\t$rough\t$cutoff\t$identity\n";
}
}
close(I);
close(OB);
close(OT);
sub cat
#function:quit redundance
#input:($para,@array), para is the merge length
#output:(@array),
#for example (0,1,3,4,7,5,8)->(1,3,4,8) (1,1,3,4,7,5,8)->(1,8)
{
my($merge,@input) = @_;
my $i = 0;
my @output = ();
my %hash = ();
my $each = 0;
my $begin = "";
my $end = 0;
my $Qb = 0;
my $Qe = 0;
my $temp = 0;
for ($i=0;$i<=@input;$i+=2)
{
$Qb = $input[$i];
$Qe = $input[$i+1];
if($Qb > $Qe) { $temp = $Qb; $Qb = $Qe; $Qe = $temp; }
if(defined($hash{$Qb})) { if($hash{$Qb} < $Qe) { $hash{$Qb} = $Qe; } }
else { $hash{$Qb} = $Qe; }
$Qb = 0;
}
foreach $each (sort {$a <=> $b} keys %hash)
{
if($begin eq "")
{
$begin = $each;
$end = $hash{$each};
}
else
{
if($hash{$each} > $end)
{
if($each > $end + $merge)
{
push(@output,$begin);
push(@output,$end);
$begin = $each;
$end = $hash{$each};
}
else { $end = $hash{$each}; }
}
}
}
push(@output,$begin);
push(@output,$end);
%hash = ();
return(@output);
}
exit;