Bio/Location/Simple.pm

filter: Statementstmt 68.4% 50 / 73 Branchbran 78.9% 30 / 38 Conditioncond 76.9% 30 / 39 MC/DCmcdc 35.0% 7 / 20 Subroutinesub 88.8% 8 / 9 Podpod 100% 7 / 7 totaltotal 70.9% 132 / 186 CC 33 SCAR 21.8
CC
33
Cov
73%
end
12.3
location_type
12.1
trunc
12.0
CRAP 8.8
« Bio/Matrix/IO.pm ↑ Summary Bio/SearchIO/Writer/HitTableWriter.pm »
1 #
2 # BioPerl module for Bio::Location::Simple
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
4 #
5 # Cared for by Heikki Lehvaslaiho <heikki-at-bioperl-dot-org>
6 #
7 # Copyright Heikki Lehvaslaiho
8 #
9 # You may distribute this module under the same terms as perl itself
10 # POD documentation - main docs before the code
11  
12 =head1 NAME
13  
14 Bio::Location::Simple - Implementation of a Simple Location on a Sequence
15  
16 =head1 SYNOPSIS
17  
18 use Bio::Location::Simple;
19  
20 my $location = Bio::Location::Simple->new(
21 -start => 1,
22 -end => 100,
23 -strand => 1,
24 );
25  
26 if( $location->strand == -1 ) {
27 printf "complement(%d..%d)\n", $location->start, $location->end;
28 } else {
29 printf "%d..%d\n", $location->start, $location->end;
30 }
31  
32 =head1 DESCRIPTION
33  
34 This is an implementation of Bio::LocationI to manage exact location
35 information on a Sequence: '22' or '12..15' or '16^17'.
36  
37 You can test the type of the location using length() function () or
38 directly location_type() which can one of two values: 'EXACT' or
39 'IN-BETWEEN'.
40  
41  
42 =head1 FEEDBACK
43  
44 User feedback is an integral part of the evolution of this and other
45 Bioperl modules. Send your comments and suggestions preferably to one
46 of the Bioperl mailing lists. Your participation is much appreciated.
47  
48 bioperl-l@bioperl.org - General discussion
49 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
50  
51 =head2 Support
52  
53 Please direct usage questions or support issues to the mailing list:
54  
55 I<bioperl-l@bioperl.org>
56  
57 rather than to the module maintainer directly. Many experienced and
58 reponsive experts will be able look at the problem and quickly
59 address it. Please include a thorough description of the problem
60 with code and data examples if at all possible.
61  
62 =head2 Reporting Bugs
63  
64 Report bugs to the Bioperl bug tracking system to help us keep track
65 the bugs and their resolution. Bug reports can be submitted via the
66 web:
67  
68 https://github.com/bioperl/bioperl-live/issues
69  
70 =head1 AUTHOR - Heikki Lehvaslaiho
71  
72 Email heikki-at-bioperl-dot-org
73  
74 =head1 APPENDIX
75  
76 The rest of the documentation details each of the object
77 methods. Internal methods are usually preceded with a _
78  
79 =cut
80  
81 # Let the code begin...
82  
83  
84 package Bio::Location::Simple;
85 324 $Bio::Location::Simple::VERSION = '1.7.8';
86 324 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 324 ▶use base qw(Bio::Location::Atomic);
Subroutine BEGIN: called CC=1 SCAR=0.0
89  
90 324 our %RANGEENCODE = ('\.\.' => 'EXACT',
91 '\^' => 'IN-BETWEEN' );
92  
93 324 our %RANGEDECODE = ('EXACT' => '..',
94 'IN-BETWEEN' => '^' );
95  
96 55409 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
97 55409 my ($class, @args) = @_;
98 55409 my $self = $class->SUPER::new(@args);
99  
100 55409 my ($locationtype) = $self->_rearrange([qw(LOCATION_TYPE)],@args);
101  
102 55409 ▶ $locationtype && $self->location_type($locationtype);
Branch: 1 branch
BranchTrueFalseTotal
$locationtype and $self->location_type($locationtype) 41038 14371 55409
103  
104 55408 return $self;
105 }
106  
107 =head2 start
108  
109 Title : start
110 Usage : $start = $loc->start();
111 Function: get/set the start of this range
112 Returns : the start of this range
113 Args : optionally allows the start to be set
114 using $loc->start($start)
115  
116 =cut
117  
118 341236 ▶sub start {
Subroutine start: called CC=6 SCAR=18.0
Pod documented
119 341236 my ($self, $value) = @_;
120 341236 ▶ $self->{'_start'} = $value if defined $value ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 71913 269323 341236
121
122 $self->throw("Only adjacent residues when location type ".
123 "is IN-BETWEEN. Not [". $self->{'_start'}. "] and [".
124 $self->{'_end'}. "]" )
125 if defined $self->{'_start'} && defined $self->{'_end'} &&
126 $self->location_type eq 'IN-BETWEEN' &&
127 341236 ▶ ($self->{'_end'} - 1 != $self->{'_start'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_start"} and defined $self->{"_end"} and $self->location_type eq "IN-BETWEEN" and $self->{"_end"} - 1 != $self->{"_start"} 0 341236 341236
Condition88%8/9
defined $self->{"_start"} and defined $self->{"_end"} and $self->location_type eq "IN-BETWEEN" and $self->{"_end"} - 1 != $self->{"_start"}
!ll&&!rl&&r
341220160
defined $self->{"_start"} and defined $self->{"_end"} and $self->location_type eq "IN-BETWEEN"
!ll&&!rl&&r
6925927196116
defined $self->{"_start"} and defined $self->{"_end"}
!ll&&!rl&&r
1419555064271977
MC/DC0%0/4
defined $self->{"_start"} and defined $self->{"_end"} and $self->location_type eq "IN-BETWEEN" and $self->{"_end"} - 1 != $self->{"_start"}
defined $self->{"_start"} defined $self->{"_end"} $self->location_type eq "IN-BETWEEN" $self->{"_end"} - 1 != $self->{"_start"}
Truth table80%4/5
A and B and C and D
A= defined $self->{"_start"}B= defined $self->{"_end"}C= $self->location_type eq "IN-BETWEEN"D= $self->{"_end"} - 1 != $self->{"_start"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
128 341236 return $self->{'_start'};
129 }
130  
131  
132 =head2 end
133  
134 Title : end
135 Usage : $end = $loc->end();
136 Function: get/set the end of this range
137 Returns : the end of this range
138 Args : optionally allows the end to be set
139 : using $loc->end($start)
140 Note : If start is set but end is undefined, this now assumes that start
141 is the same as end but throws a warning (i.e. it assumes this is
142 a possible error). If start is undefined, this now throws an
143 exception.
144  
145 =cut
146  
147 326887 ▶sub end {
Subroutine end: called CC=8 SCAR=25.1
Pod documented
148 326887 my ($self, $value) = @_;
149
150 326887 ▶ $self->{'_end'} = $value if defined $value ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 71909 254978 326887
151
152 # Assume end is the same as start if not defined
153 326887 ▶ if (!defined $self->{'_end'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_end"}) 0 326887 326887
154 0 ▶ if (!defined $self->{'_start'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_start"}) 0 0 0
155 0 $self->warn('Can not set Bio::Location::Simple::end() equal to start; start not set');
156 0 return;
157 }
158 0 $self->warn('Setting end to equal start['. $self->{'_start'}. ']');
159 0 $self->{'_end'} = $self->{'_start'};
160 }
161 $self->throw("Only adjacent residues when location type ".
162 "is IN-BETWEEN. Not [". $self->{'_start'}. "] and [".
163 $self->{'_end'}. "]" )
164 if defined $self->{'_start'} && defined $self->{'_end'} &&
165 $self->location_type eq 'IN-BETWEEN' &&
166 326887 ▶ ($self->{'_end'} - 1 != $self->{'_start'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_start"} and defined $self->{"_end"} and $self->location_type eq "IN-BETWEEN" and $self->{"_end"} - 1 != $self->{"_start"} 0 326887 326887
Condition77%7/9
defined $self->{"_start"} and defined $self->{"_end"} and $self->location_type eq "IN-BETWEEN" and $self->{"_end"} - 1 != $self->{"_start"}
!ll&&!rl&&r
326873140
defined $self->{"_start"} and defined $self->{"_end"} and $self->location_type eq "IN-BETWEEN"
!ll&&!rl&&r
7532679814
defined $self->{"_start"} and defined $self->{"_end"}
!ll&&!rl&&r
750326812
MC/DC0%0/4
defined $self->{"_start"} and defined $self->{"_end"} and $self->location_type eq "IN-BETWEEN" and $self->{"_end"} - 1 != $self->{"_start"}
defined $self->{"_start"} defined $self->{"_end"} $self->location_type eq "IN-BETWEEN" $self->{"_end"} - 1 != $self->{"_start"}
Truth table60%3/5
A and B and C and D
A= defined $self->{"_start"}B= defined $self->{"_end"}C= $self->location_type eq "IN-BETWEEN"D= $self->{"_end"} - 1 != $self->{"_start"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
167
168 326887 return $self->{'_end'};
169 }
170  
171 =head2 strand
172  
173 Title : strand
174 Usage : $strand = $loc->strand();
175 Function: get/set the strand of this range
176 Returns : the strandedness (-1, 0, +1)
177 Args : optionally allows the strand to be set
178 : using $loc->strand($strand)
179  
180 =cut
181  
182 =head2 length
183  
184 Title : length
185 Usage : $len = $loc->length();
186 Function: get the length in the coordinate space this location spans
187 Example :
188 Returns : an integer
189 Args : none
190  
191 =cut
192  
193 9 ▶sub length {
Subroutine length: called CC=2 SCAR=6.9
Pod documented
194 9 my ($self) = @_;
195 9 ▶ if ($self->location_type eq 'IN-BETWEEN' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->location_type eq 'IN-BETWEEN') { } 1 8 9
196 1 return 0;
197 } else {
198 8 return abs($self->end - $self->start) + 1;
199 }
200 }
201  
202  
203 =head2 min_start
204  
205 Title : min_start
206 Usage : my $minstart = $location->min_start();
207 Function: Get minimum starting location of feature startpoint
208 Returns : integer or undef if no minimum starting point.
209 Args : none
210  
211 =cut
212  
213 =head2 max_start
214  
215 Title : max_start
216 Usage : my $maxstart = $location->max_start();
217 Function: Get maximum starting location of feature startpoint.
218  
219 In this implementation this is exactly the same as min_start().
220  
221 Returns : integer or undef if no maximum starting point.
222 Args : none
223  
224 =cut
225  
226 =head2 start_pos_type
227  
228 Title : start_pos_type
229 Usage : my $start_pos_type = $location->start_pos_type();
230 Function: Get start position type (ie <,>, ^).
231  
232 Returns : type of position coded as text
233 ('BEFORE', 'AFTER', 'EXACT','WITHIN', 'BETWEEN')
234 Args : none
235  
236 =cut
237  
238 =head2 min_end
239  
240 Title : min_end
241 Usage : my $minend = $location->min_end();
242 Function: Get minimum ending location of feature endpoint
243 Returns : integer or undef if no minimum ending point.
244 Args : none
245  
246 =cut
247  
248  
249 =head2 max_end
250  
251 Title : max_end
252 Usage : my $maxend = $location->max_end();
253 Function: Get maximum ending location of feature endpoint
254  
255 In this implementation this is exactly the same as min_end().
256  
257 Returns : integer or undef if no maximum ending point.
258 Args : none
259  
260 =cut
261  
262 =head2 end_pos_type
263  
264 Title : end_pos_type
265 Usage : my $end_pos_type = $location->end_pos_type();
266 Function: Get end position type (ie <,>, ^)
267  
268 Returns : type of position coded as text
269 ('BEFORE', 'AFTER', 'EXACT','WITHIN', 'BETWEEN')
270 Args : none
271  
272 =cut
273  
274 =head2 location_type
275  
276 Title : location_type
277 Usage : my $location_type = $location->location_type();
278 Function: Get location type encoded as text
279 Returns : string ('EXACT' or 'IN-BETWEEN')
280 Args : 'EXACT' or '..' or 'IN-BETWEEN' or '^'
281  
282 =cut
283  
284 640328 ▶sub location_type {
Subroutine location_type: called CC=12 SCAR=24.9
Pod documented
285 640328 my ($self, $value) = @_;
286  
287 640328 ▶ if( defined $value || ! defined $self->{'_location_type'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value or not defined $self->{"_location_type"}) 96174 544154 640328
Condition100%3/3
defined $value or not defined $self->{"_location_type"}
l!l&&r!l&&!r
4103855136544154
MC/DC100%2/2
defined $value or not defined $self->{"_location_type"}
defined $value not defined $self->{"_location_type"}
Truth table100%3/3
A or not(B)
A= defined $valueB= not defined $self->{"_location_type"}
ABresult
1X1
011
000
288 96174 ▶ $value = 'EXACT' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 55136 41038 96174
289 96174 $value = uc $value;
290 96174 ▶ if (! defined $RANGEDECODE{$value}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Bio::Location::Simple::RANGEDECODE{$value}) 41031 55143 96174
291 41031 ▶ $value = '\^' if $value eq '^';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "^" 13 41018 41031
292 41031 ▶ $value = '\.\.' if $value eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq ".." 41018 13 41031
293 41031 $value = $RANGEENCODE{$value};
294 }
295 96174 ▶ $self->throw("Did not specify a valid location type. [$value] is no good")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 96174 96174
296 unless defined $value;
297 96174 $self->{'_location_type'} = $value;
298 }
299 $self->throw("Only adjacent residues when location type ".
300 "is IN-BETWEEN. Not [". $self->{'_start'}. "] and [".
301 $self->{'_end'}. "]" )
302 if $self->{'_location_type'} eq 'IN-BETWEEN' &&
303 defined $self->{'_start'} &&
304 defined $self->{'_end'} &&
305 640328 ▶ ($self->{'_end'} - 1 != $self->{'_start'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_location_type"} eq "IN-BETWEEN" and defined $self->{"_start"} and defined $self->{"_end"} and $self->{"_end"} - 1 != $self->{"_start"} 1 640327 640328
Condition77%7/9
$self->{"_location_type"} eq "IN-BETWEEN" and defined $self->{"_start"} and defined $self->{"_end"} and $self->{"_end"} - 1 != $self->{"_start"}
!ll&&!rl&&r
640263641
$self->{"_location_type"} eq "IN-BETWEEN" and defined $self->{"_start"} and defined $self->{"_end"}
!ll&&!rl&&r
640263065
$self->{"_location_type"} eq "IN-BETWEEN" and defined $self->{"_start"}
!ll&&!rl&&r
640263065
MC/DC50%2/4
$self->{"_location_type"} eq "IN-BETWEEN" and defined $self->{"_start"} and defined $self->{"_end"} and $self->{"_end"} - 1 != $self->{"_start"}
$self->{"_location_type"} eq "IN-BETWEEN" defined $self->{"_start"} defined $self->{"_end"} $self->{"_end"} - 1 != $self->{"_start"}
Truth table60%3/5
A and B and C and D
A= $self->{"_location_type"} eq "IN-BETWEEN"B= defined $self->{"_start"}C= defined $self->{"_end"}D= $self->{"_end"} - 1 != $self->{"_start"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
306  
307 640327 return $self->{'_location_type'};
308 }
309  
310 =head2 is_remote
311  
312 Title : is_remote
313 Usage : $is_remote_loc = $loc->is_remote()
314 Function: Whether or not a location is a remote location.
315  
316 A location is said to be remote if it is on a different
317 'object' than the object which 'has' this
318 location. Typically, features on a sequence will sometimes
319 have a remote location, which means that the location of
320 the feature is on a different sequence than the one that is
321 attached to the feature. In such a case, $loc->seq_id will
322 be different from $feat->seq_id (usually they will be the
323 same).
324  
325 While this may sound weird, it reflects the location of the
326 kind of AL445212.9:83662..166657 which can be found in GenBank/EMBL
327 feature tables.
328  
329 Example :
330 Returns : TRUE if the location is a remote location, and FALSE otherwise
331 Args : Value to set to
332  
333 =cut
334  
335 =head2 to_FTstring
336  
337 Title : to_FTstring
338 Usage : my $locstr = $location->to_FTstring()
339 Function: returns the FeatureTable string of this location
340 Returns : string
341 Args : none
342  
343 =cut
344  
345 582 ▶sub to_FTstring {
Subroutine to_FTstring: called CC=6 SCAR=17.9
Pod documented
346 582 my($self) = @_;
347  
348 582 my $str;
349 582 ▶ if( $self->start == $self->end ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->start == $self->end) { } 105 477 582
350 105 $str = $self->start;
351 } else {
352 477 $str = $self->start . $RANGEDECODE{$self->location_type} . $self->end;
353 }
354 582 ▶ if($self->is_remote() && $self->seq_id()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_remote and $self->seq_id) 17 565 582
Condition66%2/3
$self->is_remote and $self->seq_id
!ll&&!rl&&r
565017
MC/DC50%1/2
$self->is_remote and $self->seq_id
$self->is_remote $self->seq_id
Truth table66%2/3
A and B
A= $self->is_remoteB= $self->seq_id
ABresult
0X0
100
111
355 17 $str = $self->seq_id() . ":" . $str;
356 }
357 582 ▶ if( defined $self->strand &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->strand and $self->strand == -1) 234 348 582
Condition100%3/3
defined $self->strand and $self->strand == -1
!ll&&!rl&&r
4344234
MC/DC100%2/2
defined $self->strand and $self->strand == -1
defined $self->strand $self->strand == -1
Truth table100%3/3
A and B
A= defined $self->strandB= $self->strand == -1
ABresult
0X0
100
111
358 $self->strand == -1 ) {
359 234 $str = "complement(".$str.")";
360 }
361 582 return $str;
362 }
363  
364  
365 =head2 valid_Location
366  
367 Title : valid_Location
368 Usage : if ($location->valid_location) {...};
369 Function: boolean method to determine whether location is considered valid
370 (has minimum requirements for Simple implementation)
371 Returns : Boolean value: true if location is valid, false otherwise
372 Args : none
373  
374 =cut
375  
376 # comments, not function added by jason
377 #
378 # trunc is untested, and as of now unannounced method for truncating a
379 # location. This is to eventually be part of the procedure to
380 # truncate a sequence with annotation and properly remap the location
381 # of all the features contained within the truncated segment.
382  
383 # presumably this might do things a little differently for the case
384 # where the truncation splits the location in half
385 #
386 # in short- you probably don't want to use this method.
387  
388 0 ▶sub trunc {
Subroutine trunc: not called CC=3 SCAR=24.8
Pod documented
389 0 my ($self,$start,$end,$relative_ori) = @_;
390 0 my $newstart = $self->start - $start+1;
391 0 my $newend = $self->end - $start+1;
392 0 my $newstrand = $relative_ori * $self->strand;
393  
394 0 my $out;
395 0 ▶ if( $newstart < 1 || $newend > ($end-$start+1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newstart < 1 or $newend > $end - $start + 1) { } 0 0 0
Condition0%0/3
$newstart < 1 or $newend > $end - $start + 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$newstart < 1 or $newend > $end - $start + 1
$newstart < 1 $newend > $end - $start + 1
Truth table0%0/3
A or B
A= $newstart < 1B= $newend > $end - $start + 1
ABresult
1X1
011
000
396 0 $out = Bio::Location::Simple->new();
397 0 $out->start($self->start);
398 0 $out->end($self->end);
399 0 $out->strand($self->strand);
400 0 $out->seq_id($self->seqid);
401 0 $out->is_remote(1);
402 } else {
403 0 $out = Bio::Location::Simple->new();
404 0 $out->start($newstart);
405 0 $out->end($newend);
406 0 $out->strand($newstrand);
407 0 $out->seq_id();
408 }
409  
410 0 return $out;
411 }
412  
413 324 1;
414  
« Bio/Matrix/IO.pm ↑ Summary Bio/SearchIO/Writer/HitTableWriter.pm »