forked from PASApipeline/PASApipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTierFeatures.pm
executable file
·129 lines (90 loc) · 2.59 KB
/
TierFeatures.pm
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
package TierFeatures;
use strict;
use warnings;
sub new {
my $packagename = shift;
my $self = { tiers => [ [] ], # give it one empty tier to start
overlap_routine => undef, # will set default shortly....
};
bless ($self, $packagename);
$self->_set_default_overlap_routine();
return ($self);
}
sub tier_features {
my $self = shift;
my @features = @_;
## start at first tier:
foreach my $feature (@features) {
my ($feat_lend, $feat_rend) = ($feature->{lend}, $feature->{rend});
my @tiers = @{$self->{tiers}};
my $tiered_feature_flag = 0;
tiers:
foreach my $tier (@tiers) {
my @tiered_feats = @$tier;
feats:
foreach my $feat (@tiered_feats) {
#my ($lend, $rend) = ($feat->{lend}, $feat->{rend});
# check for overlap
if ($self->{overlap_routine}($feature, $feat) ) {
#$lend <= $feat_rend && $rend >= $feat_lend) {
# got overlap
next tiers;
}
}
# if got here, no overlap in current tier. Just add it:
push (@$tier, $feature);
$tiered_feature_flag = 1;
last tiers;
}
unless ($tiered_feature_flag) {
# no current tier can accommodate it. Add another tier with this element
push (@{$self->{tiers}}, [$feature]);
}
}
## return tiers:
return (@{$self->{tiers}});
}
####
sub _set_default_overlap_routine {
my $self = shift;
my $overlap_routine = sub {
my ($featureA, $featureB) = @_;
my ($featureA_lend, $featureA_rend) = ($featureA->{lend}, $featureA->{rend});
my ($featureB_lend, $featureB_rend) = ($featureB->{lend}, $featureB->{rend});
if ($featureA_lend <= $featureB_rend
&&
$featureA_rend >= $featureB_lend) {
return(1);
}
else {
return(0);
}
};
$self->set_overlap_routine($overlap_routine);
return;
}
####
sub set_overlap_routine {
my $self = shift;
my $overlap_routine = shift;
$self->{overlap_routine} = $overlap_routine;
return;
}
##################################
package TierFeatures::Feature;
use strict;
use warnings;
sub new {
my $packagename = shift;
my ($lend, $rend, $feat_id) = @_;
if ($lend > $rend) {
($lend, $rend) = ($rend, $lend);
}
my $self = { lend => $lend,
rend => $rend,
feat_id => $feat_id,
};
bless ($self, $packagename);
return ($self);
}
1; #EOM