GenOO/Region.pm

filter: Statementstmt 81.5% 75 / 92 Branchbran 78.2% 36 / 46 Conditioncond 73.5% 39 / 53 MC/DCmcdc 54.1% 13 / 24 Subroutinesub 83.3% 20 / 24 Podpod 0.0% 0 / 20 totaltotal 70.6% 183 / 259 CC 44 SCAR 17.1
CC
44
Cov
79%
_to_string_bed
20.0
overlaps_with_offset
8.0
contains
7.3
CRAP 5.5
« GenOO/Data/File/SAM/MDZ.pm ↑ Summary GenOO/RegionCollection/Type/DBIC.pm »
1 # POD documentation - main docs before the code
2  
3 =head1 NAME
4  
5 GenOO::Region - Role that represents a region on a reference sequence
6  
7 =head1 SYNOPSIS
8  
9 This role when consumed requires specific attributes and provides
10 methods that correspond to a region on a reference sequence.
11  
12 =head1 DESCRIPTION
13  
14 A region object is an area on another reference sequence. It has a
15 specific start and stop position on the reference and a specific
16 direction (strand). It has methods that combine the direction with
17 the positional information a give positions for the head or the tail
18 of the region. It also offers methods that calculate distances or
19 overlaps with other object that also consume the role.
20  
21 =head1 EXAMPLES
22  
23 # Get the location information on the reference sequence
24 $obj_with_role->start; # 10
25 $obj_with_role->stop; # 20
26 $obj_with_role->strand; # -1
27
28 # Get the head position on the reference sequence
29 $obj_with_role->head_position; # 20
30  
31 =cut
32  
33 # Let the code begin...
34  
35 package GenOO::Region;
36 1 $GenOO::Region::VERSION = '1.4.9';
37  
38 #######################################################################
39 ####################### Load External modules #####################
40 #######################################################################
41 1 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44  
45 #######################################################################
46 ####################### Required attributes #######################
47 #######################################################################
48 1 requires qw(strand rname start stop copy_number);
49  
50  
51 #######################################################################
52 ####################### Interface attributes ######################
53 #######################################################################
54 1 has 'length' => (
55 is => 'ro',
56 builder => '_calculate_length',
57 init_arg => undef,
58 lazy => 1,
59 );
60  
61  
62 #######################################################################
63 ######################## Interface Methods ########################
64 #######################################################################
65 sub location {
66 35 ▶ my ($self) = @_;
Subroutine location: called CC=1 SCAR=0.0
Pod undocumented
67
68 35 return $self->rname . ':' . $self->start . '-' . $self->stop . ':' . $self->strand;
69 }
70  
71 sub strand_symbol {
72 5 ▶ my ($self) = @_;
Subroutine strand_symbol: called CC=4 SCAR=14.0
Pod undocumented
73
74 5 ▶ return undef if !defined $self->strand;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->strand 1 4 5
75
76 4 ▶ if ($self->strand == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->strand == 1) { } 3 1 4
elsif ($self->strand == -1) { } 1 0 1
77 3 return '+';
78 }
79 elsif ($self->strand == -1) {
80 1 return '-';
81 }
82 0 return undef;
83 }
84  
85 sub head_position {
86 44 ▶ my ($self) = @_;
Subroutine head_position: called CC=3 SCAR=11.3
Pod undocumented
87
88 44 ▶ if ($self->strand == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->strand == 1) { } 22 22 44
elsif ($self->strand == -1) { } 22 0 22
89 22 return $self->start;
90 }
91 elsif ($self->strand == -1) {
92 22 return $self->stop;
93 }
94 else {
95 0 return undef;
96 }
97 }
98  
99 sub tail_position {
100 36 ▶ my ($self) = @_;
Subroutine tail_position: called CC=3 SCAR=11.3
Pod undocumented
101
102 36 ▶ if ($self->strand == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->strand == 1) { } 18 18 36
elsif ($self->strand == -1) { } 18 0 18
103 18 return $self->stop;
104 }
105 elsif ($self->strand == -1) {
106 18 return $self->start;
107 }
108 else {
109 0 return undef;
110 }
111 }
112  
113 sub mid_position {
114 33 ▶ my ($self) = @_;
Subroutine mid_position: called CC=1 SCAR=0.0
Pod undocumented
115
116 33 return ($self->start + $self->stop)/2;
117 }
118  
119 sub mid_mid_distance_from {
120 10 ▶ my ($self, $from_locus) = @_;
Subroutine mid_mid_distance_from: called CC=2 SCAR=6.9
Pod undocumented
121
122 10 ▶ die join(' ', 'Comparing relative position for regions on different reference (rname)',$self->rname,'ne',$from_locus->rname)."\n" if ($self->rname ne $from_locus->rname);
Branch: 1 branch
BranchTrueFalseTotal
if $self->rname ne $from_locus->rname 2 8 10
123 8 return ($self->mid_position - $from_locus->mid_position) * $self->strand;
124 }
125  
126 sub mid_head_distance_from {
127 10 ▶ my ($self, $from_locus) = @_;
Subroutine mid_head_distance_from: called CC=2 SCAR=6.9
Pod undocumented
128
129 10 ▶ die join(' ', 'Comparing relative position for regions on different reference (rname)',$self->rname,'ne',$from_locus->rname)."\n" if ($self->rname ne $from_locus->rname);
Branch: 1 branch
BranchTrueFalseTotal
if $self->rname ne $from_locus->rname 2 8 10
130 8 return ($self->mid_position - $from_locus->head_position) * $self->strand;
131 }
132  
133 sub mid_tail_distance_from {
134 0 ▶ my ($self, $from_locus) = @_;
Subroutine mid_tail_distance_from: not called CC=2 SCAR=17.9
Pod undocumented
135
136 0 ▶ die join(' ', 'Comparing relative position for regions on different reference (rname)',$self->rname,'ne',$from_locus->rname)."\n" if ($self->rname ne $from_locus->rname);
Branch: 1 branch
BranchTrueFalseTotal
if $self->rname ne $from_locus->rname 0 0 0
137 0 return ($self->mid_position - $from_locus->tail_position) * $self->strand;
138 }
139  
140 sub head_mid_distance_from {
141 0 ▶ my ($self, $from_locus) = @_;
Subroutine head_mid_distance_from: not called CC=2 SCAR=17.9
Pod undocumented
142
143 0 ▶ die join(' ', 'Comparing relative position for regions on different reference (rname)',$self->rname,'ne',$from_locus->rname)."\n" if ($self->rname ne $from_locus->rname);
Branch: 1 branch
BranchTrueFalseTotal
if $self->rname ne $from_locus->rname 0 0 0
144 0 return ($self->head_position - $from_locus->mid_position) * $self->strand;
145 }
146  
147 sub head_head_distance_from {
148 10 ▶ my ($self, $from_locus) = @_;
Subroutine head_head_distance_from: called CC=2 SCAR=6.9
Pod undocumented
149
150 10 ▶ die join(' ', 'Comparing relative position for regions on different reference (rname)',$self->rname,'ne',$from_locus->rname)."\n" if ($self->rname ne $from_locus->rname);
Branch: 1 branch
BranchTrueFalseTotal
if $self->rname ne $from_locus->rname 2 8 10
151 8 return ($self->head_position - $from_locus->head_position) * $self->strand;
152 }
153  
154 sub head_tail_distance_from {
155 10 ▶ my ($self, $from_locus) = @_;
Subroutine head_tail_distance_from: called CC=2 SCAR=6.9
Pod undocumented
156
157 10 ▶ die join(' ', 'Comparing relative position for regions on different reference (rname)',$self->rname,'ne',$from_locus->rname)."\n" if ($self->rname ne $from_locus->rname);
Branch: 1 branch
BranchTrueFalseTotal
if $self->rname ne $from_locus->rname 2 8 10
158 8 return ($self->head_position - $from_locus->tail_position) * $self->strand;
159 }
160  
161 sub tail_mid_distance_from {
162 0 ▶ my ($self, $from_locus) = @_;
Subroutine tail_mid_distance_from: not called CC=2 SCAR=17.9
Pod undocumented
163
164 0 ▶ die join(' ', 'Comparing relative position for regions on different reference (rname)',$self->rname,'ne',$from_locus->rname)."\n" if ($self->rname ne $from_locus->rname);
Branch: 1 branch
BranchTrueFalseTotal
if $self->rname ne $from_locus->rname 0 0 0
165 0 return ($self->tail_position - $from_locus->mid_position) * $self->strand;
166 }
167  
168 sub tail_head_distance_from {
169 10 ▶ my ($self, $from_locus) = @_;
Subroutine tail_head_distance_from: called CC=2 SCAR=6.9
Pod undocumented
170
171 10 ▶ die join(' ', 'Comparing relative position for regions on different reference (rname)',$self->rname,'ne',$from_locus->rname)."\n" if ($self->rname ne $from_locus->rname);
Branch: 1 branch
BranchTrueFalseTotal
if $self->rname ne $from_locus->rname 2 8 10
172 8 return ($self->tail_position - $from_locus->head_position) * $self->strand;
173 }
174  
175 sub tail_tail_distance_from {
176 10 ▶ my ($self, $from_locus) = @_;
Subroutine tail_tail_distance_from: called CC=2 SCAR=6.9
Pod undocumented
177
178 10 ▶ die join(' ', 'Comparing relative position for regions on different reference (rname)',$self->rname,'ne',$from_locus->rname)."\n" if ($self->rname ne $from_locus->rname);
Branch: 1 branch
BranchTrueFalseTotal
if $self->rname ne $from_locus->rname 2 8 10
179 8 return ($self->tail_position - $from_locus->tail_position) * $self->strand;
180 }
181  
182 sub to_string {
183 2 ▶ my ($self, $params) = @_;
Subroutine to_string: called CC=1 SCAR=0.0
Pod undocumented
184
185 2 return $self->location;
186 }
187  
188 sub overlaps_with_offset {
189 10 ▶ my ($self, $region2, $use_strand, $offset) = @_;
Subroutine overlaps_with_offset: called CC=8 SCAR=20.8
Pod undocumented
190
191 10 ▶ $offset //= 0;
Condition100%2/2
$offset //= 0
l!l
28
MC/DC100%1/1
$offset //= 0
$offset
Truth table100%2/2
A
A= $offset
Aresult
11
00
192 10 ▶ $use_strand //= 1;
Condition100%2/2
$use_strand //= 1
l!l
46
MC/DC100%1/1
$use_strand //= 1
$use_strand
Truth table100%2/2
A
A= $use_strand
Aresult
11
00
193
194 10 ▶ if (($use_strand == 0 or $self->strand == $region2->strand) and ($self->rname eq $region2->rname) and (($self->start-$offset) <= $region2->stop) and ($region2->start <= ($self->stop+$offset))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_strand == 0 || $self->strand == $region2->strand and $self->rname eq $region2->rname and $self->start - $offset <= $region2->stop and $region2->start <= $self->stop + $offset) { } 6 4 10
Condition83%10/12
$use_strand == 0 || $self->strand == $region2->strand and $self->rname eq $region2->rname and $self->start - $offset <= $region2->stop and $region2->start <= $self->stop + $offset
!ll&&!rl&&r
226
$use_strand == 0 || $self->strand == $region2->strand and $self->rname eq $region2->rname and $self->start - $offset <= $region2->stop
!ll&&!rl&&r
208
$use_strand == 0 || $self->strand == $region2->strand and $self->rname eq $region2->rname
!ll&&!rl&&r
208
$use_strand == 0 or $self->strand == $region2->strand
l!l&&r!l&&!r
262
MC/DC60%3/5
$use_strand == 0 || $self->strand == $region2->strand and $self->rname eq $region2->rname and $self->start - $offset <= $region2->stop and $region2->start <= $self->stop + $offset
$use_strand == 0 $self->strand == $region2->strand $self->rname eq $region2->rname $self->start - $offset <= $region2->stop $region2->start <= $self->stop + $offset
Truth table44%4/9
A or B and C and D and E
A= $use_strand == 0B= $self->strand == $region2->strandC= $self->rname eq $region2->rnameD= $self->start - $offset <= $region2->stopE= $region2->start <= $self->stop + $offset
ABCDEresult
00XXX0
1X0XX0
010XX0
1X10X0
0110X0
1X1100
011100
1X1111
011111
195 6 return 1; #overlap
196 }
197 else {
198 4 return 0; #no overlap
199 }
200 }
201  
202 sub overlaps {
203 46 ▶ my ($self, $region2, $use_strand) = @_;
Subroutine overlaps: called CC=7 SCAR=19.5
Pod undocumented
204
205 46 ▶ $use_strand //= 1;
Condition100%2/2
$use_strand //= 1
l!l
2422
MC/DC100%1/1
$use_strand //= 1
$use_strand
Truth table100%2/2
A
A= $use_strand
Aresult
11
00
206
207 46 ▶ if (($use_strand == 0 or $self->strand == $region2->strand) and ($self->rname eq $region2->rname) and ($self->start <= $region2->stop) and ($region2->start <= $self->stop)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_strand == 0 || $self->strand == $region2->strand and $self->rname eq $region2->rname and $self->start <= $region2->stop and $region2->start <= $self->stop) { } 33 13 46
Condition83%10/12
$use_strand == 0 || $self->strand == $region2->strand and $self->rname eq $region2->rname and $self->start <= $region2->stop and $region2->start <= $self->stop
!ll&&!rl&&r
9433
$use_strand == 0 || $self->strand == $region2->strand and $self->rname eq $region2->rname and $self->start <= $region2->stop
!ll&&!rl&&r
9037
$use_strand == 0 || $self->strand == $region2->strand and $self->rname eq $region2->rname
!ll&&!rl&&r
9037
$use_strand == 0 or $self->strand == $region2->strand
l!l&&r!l&&!r
2359
MC/DC60%3/5
$use_strand == 0 || $self->strand == $region2->strand and $self->rname eq $region2->rname and $self->start <= $region2->stop and $region2->start <= $self->stop
$use_strand == 0 $self->strand == $region2->strand $self->rname eq $region2->rname $self->start <= $region2->stop $region2->start <= $self->stop
Truth table44%4/9
A or B and C and D and E
A= $use_strand == 0B= $self->strand == $region2->strandC= $self->rname eq $region2->rnameD= $self->start <= $region2->stopE= $region2->start <= $self->stop
ABCDEresult
00XXX0
1X0XX0
010XX0
1X10X0
0110X0
1X1100
011100
1X1111
011111
208 33 return 1; #overlap
209 }
210 else {
211 13 return 0; #no overlap
212 }
213 }
214  
215 sub overlap_length {
216 8 ▶ my ($self, $region2) = @_;
Subroutine overlap_length: called CC=4 SCAR=13.9
Pod undocumented
217
218 8 ▶ if ($self->overlaps($region2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->overlaps($region2)) { } 4 4 8
219 4 ▶ my $max_start = $self->start > $region2->start ? $self->start : $region2->start;
Branch: 1 branch
BranchTrueFalseTotal
$self->start > $region2->start ? : 2 2 4
220 4 ▶ my $min_stop = $self->stop < $region2->stop ? $self->stop : $region2->stop;
Branch: 1 branch
BranchTrueFalseTotal
$self->stop < $region2->stop ? : 0 4 4
221 4 return $min_stop - $max_start + 1 ;
222 }
223 else {
224 4 return 0;
225 }
226 }
227  
228 sub contains {
229 12 ▶ my ($self, $region2, $use_strand) = @_;
Subroutine contains: called CC=7 SCAR=19.9
Pod undocumented
230
231 12 ▶ $use_strand //= 1;
Condition50%1/2
$use_strand //= 1
l!l
012
MC/DC0%0/1
$use_strand //= 1
$use_strand
Truth table50%1/2
A
A= $use_strand
Aresult
11
00
232
233 12 ▶ if (($use_strand == 0 or $self->strand == $region2->strand) and ($self->rname eq $region2->rname) and ($self->start <= $region2->start) and ($region2->stop <= $self->stop)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_strand == 0 || $self->strand == $region2->strand and $self->rname eq $region2->rname and $self->start <= $region2->start and $region2->stop <= $self->stop) { } 4 8 12
Condition75%9/12
$use_strand == 0 || $self->strand == $region2->strand and $self->rname eq $region2->rname and $self->start <= $region2->start and $region2->stop <= $self->stop
!ll&&!rl&&r
804
$use_strand == 0 || $self->strand == $region2->strand and $self->rname eq $region2->rname and $self->start <= $region2->start
!ll&&!rl&&r
444
$use_strand == 0 || $self->strand == $region2->strand and $self->rname eq $region2->rname
!ll&&!rl&&r
408
$use_strand == 0 or $self->strand == $region2->strand
l!l&&r!l&&!r
084
MC/DC40%2/5
$use_strand == 0 || $self->strand == $region2->strand and $self->rname eq $region2->rname and $self->start <= $region2->start and $region2->stop <= $self->stop
$use_strand == 0 $self->strand == $region2->strand $self->rname eq $region2->rname $self->start <= $region2->start $region2->stop <= $self->stop
Truth table33%3/9
A or B and C and D and E
A= $use_strand == 0B= $self->strand == $region2->strandC= $self->rname eq $region2->rnameD= $self->start <= $region2->startE= $region2->stop <= $self->stop
ABCDEresult
00XXX0
1X0XX0
010XX0
1X10X0
0110X0
1X1100
011100
1X1111
011111
234 4 return 1;
235 }
236 else {
237 8 return 0;
238 }
239 }
240  
241 sub contains_position {
242 22 ▶ my ($self, $position) = @_;
Subroutine contains_position: called CC=3 SCAR=11.0
Pod undocumented
243
244 22 ▶ if (($self->start <= $position) and ($position <= $self->stop)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->start <= $position and $position <= $self->stop) { } 7 15 22
Condition100%3/3
$self->start <= $position and $position <= $self->stop
!ll&&!rl&&r
1327
MC/DC100%2/2
$self->start <= $position and $position <= $self->stop
$self->start <= $position $position <= $self->stop
Truth table100%3/3
A and B
A= $self->start <= $positionB= $position <= $self->stop
ABresult
0X0
100
111
245 7 return 1;
246 }
247 else {
248 15 return 0;
249 }
250 }
251  
252 #######################################################################
253 ######################### Private methods ##########################
254 #######################################################################
255 sub _calculate_length {
256 72 ▶ my ($self) = @_;
Subroutine _calculate_length: called CC=1 SCAR=0.0
257
258 72 return $self->stop - $self->start + 1;
259 }
260  
261 sub _to_string_bed {
262 0 ▶ my ($self) = @_;
Subroutine _to_string_bed: not called CC=4 SCAR=30.0
263
264 0 ▶ my $strand_symbol = $self->strand_symbol || '.';
Condition0%0/2
$self->strand_symbol || '.'
l!l
00
MC/DC0%0/1
$self->strand_symbol || '.'
$self->strand_symbol
Truth table0%0/2
A
A= $self->strand_symbol
Aresult
11
00
265 0 ▶ my $name = $self->name || '.';
Condition0%0/2
$self->name || '.'
l!l
00
MC/DC0%0/1
$self->name || '.'
$self->name
Truth table0%0/2
A
A= $self->name
Aresult
11
00
266 0 ▶ my $score = $self->copy_number || 1;
Condition0%0/2
$self->copy_number || 1
l!l
00
MC/DC0%0/1
$self->copy_number || 1
$self->copy_number
Truth table0%0/2
A
A= $self->copy_number
Aresult
11
00
267
268 0 return $self->rname."\t".$self->start."\t".($self->stop+1)."\t".$name."\t".$score."\t".$strand_symbol;
269 }
270  
271 1 1;
« GenOO/Data/File/SAM/MDZ.pm ↑ Summary GenOO/RegionCollection/Type/DBIC.pm »