-
Notifications
You must be signed in to change notification settings - Fork 0
/
distance2TSS.pl
76 lines (61 loc) · 1.09 KB
/
distance2TSS.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
#!/usr/bin/perl
use warnings;
use strict;
if(@ARGV<1)
{
print "Usage perl $0 <TSS start> <peaks region>\n";
print "<TSS start formate>\n";
print "chr start_position end_position \n";
print "<peaks regions formate>\n";
print "chr start_position end_position other_inform\n";
exit;
}
my %hash_peaks;
my @Tss;
open IN, "$ARGV[0]" or die "can not open $ARGV[0]\n";
while(<IN>)
{
chomp;
push @Tss, $_;
}
close IN;
open P,"$ARGV[1]" or die "can not open $ARGV[1]\n";
while(<P>)
{
chomp;
my @a=split;
my $peak_s=$a[1];
my $peak_e=$a[2];
my ($distan_s,$gene_s)=&min_dist($peak_s,@Tss);
my ($distan_e,$gene_e)=&min_dist($peak_e,@Tss);
if($distan_s<$distan_e)
{
print $_,"\t",$distan_s,"\t",$gene_s,"\n";
}
else
{
print $_,"\t",$distan_e,"\t",$gene_e,"\n";
}
}
1;
sub min_dist {
my $peak=shift;
my @tss=@_;
my $min_dis_c=10000000000;
my $gene="";
for (my $i=0;$i<=$#tss;$i++)
{
my @a=split(/\t/,$tss[$i]);
my $distanc=abs($a[1]-$peak);
if($distanc<$min_dis_c)
{
$min_dis_c=$distanc;
$gene=$a[2];
}
else
{
next;
}
}
return($min_dis_c,$gene);
}