Bio/Location/Fuzzy.pm

filter: Statementstmt 85.0% 114 / 134 Branchbran 76.0% 76 / 100 Conditioncond 79.4% 62 / 78 MC/DCmcdc 62.7% 27 / 43 Subroutinesub 100% 14 / 14 Podpod 100% 11 / 11 totaltotal 80.0% 304 / 380 CC 79 SCAR 27.5
CC
79
Cov
81%
to_FTstring
28.7
location_type
17.9
_fuzzypointdecode
13.3
CRAP 15.7
« Bio/Index/Abstract.pm ↑ Summary Bio/Tools/Fgenesh.pm »
1 #
2 # BioPerl module for Bio::Location::Fuzzy
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
4 #
5 # Cared for by Jason Stajich <jason@bioperl.org>
6 #
7 # Copyright Jason Stajich
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::Fuzzy - Implementation of a Location on a Sequence
15 which has unclear start and/or end locations
16  
17 =head1 SYNOPSIS
18  
19 use Bio::Location::Fuzzy;
20 my $fuzzylocation = Bio::Location::Fuzzy->new(
21 -start => '<30',
22 -end => 90,
23 -location_type => '..');
24  
25 print "location string is ", $fuzzylocation->to_FTstring(), "\n";
26 print "location is of the type ", $fuzzylocation->location_type, "\n";
27  
28 =head1 DESCRIPTION
29  
30 This module contains the necessary methods for representing a
31 Fuzzy Location, one that does not have clear start and/or end points.
32 This will initially serve to handle features from Genbank/EMBL feature
33 tables that are written as 1^100 meaning between bases 1 and 100 or
34 E<lt>100..300 meaning it starts somewhere before 100. Advanced
35 implementations of this interface may be able to handle the necessary
36 logic of overlaps/intersection/contains/union. It was constructed to
37 handle fuzzy locations that can be represented in Genbank/EMBL and
38 Swissprot.
39  
40 =head1 FEEDBACK
41  
42 User feedback is an integral part of the evolution of this and other
43 Bioperl modules. Send your comments and suggestions preferably to one
44 of the Bioperl mailing lists. Your participation is much appreciated.
45  
46 bioperl-l@bioperl.org - General discussion
47 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
48  
49 =head2 Support
50  
51 Please direct usage questions or support issues to the mailing list:
52  
53 I<bioperl-l@bioperl.org>
54  
55 rather than to the module maintainer directly. Many experienced and
56 reponsive experts will be able look at the problem and quickly
57 address it. Please include a thorough description of the problem
58 with code and data examples if at all possible.
59  
60 =head2 Reporting Bugs
61  
62 Report bugs to the Bioperl bug tracking system to help us keep track
63 the bugs and their resolution. Bug reports can be submitted via the
64 web:
65  
66 https://github.com/bioperl/bioperl-live/issues
67  
68 =head1 AUTHOR - Jason Stajich
69  
70 Email jason-at-bioperl-dot-org
71  
72 =head1 APPENDIX
73  
74 The rest of the documentation details each of the object
75 methods. Internal methods are usually preceded with a _
76  
77 =cut
78  
79 # Let the code begin...
80  
81 package Bio::Location::Fuzzy;
82 324 $Bio::Location::Fuzzy::VERSION = '1.7.8';
83 324 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
84  
85 324 ▶use base qw(Bio::Location::Atomic Bio::Location::FuzzyLocationI);
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 324 our @LOCATIONCODESBSANE = (undef, 'EXACT', 'WITHIN', 'BETWEEN', 'UNCERTAIN',
88 'BEFORE', 'AFTER');
89  
90 324 our %FUZZYCODES = ( 'EXACT' => '..', # Position is 'exact
91 # Exact position is unknown, but is within the range specified, ((1.2)..100)
92 'WITHIN' => '.',
93 # 1^2
94 'BETWEEN' => '^',
95 'IN-BETWEEN' => '^',
96 'UNCERTAIN' => '?',
97 # <100
98 'BEFORE' => '<',
99 # >10
100 'AFTER' => '>');
101
102 # The following regular expressions map to fuzzy location types. Every
103 # expression must match the complete encoded point string, and must
104 # contain two groups identifying min and max. Empty matches are automatic.
105 # converted to undef, except for 'EXACT', for which max is set to equal
106 # min.
107
108 324 our %FUZZYPOINTENCODE = (
109 '\>(\d+)(.{0})' => 'AFTER',
110 '\<(.{0})(\d+)' => 'BEFORE',
111 '(\d+)' => 'EXACT',
112 '\?(\d*)' => 'UNCERTAIN',
113 '(\d+)(.{0})\>' => 'AFTER',
114 '(.{0})(\d+)\<' => 'BEFORE',
115 '(\d+)\.(\d+)' => 'WITHIN',
116 '(\d+)\^(\d+)' => 'BETWEEN',
117 );
118
119 324 our %FUZZYRANGEENCODE = ( '\.' => 'WITHIN',
120 '\.\.' => 'EXACT',
121 '\^' => 'IN-BETWEEN' );
122  
123 =head2 new
124  
125 Title : new
126 Usage : my $fuzzyloc = Bio::Location::Fuzzy->new( @args);
127 Function:
128 Returns :
129 Args : -start => value for start (initialize by superclass)
130 -end => value for end (initialize by superclass)
131 -strand => value for strand (initialize by superclass)
132 -location_type => either ('EXACT','WITHIN','IN-BETWEEN',
133 'UNCERTAIN') OR ( 1,2,3,4)
134 -start_ext=> extension for start - defaults to 0,
135 -start_fuz= fuzzy code for start can be
136 ('EXACT','WITHIN','BETWEEN','BEFORE','AFTER',
137 'UNCERTAIN' ) OR
138 a value 1 - 5 corresponding to index+1 above
139 -end_ext=> extension for end - defaults to 0,
140 -end_fuz= fuzzy code for end can be
141 ('EXACT','WITHIN','BETWEEN','BEFORE','AFTER',
142 'UNCERTAIN') OR
143 a value 1 - 5 corresponding to index+1 above
144  
145 =cut
146  
147 472 ▶sub new {
Subroutine new: called CC=6 SCAR=18.5
Pod documented
148 472 my ($class, @args) = @_;
149 472 my $self = $class->SUPER::new(@args);
150 472 my ($location_type, $start_ext, $start_fuz, $end_ext, $end_fuz) =
151 $self->_rearrange([ qw(LOCATION_TYPE START_EXT START_FUZ
152 END_EXT END_FUZ )
153 ], @args);
154  
155 472 ▶ $location_type && $self->location_type($location_type);
Branch: 1 branch
BranchTrueFalseTotal
$location_type and $self->location_type($location_type) 465 7 472
156 471 ▶ $start_ext && $self->max_start($self->min_start + $start_ext);
Branch: 1 branch
BranchTrueFalseTotal
$start_ext and $self->max_start($self->min_start + $start_ext) 0 471 471
157 471 ▶ $end_ext && $self->max_end($self->min_end + $end_ext);
Branch: 1 branch
BranchTrueFalseTotal
$end_ext and $self->max_end($self->min_end + $end_ext) 0 471 471
158 471 ▶ $start_fuz && $self->start_pos_type($start_fuz);
Branch: 1 branch
BranchTrueFalseTotal
$start_fuz and $self->start_pos_type($start_fuz) 0 471 471
159 471 ▶ $end_fuz && $self->end_pos_type($end_fuz);
Branch: 1 branch
BranchTrueFalseTotal
$end_fuz and $self->end_pos_type($end_fuz) 0 471 471
160  
161 471 return $self;
162 }
163  
164 =head2 location_type
165  
166 Title : location_type
167 Usage : my $location_type = $location->location_type();
168 Function: Get location type encoded as text
169 Returns : string ('EXACT', 'WITHIN', 'IN-BETWEEN', 'UNCERTAIN')
170 Args : none
171  
172 =cut
173  
174 5710 ▶sub location_type {
Subroutine location_type: called CC=15 SCAR=28.8
Pod documented
175 5710 my ($self,$value) = @_;
176 5710 ▶ if( defined $value || ! defined $self->{'_location_type'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value or not defined $self->{"_location_type"}) 937 4773 5710
Condition100%3/3
defined $value or not defined $self->{"_location_type"}
l!l&&r!l&&!r
4654724773
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
177 937 ▶ $value = 'EXACT' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 472 465 937
178 937 ▶ if(! defined $FUZZYCODES{$value} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Bio::Location::Fuzzy::FUZZYCODES{$value}) 463 474 937
179 463 $value = uc($value);
180 463 ▶ if( $value =~ /\.\./ ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($value =~ /\.\./) { } 405 58 463
elsif ($value =~ /^\.$/) { } 17 41 58
elsif ($value =~ /\^/) { } 6 35 41
elsif ($value =~ /\?/) { } 35 0 35
elsif ($value ne 'EXACT' and $value ne 'WITHIN' and $value ne 'IN-BETWEEN') { } 0 0 0
181 405 $value = 'EXACT';
182 } elsif( $value =~ /^\.$/ ) {
183 17 $value = 'WITHIN';
184 } elsif( $value =~ /\^/ ) {
185 6 $value = 'IN-BETWEEN';
186 6 ▶ $self->throw("Use Bio::Location::Simple for IN-BETWEEN locations [".
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->start and defined $self->end and $self->end - 1 == $self->start 1 5 6
Condition83%5/6
defined $self->start and defined $self->end and $self->end - 1 == $self->start
!ll&&!rl&&r
231
defined $self->start and defined $self->end
!ll&&!rl&&r
204
MC/DC66%2/3
defined $self->start and defined $self->end and $self->end - 1 == $self->start
defined $self->start defined $self->end $self->end - 1 == $self->start
Truth table75%3/4
A and B and C
A= defined $self->startB= defined $self->endC= $self->end - 1 == $self->start
ABCresult
0XX0
10X0
1100
1111
187 $self->start. "] and [". $self->end. "]")
188 if defined $self->start && defined $self->end &&
189 ($self->end - 1 == $self->start);
190 } elsif( $value =~ /\?/ ) {
191 35 $value = 'UNCERTAIN';
192 ▶ } elsif( $value ne 'EXACT' && $value ne 'WITHIN' &&
Condition0%0/6
$value ne "EXACT" and $value ne "WITHIN" and $value ne "IN-BETWEEN"
!ll&&!rl&&r
000
$value ne "EXACT" and $value ne "WITHIN"
!ll&&!rl&&r
000
MC/DC0%0/3
$value ne "EXACT" and $value ne "WITHIN" and $value ne "IN-BETWEEN"
$value ne "EXACT" $value ne "WITHIN" $value ne "IN-BETWEEN"
Truth table0%0/4
A and B and C
A= $value ne "EXACT"B= $value ne "WITHIN"C= $value ne "IN-BETWEEN"
ABCresult
0XX0
10X0
1100
1111
193 $value ne 'IN-BETWEEN' ) {
194 0 $self->throw("Did not specify a valid location type");
195 }
196 }
197 936 $self->{'_location_type'} = $value;
198 }
199 5709 return $self->{'_location_type'};
200 }
201  
202 =head1 LocationI methods
203  
204 =head2 length
205  
206 Title : length
207 Usage : $length = $fuzzy_loc->length();
208 Function: Get the length of this location.
209  
210 Note that the length of a fuzzy location will always depend
211 on the currently active interpretation of start and end. The
212 result will therefore vary for different CoordinatePolicy objects.
213  
214 Returns : an integer
215 Args : none
216  
217 =cut
218  
219 #sub length {
220 # my($self) = @_;
221 # return $self->SUPER::length() if( !$self->start || !$self->end);
222 # $self->warn('Length is not valid for a FuzzyLocation');
223 # return 0;
224 #}
225  
226 =head2 start
227  
228 Title : start
229 Usage : $start = $fuzzy->start();
230 Function: get/set start of this range, handling fuzzy_starts
231 Returns : a positive integer representing the start of the location
232 Args : start location on set (can be fuzzy point string)
233  
234 =cut
235  
236 2484 ▶sub start {
Subroutine start: called CC=5 SCAR=16.1
Pod documented
237 2484 my($self,$value) = @_;
238 2484 ▶ if( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 473 2011 2484
239 473 my ($encode,$min,$max) = $self->_fuzzypointdecode($value);
240 473 $self->start_pos_type($encode);
241 473 $self->min_start($min);
242 473 $self->max_start($max);
243 }
244  
245 2484 ▶ $self->throw("Use Bio::Location::Simple for IN-BETWEEN locations ["
Branch: 1 branch
BranchTrueFalseTotal
if $self->location_type eq "IN-BETWEEN" and defined $self->SUPER::end and $self->SUPER::end - 1 == $self->SUPER::start 1 2483 2484
Condition100%6/6
$self->location_type eq "IN-BETWEEN" and defined $self->SUPER::end and $self->SUPER::end - 1 == $self->SUPER::start
!ll&&!rl&&r
248031
$self->location_type eq "IN-BETWEEN" and defined $self->SUPER::end
!ll&&!rl&&r
247914
MC/DC100%3/3
$self->location_type eq "IN-BETWEEN" and defined $self->SUPER::end and $self->SUPER::end - 1 == $self->SUPER::start
$self->location_type eq "IN-BETWEEN" defined $self->SUPER::end $self->SUPER::end - 1 == $self->SUPER::start
Truth table100%4/4
A and B and C
A= $self->location_type eq "IN-BETWEEN"B= defined $self->SUPER::endC= $self->SUPER::end - 1 == $self->SUPER::start
ABCresult
0XX0
10X0
1100
1111
246 . $self->SUPER::start. "] and [". $self->SUPER::end. "]")
247 if $self->location_type eq 'IN-BETWEEN' && defined $self->SUPER::end &&
248 ($self->SUPER::end - 1 == $self->SUPER::start);
249  
250 2483 return $self->SUPER::start();
251 }
252  
253 =head2 end
254  
255 Title : end
256 Usage : $end = $fuzzy->end();
257 Function: get/set end of this range, handling fuzzy_ends
258 Returns : a positive integer representing the end of the range
259 Args : end location on set (can be fuzzy string)
260  
261 =cut
262  
263 2445 ▶sub end {
Subroutine end: called CC=5 SCAR=16.1
Pod documented
264 2445 my($self,$value) = @_;
265 2445 ▶ if( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 472 1973 2445
266 472 my ($encode,$min,$max) = $self->_fuzzypointdecode($value);
267 472 $self->end_pos_type($encode);
268 472 $self->min_end($min);
269 472 $self->max_end($max);
270 }
271  
272 2445 ▶ $self->throw("Use Bio::Location::Simple for IN-BETWEEN locations [".
Branch: 1 branch
BranchTrueFalseTotal
if $self->location_type eq "IN-BETWEEN" and defined $self->SUPER::start and $self->SUPER::end - 1 == $self->SUPER::start 1 2444 2445
Condition100%6/6
$self->location_type eq "IN-BETWEEN" and defined $self->SUPER::start and $self->SUPER::end - 1 == $self->SUPER::start
!ll&&!rl&&r
244131
$self->location_type eq "IN-BETWEEN" and defined $self->SUPER::start
!ll&&!rl&&r
244014
MC/DC100%3/3
$self->location_type eq "IN-BETWEEN" and defined $self->SUPER::start and $self->SUPER::end - 1 == $self->SUPER::start
$self->location_type eq "IN-BETWEEN" defined $self->SUPER::start $self->SUPER::end - 1 == $self->SUPER::start
Truth table100%4/4
A and B and C
A= $self->location_type eq "IN-BETWEEN"B= defined $self->SUPER::startC= $self->SUPER::end - 1 == $self->SUPER::start
ABCresult
0XX0
10X0
1100
1111
273 $self->SUPER::start. "] and [". $self->SUPER::end. "]")
274 if $self->location_type eq 'IN-BETWEEN' && defined $self->SUPER::start &&
275 ($self->SUPER::end - 1 == $self->SUPER::start);
276  
277 2444 return $self->SUPER::end();
278 }
279  
280 =head2 min_start
281  
282 Title : min_start
283 Usage : $min_start = $fuzzy->min_start();
284 Function: get/set the minimum starting point
285 Returns : the minimum starting point from the contained sublocations
286 Args : integer or undef on set
287  
288 =cut
289  
290 3996 ▶sub min_start {
Subroutine min_start: called CC=2 SCAR=6.9
Pod documented
291 3996 my ($self,@args) = @_;
292  
293 3996 ▶ if(@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 473 3523 3996
294 473 $self->{'_min_start'} = $args[0]; # the value may be undef!
295 }
296 3996 return $self->{'_min_start'};
297 }
298  
299 =head2 max_start
300  
301 Title : max_start
302 Usage : my $maxstart = $location->max_start();
303 Function: Get/set maximum starting location of feature startpoint
304 Returns : integer or undef if no maximum starting point.
305 Args : integer or undef on set
306  
307 =cut
308  
309 3103 ▶sub max_start {
Subroutine max_start: called CC=2 SCAR=6.9
Pod documented
310 3103 my ($self,@args) = @_;
311  
312 3103 ▶ if(@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 473 2630 3103
313 473 $self->{'_max_start'} = $args[0]; # the value may be undef!
314 }
315 3103 return $self->{'_max_start'};
316 }
317  
318 =head2 start_pos_type
319  
320 Title : start_pos_type
321 Usage : my $start_pos_type = $location->start_pos_type();
322 Function: Get/set start position type.
323 Returns : type of position coded as text
324 ('BEFORE','AFTER','EXACT','WITHIN','BETWEEN','UNCERTAIN')
325 Args : a string on set
326  
327 =cut
328  
329 598 ▶sub start_pos_type {
Subroutine start_pos_type: called CC=6 SCAR=25.3
Pod documented
330 598 my ($self,$value) = @_;
331 598 ▶ if(defined $value && $value =~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and $value =~ /^\d+$/) 0 598 598
Condition66%2/3
defined $value and $value =~ /^\d+$/
!ll&&!rl&&r
1294690
MC/DC0%0/2
defined $value and $value =~ /^\d+$/
defined $value $value =~ /^\d+$/
Truth table66%2/3
A and B
A= defined $valueB= $value =~ /^\d+$/
ABresult
0X0
100
111
332 0 ▶ if( $value == 0 ) { $value = 'EXACT'; }
Branch: 1 branch
BranchTrueFalseTotal
if ($value == 0) { } 0 0 0
333 else {
334 0 my $v = $LOCATIONCODESBSANE[$value];
335 0 ▶ if( ! defined $v ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v) 0 0 0
336 0 $self->warn("Provided value $value which I don't understand,".
337 " reverting to 'EXACT'");
338 0 $v = 'EXACT';
339 }
340 0 $value = $v;
341 }
342 }
343 598 ▶ if(defined($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 469 129 598
344 469 $self->{'_start_pos_type'} = $value;
345 }
346 598 return $self->{'_start_pos_type'};
347 }
348  
349 =head2 min_end
350  
351 Title : min_end
352 Usage : my $minend = $location->min_end();
353 Function: Get/set minimum ending location of feature endpoint
354 Returns : integer or undef if no minimum ending point.
355 Args : integer or undef on set
356  
357 =cut
358  
359 2303 ▶sub min_end {
Subroutine min_end: called CC=2 SCAR=6.9
Pod documented
360 2303 my ($self,@args) = @_;
361  
362 2303 ▶ if(@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 472 1831 2303
363 472 $self->{'_min_end'} = $args[0]; # the value may be undef!
364 }
365 2303 return $self->{'_min_end'};
366 }
367  
368 =head2 max_end
369  
370 Title : max_end
371 Usage : my $maxend = $location->max_end();
372 Function: Get/set maximum ending location of feature endpoint
373 Returns : integer or undef if no maximum ending point.
374 Args : integer or undef on set
375  
376 =cut
377  
378 3553 ▶sub max_end {
Subroutine max_end: called CC=2 SCAR=6.9
Pod documented
379 3553 my ($self,@args) = @_;
380  
381 3553 ▶ if(@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 472 3081 3553
382 472 $self->{'_max_end'} = $args[0]; # the value may be undef!
383 }
384 3553 return $self->{'_max_end'};
385 }
386  
387 =head2 end_pos_type
388  
389 Title : end_pos_type
390 Usage : my $end_pos_type = $location->end_pos_type();
391 Function: Get/set end position type.
392 Returns : type of position coded as text
393 ('BEFORE','AFTER','EXACT','WITHIN','BETWEEN','UNCERTAIN')
394 Args : a string on set
395  
396 =cut
397  
398 598 ▶sub end_pos_type {
Subroutine end_pos_type: called CC=6 SCAR=25.3
Pod documented
399 598 my ($self,$value) = @_;
400 598 ▶ if( defined $value && $value =~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and $value =~ /^\d+$/) 0 598 598
Condition66%2/3
defined $value and $value =~ /^\d+$/
!ll&&!rl&&r
1414570
MC/DC0%0/2
defined $value and $value =~ /^\d+$/
defined $value $value =~ /^\d+$/
Truth table66%2/3
A and B
A= defined $valueB= $value =~ /^\d+$/
ABresult
0X0
100
111
401 0 ▶ if( $value == 0 ) { $value = 'EXACT'; }
Branch: 1 branch
BranchTrueFalseTotal
if ($value == 0) { } 0 0 0
402 else {
403 0 my $v = $LOCATIONCODESBSANE[$value];
404 0 ▶ if( ! defined $v ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v) 0 0 0
405 0 $self->warn("Provided value $value which I don't understand,".
406 " reverting to 'EXACT'");
407 0 $v = 'EXACT';
408 }
409 0 $value = $v;
410 }
411 }
412  
413 598 ▶ if(defined($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 457 141 598
414 457 $self->{'_end_pos_type'} = $value;
415 }
416 598 return $self->{'_end_pos_type'};
417 }
418  
419 =head2 seq_id
420  
421 Title : seq_id
422 Usage : my $seqid = $location->seq_id();
423 Function: Get/Set seq_id that location refers to
424 Returns : seq_id
425 Args : [optional] seq_id value to set
426  
427 =cut
428  
429 =head2 coordinate_policy
430  
431 Title : coordinate_policy
432  
433 Usage : $policy = $location->coordinate_policy();
434 $location->coordinate_policy($mypolicy); # set may not be possible
435 Function: Get the coordinate computing policy employed by this object.
436  
437 See Bio::Location::CoordinatePolicyI for documentation about
438 the policy object and its use.
439  
440 The interface *does not* require implementing classes to accept
441 setting of a different policy. The implementation provided here
442 does, however, allow one to do so.
443  
444 Implementors of this interface are expected to initialize every
445 new instance with a CoordinatePolicyI object. The implementation
446 provided here will return a default policy object if none has
447 been set yet. To change this default policy object call this
448 method as a class method with an appropriate argument. Note that
449 in this case only subsequently created Location objects will be
450 affected.
451  
452 Returns : A Bio::Location::CoordinatePolicyI implementing object.
453 Args : On set, a Bio::Location::CoordinatePolicyI implementing object.
454  
455 See L<Bio::Location::CoordinatePolicyI>
456  
457 =cut
458  
459 =head2 to_FTstring
460  
461 Title : to_FTstring
462 Usage : my $locstr = $location->to_FTstring()
463 Function: Get/Set seq_id that location refers to
464 Returns : seq_id
465 Args : [optional] seq_id value to set
466  
467 =cut
468  
469 99 ▶sub to_FTstring {
Subroutine to_FTstring: called CC=26 SCAR=33.6
Pod documented
470 99 my ($self) = @_;
471 99 my (%vals) = ( 'start' => $self->start,
472 'min_start' => $self->min_start,
473 'max_start' => $self->max_start,
474 'start_code' => $self->start_pos_type,
475 'end' => $self->end,
476 'min_end' => $self->min_end,
477 'max_end' => $self->max_end,
478 'end_code' => $self->end_pos_type );
479  
480 99 my (%strs) = ( 'start' => '',
481 'end' => '');
482 99 my ($delimiter) = $FUZZYCODES{$self->location_type};
483 99 ▶ $delimiter = $FUZZYCODES{'EXACT'} if ($self->location_type eq 'UNCERTAIN');
Branch: 1 branch
BranchTrueFalseTotal
if $self->location_type eq "UNCERTAIN" 9 90 99
484
485 99 my $policy = ref($self->coordinate_policy);
486
487 # I'm lazy, lets do this in a loop since behaviour will be the same for
488 # start and end
489 # The CoordinatePolicy now dictates start/end data here (bug 992) - cjf
490 99 foreach my $point ( qw(start end) ) {
491 198 ▶ if( ($vals{$point."_code"} ne 'EXACT') &&
Branch: 2 branches
BranchTrueFalseTotal
if ($vals{$point . '_code'} ne 'EXACT' and $vals{$point . '_code'} ne 'UNCERTAIN') { } 104 94 198
elsif ($vals{$point . '_code'} eq 'UNCERTAIN') { } 15 79 94
Condition100%3/3
$vals{$point . '_code'} ne "EXACT" and $vals{$point . '_code'} ne "UNCERTAIN"
!ll&&!rl&&r
7915104
MC/DC100%2/2
$vals{$point . '_code'} ne "EXACT" and $vals{$point . '_code'} ne "UNCERTAIN"
$vals{$point . '_code'} ne "EXACT" $vals{$point . '_code'} ne "UNCERTAIN"
Truth table100%3/3
A and B
A= $vals{$point . '_code'} ne "EXACT"B= $vals{$point . '_code'} ne "UNCERTAIN"
ABresult
0X0
100
111
492 ($vals{$point."_code"} ne 'UNCERTAIN') ) {
493
494 # must have max and min defined to use 'WITHIN', 'BETWEEN'
495 104 ▶ if ((!defined $vals{"min_$point"} ||
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $vals{"min_$point"} && defined $vals{"max_$point"} and $vals{$point . '_code'} eq "WITHIN" || $vals{$point . '_code'} eq "BETWEEN") 0 104 104
Condition66%6/9
not defined $vals{"min_$point"} && defined $vals{"max_$point"} and $vals{$point . '_code'} eq "WITHIN" || $vals{$point . '_code'} eq "BETWEEN"
!ll&&!rl&&r
27770
defined $vals{"min_$point"} && defined $vals{"max_$point"}
!ll&&!rl&&r
463127
$vals{$point . '_code'} eq "WITHIN" or $vals{$point . '_code'} eq "BETWEEN"
l!l&&r!l&&!r
0077
MC/DC0%0/4
not defined $vals{"min_$point"} && defined $vals{"max_$point"} and $vals{$point . '_code'} eq "WITHIN" || $vals{$point . '_code'} eq "BETWEEN"
defined $vals{"min_$point"} defined $vals{"max_$point"} $vals{$point . '_code'} eq "WITHIN" $vals{$point . '_code'} eq "BETWEEN"
Truth table42%3/7
not(A && B) and C or D
A= defined $vals{"min_$point"}B= defined $vals{"max_$point"}C= $vals{$point . '_code'} eq "WITHIN"D= $vals{$point . '_code'} eq "BETWEEN"
ABCDresult
11XX0
0X000
10000
0X1X1
0X011
101X1
10011
496 !defined $vals{"max_$point"}) &&
497 ( $vals{$point."_code"} eq 'WITHIN' ||
498 $vals{$point."_code"} eq 'BETWEEN'))
499 {
500 0 ▶ $vals{"min_$point"} = '' unless defined $vals{"min_$point"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $vals{"min_$point"} 0 0 0
501 0 ▶ $vals{"max_$point"} = '' unless defined $vals{"max_$point"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $vals{"max_$point"} 0 0 0
502
503 $self->warn("Fuzzy codes for start are in a strange state, (".
504 join(",", ($vals{"min_$point"},
505 $vals{"max_$point"},
506 0 $vals{$point."_code"})). ")");
507 0 return '';
508 }
509
510 104 ▶ if (defined $vals{$point."_code"} &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $vals{$point . '_code'} and $vals{$point . '_code'} eq "BEFORE" || $vals{$point . '_code'} eq "AFTER") 69 35 104
Condition100%6/6
defined $vals{$point . '_code'} and $vals{$point . '_code'} eq "BEFORE" || $vals{$point . '_code'} eq "AFTER"
!ll&&!rl&&r
82769
$vals{$point . '_code'} eq "BEFORE" or $vals{$point . '_code'} eq "AFTER"
l!l&&r!l&&!r
383127
MC/DC100%3/3
defined $vals{$point . '_code'} and $vals{$point . '_code'} eq "BEFORE" || $vals{$point . '_code'} eq "AFTER"
defined $vals{$point . '_code'} $vals{$point . '_code'} eq "BEFORE" $vals{$point . '_code'} eq "AFTER"
Truth table100%4/4
A and B or C
A= defined $vals{$point . '_code'}B= $vals{$point . '_code'} eq "BEFORE"C= $vals{$point . '_code'} eq "AFTER"
ABCresult
0XX0
1000
11X1
1011
511 ($vals{$point."_code"} eq 'BEFORE' ||
512 $vals{$point."_code"} eq 'AFTER'))
513 {
514 69 $strs{$point} .= $FUZZYCODES{$vals{$point."_code"}};
515 69 $strs{$point} .= $vals{"$point"};
516 }
517
518 104 ▶ if( defined $vals{$point."_code"} &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $vals{$point . '_code'} and $vals{$point . '_code'} eq "WITHIN" || $vals{$point . '_code'} eq "BETWEEN") 27 77 104
Condition100%6/6
defined $vals{$point . '_code'} and $vals{$point . '_code'} eq "WITHIN" || $vals{$point . '_code'} eq "BETWEEN"
!ll&&!rl&&r
86927
$vals{$point . '_code'} eq "WITHIN" or $vals{$point . '_code'} eq "BETWEEN"
l!l&&r!l&&!r
23469
MC/DC100%3/3
defined $vals{$point . '_code'} and $vals{$point . '_code'} eq "WITHIN" || $vals{$point . '_code'} eq "BETWEEN"
defined $vals{$point . '_code'} $vals{$point . '_code'} eq "WITHIN" $vals{$point . '_code'} eq "BETWEEN"
Truth table100%4/4
A and B or C
A= defined $vals{$point . '_code'}B= $vals{$point . '_code'} eq "WITHIN"C= $vals{$point . '_code'} eq "BETWEEN"
ABCresult
0XX0
1000
11X1
1011
519 ($vals{$point."_code"} eq 'WITHIN' ||
520 $vals{$point."_code"} eq 'BETWEEN'))
521 {
522 # Expect odd results with anything but WidestCoordPolicy for now
523 $strs{$point} .= ($point eq 'start') ?
524 $vals{"$point"}.
525 $FUZZYCODES{$vals{$point."_code"}}.
526 $vals{'max_'.$point}
527 :
528 $vals{'min_'.$point}.
529 $FUZZYCODES{$vals{$point."_code"}}.
530 27 ▶ $vals{"$point"};
Branch: 1 branch
BranchTrueFalseTotal
$point eq 'start' ? : 16 11 27
531 27 $strs{$point} = "(".$strs{$point}.")";
532 }
533
534 } elsif ($vals{$point."_code"} eq 'UNCERTAIN') {
535 15 $strs{$point} = $FUZZYCODES{$vals{$point."_code"}};
536 15 ▶ $strs{$point} .= $vals{$point} if defined $vals{$point};
Branch: 1 branch
BranchTrueFalseTotal
if defined $vals{$point} 5 10 15
537 } else {
538 79 $strs{$point} = $vals{$point};
539 }
540 }
541
542 99 my $str = $strs{'start'} . $delimiter . $strs{'end'};
543 99 ▶ if($self->is_remote() && $self->seq_id()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_remote and $self->seq_id) 2 97 99
Condition66%2/3
$self->is_remote and $self->seq_id
!ll&&!rl&&r
9702
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
544 2 $str = $self->seq_id() . ":" . $str;
545 }
546 99 ▶ if( defined $self->strand &&
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->strand and $self->strand == -1 and $self->location_type ne 'UNCERTAIN') { } 6 93 99
elsif ($self->location_type eq 'WITHIN') { } 11 82 93
Condition83%5/6
defined $self->strand and $self->strand == -1 and $self->location_type ne "UNCERTAIN"
!ll&&!rl&&r
9306
defined $self->strand and $self->strand == -1
!ll&&!rl&&r
6876
MC/DC66%2/3
defined $self->strand and $self->strand == -1 and $self->location_type ne "UNCERTAIN"
defined $self->strand $self->strand == -1 $self->location_type ne "UNCERTAIN"
Truth table75%3/4
A and B and C
A= defined $self->strandB= $self->strand == -1C= $self->location_type ne "UNCERTAIN"
ABCresult
0XX0
10X0
1100
1111
547 $self->strand == -1 &&
548 $self->location_type() ne "UNCERTAIN") {
549 6 $str = "complement(" . $str . ")";
550 } elsif($self->location_type() eq "WITHIN") {
551 11 $str = "(".$str.")";
552 }
553 99 return $str;
554 }
555  
556 =head2 valid_Location
557  
558 Title : valid_Location
559 Usage : if ($location->valid_location) {...};
560 Function: boolean method to determine whether location is considered valid
561 (has minimum requirements for Simple implementation)
562 Returns : Boolean value: true if location is valid, false otherwise
563 Args : none
564  
565 =cut
566  
567 =head2 _fuzzypointdecode
568  
569 Title : _fuzzypointdecode
570 Usage : ($type,$min,$max) = $self->_fuzzypointdecode('<5');
571 Function: Decode a fuzzy string.
572 Returns : A 3-element array consisting of the type of location, the
573 minimum integer, and the maximum integer describing the range
574 of coordinates this start or endpoint refers to. Minimum or
575 maximum coordinate may be undefined.
576 : Returns empty array on fail.
577 Args : fuzzypoint string
578  
579 =cut
580  
581 945 ▶sub _fuzzypointdecode {
Subroutine _fuzzypointdecode: called CC=13 SCAR=25.9
582 945 my ($self, $string) = @_;
583 945 ▶ return () if( !defined $string);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 945 945
584 # strip off leading and trailing space
585 945 $string =~ s/^\s*(\S+)\s*/$1/;
586 945 foreach my $pattern ( keys %FUZZYPOINTENCODE ) {
587 3730 ▶ if( $string =~ /^$pattern$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /^$pattern$/) 926 2804 3730
588 926 ▶ my ($min,$max) = ($1,$2) unless (($1 eq '') && (!defined $2));
Branch: 1 branch
BranchTrueFalseTotal
unless $1 eq "" and not defined $2 890 36 926
Condition100%3/3
$1 eq "" and not defined $2
!ll&&!rl&&r
63625436
MC/DC100%2/2
$1 eq "" and not defined $2
$1 eq "" not defined $2
Truth table100%3/3
A and not(B)
A= $1 eq ""B= not defined $2
ABresult
0X0
100
111
589 926 ▶ if( ($FUZZYPOINTENCODE{$pattern} eq 'EXACT') ||
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::Location::Fuzzy::FUZZYPOINTENCODE{$pattern} eq 'EXACT' or $Bio::Location::Fuzzy::FUZZYPOINTENCODE{$pattern} eq 'UNCERTAIN') { } 438 488 926
Condition100%3/3
$Bio::Location::Fuzzy::FUZZYPOINTENCODE{$pattern} eq "EXACT" or $Bio::Location::Fuzzy::FUZZYPOINTENCODE{$pattern} eq "UNCERTAIN"
l!l&&r!l&&!r
39741488
MC/DC100%2/2
$Bio::Location::Fuzzy::FUZZYPOINTENCODE{$pattern} eq "EXACT" or $Bio::Location::Fuzzy::FUZZYPOINTENCODE{$pattern} eq "UNCERTAIN"
$Bio::Location::Fuzzy::FUZZYPOINTENCODE{$pattern} eq "EXACT" $Bio::Location::Fuzzy::FUZZYPOINTENCODE{$pattern} eq "UNCERTAIN"
Truth table100%3/3
A or B
A= $Bio::Location::Fuzzy::FUZZYPOINTENCODE{$pattern} eq "EXACT"B= $Bio::Location::Fuzzy::FUZZYPOINTENCODE{$pattern} eq "UNCERTAIN"
ABresult
1X1
011
000
590 ($FUZZYPOINTENCODE{$pattern} eq 'UNCERTAIN')
591 ) {
592 438 $max = $min;
593 } else {
594 488 ▶ $max = undef if((defined $max) && (length($max) == 0));
Branch: 1 branch
BranchTrueFalseTotal
if defined $max and length $max == 0 214 274 488
Condition66%2/3
defined $max and length $max == 0
!ll&&!rl&&r
0274214
MC/DC50%1/2
defined $max and length $max == 0
defined $max length $max == 0
Truth table66%2/3
A and B
A= defined $maxB= length $max == 0
ABresult
0X0
100
111
595 488 ▶ $min = undef if((defined $min) && (length($min) == 0));
Branch: 1 branch
BranchTrueFalseTotal
if defined $min and length $min == 0 254 234 488
Condition66%2/3
defined $min and length $min == 0
!ll&&!rl&&r
0234254
MC/DC50%1/2
defined $min and length $min == 0
defined $min length $min == 0
Truth table66%2/3
A and B
A= defined $minB= length $min == 0
ABresult
0X0
100
111
596 }
597 926 return ($FUZZYPOINTENCODE{$pattern},$min,$max);
598 }
599 }
600 19 ▶ if( $self->verbose >= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose >= 1) 0 19 19
601 0 $self->warn("could not find a valid fuzzy encoding for $string");
602 }
603 19 return ();
604 }
605  
606 324 1;
« Bio/Index/Abstract.pm ↑ Summary Bio/Tools/Fgenesh.pm »