-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfusion2link.pl
More file actions
executable file
·212 lines (184 loc) · 4.97 KB
/
Copy pathfusion2link.pl
File metadata and controls
executable file
·212 lines (184 loc) · 4.97 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
use strict;
#use lib '/ifs/home/c2b2/ac_lab/rs3412/cpan/lib/perl5/site_perl/5.10.0';
use Statistics::Basic qw(:all nofill);
my $fusion = shift;
my $samples = shift;
my $task = shift;
my %need;
foreach my $need ( split(',',$samples) ) {
$need{$need} = '';
}
my %fusions;
my %genePrinted;
open IN, "$fusion";
#my $id = 1;
while ( <IN> ) {
next if /^#/;
chomp;
my ($rna, $dna, $gene1, $gene2, $bp1, $bp2, $dir, $rep, $sc, $type, $strand, $cov1, $cov2, $cov3, $cov4, $cov5, $contigs, $gbp1, $gbp2) = split /\t/;
my $sample = $dna;
my $g1;
my $g2;
if ($sample =~ /\w+/){
next if (!exists($need{$sample}));
$gene1 =~ /^(\w+?)\((.+?)\)$/;
$g1 = $2;
} elsif ($gene1 =~ /(AC\d+)\.fusion\.report\:(\w+?)\((.+?)\)$/) {
$sample = $1;
next if (!exists($need{$sample}));
$g1 = $3;
} elsif ($gene1 =~ /(AC\d+)\.fusion\.report\:IGR$/) {
$sample = $1;
next if (!exists($need{$sample}));
$g1 = 'IGR';
} else {
print STDERR "wierd gene name: $gene1\n";
exit 22;
}
if ($gene2 =~ /^(\w+?)\((.+?)\)$/) {
$g2 = $2;
} elsif ($gene2 eq 'IGR') {
$g2 = 'IGR';
} else {
print STDERR "wierd gene name: $gene2\n";
exit 22;
}
#print STDERR "$sample\t$g1\t$g2\n";
if (($g2 ne 'IGR' and $g1 =~ /$g2/) or ($g1 ne 'IGR' and $g2 =~ /$g1/)) {
next;
}
if (($g1 eq 'TMPRSS3' and $g2 eq 'DSCAM') or ($g2 eq 'TMPRSS3' and $g1 eq 'DSCAM')) {
next;
}
if (($g1 =~ /^IGK[JV]/ or $g2 =~ /^IGK[JV]/) and $sc eq 'CC') {
next;
}
if ($g1 =~ /^RP\d+\-/ or $g2 =~ /^RP\d+\-/) {
next;
}
if (($g1 eq 'IGR' and $g2 =~ /^RP\d+\-\d+/) or ($g2 eq 'IGR' and $g1 =~ /^RP\d+\-\d+/)){
next;
}
if (($g1 =~ /^$g2/ or $g2 =~ /^$g1/) and $sc eq 'CC') {
next;
}
if ($rep =~ /R/ and $sc =~ /C/) {
next;
}
if ($cov5 <= 1.5){
next;
}
if ($cov5 < 2 and $sc eq 'CC'){
next;
}
if ($cov4/$cov5 >= 10 and $cov5 <= 3) {
next;
}
if ($cov4/$cov5 >= 20 and $cov5 < 10) {
next;
}
#if ($sc eq 'CC') {
# next;
#}
if ($cov3 < 2) {
next;
}
#my $options = "thickness=$cov5";
my $options = "color=wblacktrans";
$bp1 =~ /^(.+?)\:(\d+)$/;
my $chr1 = $1;
my $pos1 = $2;
$chr1 =~ s/^chr//;
$chr1 = 'hs'.$chr1;
$bp2 =~ /^(.+?)\:(\d+)$/;
my $chr2 = $1;
my $pos2 = $2;
$chr2 =~ s/^chr//;
$chr2 = 'hs'.$chr2;
if ($chr1 eq $chr2 and abs($pos1 - $pos2) < 500000) {
next;
}
my $key = join("\t", sort {$a cmp $b} ($g1, $g2));
$fusions{$key}{$sample}{'support'} = $cov5;
$fusions{$key}{$sample}{'expression'} = $cov4;
$fusions{$key}{$sample}{'coor'} = "$chr1 $pos1 $pos1 $chr2 $pos2 $pos2";
if ($task ne 'merge') {
if ($task eq 'original') {
print "$_\n";
next;
}
my $rsup = round($cov5);
my @coors;
push(@coors, $chr1);
push(@coors, $pos1);
push(@coors, $pos1);
push(@coors, $chr2);
push(@coors, $pos2);
push(@coors, $pos2);
$coors[1] -= ($coors[1] > ($rsup*800000))? $rsup*800000 : ($coors[1]-1);
$coors[2] += $rsup*800000;
$coors[4] -= ($coors[4] > ($rsup*800000))? $rsup*800000 : ($coors[4]-1);
$coors[5] += $rsup*800000;
my $coorprint = join(' ', @coors);
print "$coorprint $options\n";
if (!exists($genePrinted{$g1})) {
print STDERR "$chr1 $pos1 $pos1 $g1\n";
$genePrinted{$g1} = "yes";
}
if (!exists($genePrinted{$g2})) {
print STDERR "$chr2 $pos2 $pos2 $g2\n";
$genePrinted{$g2} = "yes";
}
#print "$chr1 $pos1 $pos1 ";
#print "$chr2 $pos2 $pos2 $options\n";
}
}
close IN;
if ( $task eq 'merge' ) {
foreach my $fusion (keys %fusions){
my $samps;
my @supports;
my @expressions;
my $coor;
foreach my $samp (keys %{$fusions{$fusion}}) {
$samps .= $samp."\t";
push(@supports, $fusions{$fusion}{$samp}{'support'});
push(@expressions, $fusions{$fusion}{$samp}{'expression'});
if ($coor eq ''){
$coor = $fusions{$fusion}{$samp}{'coor'};
}
}
my $recur = scalar(keys %{$fusions{$fusion}});
my $support = sprintf("%.1f", mean(@supports));
my $expression = sprintf("%.1f", mean(@expressions));
#print STDERR "$fusion\t$recur\t$samps\t$support\t$expression\n";
my $rsup = round($support);
#$rsup .= 'p,';
#my $options = "thickness=$rsup";
my @coors = split (/\s/, $coor);
$coors[1] -= ($coors[1] > ($rsup*800000))? $rsup*800000 : ($coors[1]-1);
$coors[2] += $rsup*800000;
$coors[4] -= ($coors[4] > ($rsup*800000))? $rsup*800000 : ($coors[4]-1);
$coors[5] += $rsup*800000;
$coor = join(' ', @coors);
my $options;
if ($recur > 6) {
$options .= "color=dturquoisetrans";
} elsif ($recur >= 2) {
$options .= "color=turquoisetrans";
} elsif ($recur == 1) {
$options .= "color=wblacktrans";
} else {
$options .= "color=vwblacktrans";
}
print "$coor $options\n";
}
} #merge for circos
sub round {
my $number = shift;
my $tmp = int($number);
if ($number >= ($tmp+0.5)){
$tmp++;
}
return $tmp;
}