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
|
#!/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;
|