forked from PASApipeline/PASApipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverlapping_nucs.ph
executable file
·61 lines (43 loc) · 1.11 KB
/
overlapping_nucs.ph
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
#!/usr/local/bin/perl
####
sub nucs_in_common {
my ($e5, $e3, $g5, $g3) = @_;
($e5, $e3) = sort {$a<=>$b} ($e5, $e3);
($g5, $g3) = sort {$a<=>$b} ($g5, $g3);
unless (&coordsets_overlap([$e5,$e3], [$g5, $g3])) {
return(0);
}
my $length = abs ($e3 - $e5) + 1;
my $diff1 = ($e3 - $g3);
$diff1 = ($diff1 > 0) ? $diff1 : 0;
my $diff2 = ($g5 - $e5);
$diff2 = ($diff2 > 0) ? $diff2 : 0;
my $overlap_length = $length - $diff1 - $diff2;
return ($overlap_length);
}
####
sub coordsets_overlap {
my ($coordset_A_aref, $coordset_B_aref) = @_;
my ($lend_A, $rend_A) = sort {$a<=>$b} @$coordset_A_aref;
my ($lend_B, $rend_B) = sort {$a<=>$b} @$coordset_B_aref;
if ($lend_A <= $rend_B && $rend_A >= $lend_B) {
## yes, overlap
return (1);
}
else {
return (0);
}
}
####
sub coordset_A_encapsulates_B {
my ($coordset_A_aref, $coordset_B_aref) = @_;
my ($lend_A, $rend_A) = sort {$a<=>$b} @$coordset_A_aref;
my ($lend_B, $rend_B) = sort {$a<=>$b} @$coordset_B_aref;
if ($lend_A <= $lend_B && $rend_B <= $rend_A) {
return(1); # true
}
else {
return(0); # false;
}
}
1;