-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjuncCluster.pl
executable file
·70 lines (64 loc) · 2.16 KB
/
juncCluster.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
#!/bin/env perl
=hey
Author: Shijian Sky Zhang
E-mail: zhangsjsky@pku.edu.cn
=cut
use 5.010;
use warnings;
use strict;
use Getopt::Long;
use File::Basename;
sub usage{
my $scriptName = basename $0;
print <<HELP;
Usage: cat *.junction.bed | perl $scriptName >clustered.bed
Option:
-h --help Print this help information
HELP
}
GetOptions(
'h|help' => sub{usage(); exit}
) || usage();
my %junction;
while(<>){
chomp;
my @fields = split "\t";
my ($chr, $start, $end, $score, $strand) = @fields[0, 1, 2, 4, 5];
my @blockSizes = split ",", $fields[10];
my $junctionStart = $start + $blockSizes[0];
my $junctionEnd = $end - $blockSizes[1];
if(exists $junction{"$chr:$strand:$junctionStart:$junctionEnd"}){
$junction{"$chr:$strand:$junctionStart:$junctionEnd"}{score} += $score;
if ($start < $junction{"$chr:$strand:$junctionStart:$junctionEnd"}{leftBoundary}){
$junction{"$chr:$strand:$junctionStart:$junctionEnd"}{leftBoundary} = $start
}
if ($end > $junction{"$chr:$strand:$junctionStart:$junctionEnd"}{rightBoundary}){
$junction{"$chr:$strand:$junctionStart:$junctionEnd"}{rightBoundary} = $end
}
}else{
$junction{"$chr:$strand:$junctionStart:$junctionEnd"}{score} = $score;
$junction{"$chr:$strand:$junctionStart:$junctionEnd"}{leftBoundary} = $start;
$junction{"$chr:$strand:$junctionStart:$junctionEnd"}{rightBoundary} = $end;
}
}
while(my ($key, $value) = each %junction){
my ($chr, $strand, $junctionStart, $junctionEnd) = split ':', $key;
my $start = $value->{leftBoundary};
my $end = $value->{rightBoundary};
my $score = $value->{score};
my $blockSizes = ($junctionStart - $start) . ',' . ($end - $junctionEnd);
my $blockStarts = '0,'.($junctionEnd - $start);
say join "\t",($chr,
$start,
$end,
"$chr:$junctionStart-$junctionEnd:$score",
$score,
$strand,
$start,
$end,
'0,0,0',
2,
$blockSizes,
$blockStarts
);
}