Coordinate/Pair.pm

filter: Statementstmt 99.3% 154 / 155 Branchbran 74.0% 40 / 54 Conditioncond 78.5% 22 / 28 MC/DCmcdc 66.6% 10 / 15 Subroutinesub 100% 15 / 15 Podpod 100% 7 / 7 totaltotal 90.5% 248 / 274 CC 39 SCAR 23.7
CC
39
Cov
91%
_map
21.1
map
7.3
strand
5.1
CRAP 10.7
« Coordinate/Collection.pm ↑ Summary Coordinate/Graph.pm »
1 package Bio::Coordinate::Pair;
2 7 our $AUTHORITY = 'cpan:BIOPERLML';
3 7 $Bio::Coordinate::Pair::VERSION = '1.007001';
4 7 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use Bio::Coordinate::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Bio::Coordinate::Result::Match;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Bio::Coordinate::Result::Gap;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use parent qw(Bio::Root::Root Bio::Coordinate::MapperI);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ABSTRACT: Continuous match between two coordinate sets.
13 # AUTHOR: Heikki Lehvaslaiho <heikki@bioperl.org>
14 # OWNER: Heikki Lehvaslaiho
15 # LICENSE: Perl_5
16  
17  
18  
19 245 ▶sub new {
Subroutine new: called CC=3 SCAR=11.2
Pod documented
20 245 my($class,@args) = @_;
21 245 my $self = $class->SUPER::new(@args);
22  
23 245 my($in, $out) =
24 $self->_rearrange([qw(IN
25 OUT
26 )],
27 @args);
28  
29 245 ▶ $in && $self->in($in);
Branch: 1 branch
BranchTrueFalseTotal
$in and $self->in($in) 245 0 245
30 245 ▶ $out && $self->out($out);
Branch: 1 branch
BranchTrueFalseTotal
$out and $self->out($out) 245 0 245
31 245 return $self; # success - we hope!
32 }
33  
34  
35 2182 ▶sub in {
Subroutine in: called CC=3 SCAR=11.0
Pod documented
36 2182 my ($self,$value) = @_;
37 2182 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 245 1937 2182
38 245 ▶ $self->throw("Not a valid input Bio::Location [$value] ")
Branch: 1 branch
BranchTrueFalseTotal
unless $value->isa("Bio::LocationI") 0 245 245
39 unless $value->isa('Bio::LocationI');
40 245 $self->{'_in'} = $value;
41 }
42 2182 return $self->{'_in'};
43 }
44  
45  
46 2362 ▶sub out {
Subroutine out: called CC=3 SCAR=11.0
Pod documented
47 2362 my ($self,$value) = @_;
48 2362 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 245 2117 2362
49 245 ▶ $self->throw("Not a valid output coordinate Bio::Location [$value] ")
Branch: 1 branch
BranchTrueFalseTotal
unless $value->isa("Bio::LocationI") 0 245 245
50 unless $value->isa('Bio::LocationI');
51 245 $self->{'_out'} = $value;
52 }
53 2362 return $self->{'_out'};
54 }
55  
56  
57 147 ▶sub swap {
Subroutine swap: called CC=1 SCAR=0.0
Pod documented
58 147 my ($self) = @_;
59 147 ($self->{'_in'}, $self->{'_out'}) = ($self->{'_out'}, $self->{'_in'});
60 147 return 1;
61 }
62  
63  
64 220 ▶sub strand {
Subroutine strand: called CC=5 SCAR=16.3
Pod documented
65 220 my ($self) = @_;
66 220 ▶ $self->warn("Outgoing coordinates are not defined")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->out 0 220 220
67 unless $self->out;
68 220 ▶ $self->warn("Incoming coordinates are not defined")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->in 0 220 220
69 unless $self->in;
70  
71 220 ▶ return ($self->in->strand || 0) * ($self->out->strand || 0);
Condition100%4/4
$self->in->strand || 0
l!l
2164
$self->out->strand || 0
l!l
2164
MC/DC100%1/1
$self->in->strand || 0
$self->in->strand
MC/DC100%1/1
$self->out->strand || 0
$self->out->strand
Truth table100%2/2
A
A= $self->in->strand
Aresult
11
00
Truth table100%2/2
A
A= $self->out->strand
Aresult
11
00
72 }
73  
74  
75 208 ▶sub test {
Subroutine test: called CC=3 SCAR=11.4
Pod documented
76 208 my ($self) = @_;
77 208 ▶ $self->warn("Outgoing coordinates are not defined")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->out 0 208 208
78 unless $self->out;
79 208 ▶ $self->warn("Incoming coordinates are not defined")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->in 0 208 208
80 unless $self->in;
81 208 return ($self->in->end - $self->in->start) == ($self->out->end - $self->out->start);
82 }
83  
84  
85 73 ▶sub map {
Subroutine map: called CC=7 SCAR=19.8
Pod documented
86 73 my ($self,$value) = @_;
87  
88 73 ▶ $self->throw("Need to pass me a value.")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 73 73
89 unless defined $value;
90 73 ▶ $self->throw("I need a Bio::Location, not [$value]")
Branch: 1 branch
BranchTrueFalseTotal
unless $value->isa("Bio::LocationI") 0 73 73
91 unless $value->isa('Bio::LocationI');
92 73 ▶ $self->throw("Input coordinate system not set")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->in 0 73 73
93 unless $self->in;
94 73 ▶ $self->throw("Output coordinate system not set")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->out 0 73 73
95 unless $self->out;
96  
97 73 ▶ if ($value->isa("Bio::Location::SplitLocationI")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->isa('Bio::Location::SplitLocationI')) { } 2 71 73
98  
99 2 my $result = Bio::Coordinate::Result->new();
100 2 foreach my $loc ( $value->sub_Location(1) ) {
101 4 my $res = $self->_map($loc);
102 4 map { $result->add_sub_Location($_) } $res->each_Location;
103 }
104 2 return $result;
105 } else {
106 71 return $self->_map($value);
107 }
108 }
109  
110  
111 75 ▶sub _map {
Subroutine _map: called CC=21 SCAR=30.5
112 75 my ($self,$value) = @_;
113  
114 75 my $result = Bio::Coordinate::Result->new();
115  
116 75 my $offset = $self->in->start - $self->out->start;
117 75 my $start = $value->start - $offset;
118 75 my $end = $value->end - $offset;
119  
120 75 my $match = Bio::Location::Simple->new;
121 75 $match->location_type($value->location_type);
122 75 $match->strand($self->strand);
123  
124 #within
125 # |-------------------------|
126 # |-|
127 75 ▶ if ($start >= $self->out->start and $end <= $self->out->end) {
Branch: 5 branches
BranchTrueFalseTotal
if ($start >= $self->out->start and $end <= $self->out->end) { } 29 46 75
elsif ($end < $self->out->start or $start > $self->out->end or $value->location_type eq 'IN-BETWEEN' and ($end = $self->out->start) || ($start = $self->out->end)) { } 6 40 46
elsif ($start < $self->out->start and $end <= $self->out->end) { } 13 27 40
elsif ($start >= $self->out->start and $end > $self->out->end) { } 21 6 27
elsif ($start < $self->out->start and $end > $self->out->end) { } 6 0 6
Condition100%3/3
$start >= $self->out->start and $end <= $self->out->end
!ll&&!rl&&r
232329
MC/DC100%2/2
$start >= $self->out->start and $end <= $self->out->end
$start >= $self->out->start $end <= $self->out->end
Truth table100%3/3
A and B
A= $start >= $self->out->startB= $end <= $self->out->end
ABresult
0X0
100
111
128  
129 29 $match->seq_id($self->out->seq_id);
130 29 $result->seq_id($self->out->seq_id);
131  
132 29 ▶ if ($self->strand >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->strand >= 0) { } 19 10 29
133 19 $match->start($start);
134 19 $match->end($end);
135 } else {
136 10 $match->start($self->out->end - $end + $self->out->start);
137 10 $match->end($self->out->end - $start + $self->out->start);
138 }
139 29 ▶ if ($value->strand) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->strand) 27 2 29
140 27 $match->strand($match->strand * $value->strand);
141 27 $result->strand($match->strand);
142 }
143 29 bless $match, 'Bio::Coordinate::Result::Match';
144 29 $result->add_sub_Location($match);
145 }
146 #out
147 # |-------------------------|
148 # |-| or |-|
149 ▶ elsif ( ($end < $self->out->start or $start > $self->out->end ) or
Condition75%9/12
$end < $self->out->start or $start > $self->out->end or $value->location_type eq "IN-BETWEEN" and ($end = $self->out->start) || ($start = $self->out->end)
l!l&&r!l&&!r
4240
$end < $self->out->start or $start > $self->out->end
l!l&&r!l&&!r
3142
$value->location_type eq "IN-BETWEEN" and ($end = $self->out->start) || ($start = $self->out->end)
!ll&&!rl&&r
4002
$end = $self->out->start or $start = $self->out->end
l!l&&r!l&&!r
200
MC/DC60%3/5
$end < $self->out->start or $start > $self->out->end or $value->location_type eq "IN-BETWEEN" and ($end = $self->out->start) || ($start = $self->out->end)
$end < $self->out->start $start > $self->out->end $value->location_type eq "IN-BETWEEN" $end = $self->out->start $start = $self->out->end
Truth table66%4/6
A or B or C and D or E
A= $end < $self->out->startB= $start > $self->out->endC= $value->location_type eq "IN-BETWEEN"D= $end = $self->out->startE= $start = $self->out->end
ABCDEresult
1XXXX1
01XXX1
0011X1
001011
000XX0
001000
150 #insertions just outside the range need special settings
151 ($value->location_type eq 'IN-BETWEEN' and
152 ($end = $self->out->start or $start = $self->out->end))) {
153  
154 6 $match->seq_id($self->in->seq_id);
155 6 $result->seq_id($self->in->seq_id);
156 6 $match->start($value->start);
157 6 $match->end($value->end);
158 6 $match->strand($value->strand);
159  
160 6 bless $match, 'Bio::Coordinate::Result::Gap';
161 6 $result->add_sub_Location($match);
162 }
163 #partial I
164 # |-------------------------|
165 # |-----|
166 ▶ elsif ($start < $self->out->start and $end <= $self->out->end ) {
Condition100%3/3
$start < $self->out->start and $end <= $self->out->end
!ll&&!rl&&r
21613
MC/DC100%2/2
$start < $self->out->start and $end <= $self->out->end
$start < $self->out->start $end <= $self->out->end
Truth table100%3/3
A and B
A= $start < $self->out->startB= $end <= $self->out->end
ABresult
0X0
100
111
167  
168 13 $result->seq_id($self->out->seq_id);
169 13 ▶ if ($value->strand) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->strand) 10 3 13
170 10 $match->strand($match->strand * $value->strand);
171 10 $result->strand($match->strand);
172 }
173 13 my $gap = Bio::Location::Simple->new;
174 13 $gap->start($value->start);
175 13 $gap->end($self->in->start - 1);
176 13 $gap->strand($value->strand);
177 13 $gap->seq_id($self->in->seq_id);
178  
179 13 bless $gap, 'Bio::Coordinate::Result::Gap';
180 13 $result->add_sub_Location($gap);
181  
182 # match
183 13 $match->seq_id($self->out->seq_id);
184  
185 13 ▶ if ($self->strand >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->strand >= 0) { } 12 1 13
186 12 $match->start($self->out->start);
187 12 $match->end($end);
188 } else {
189 1 $match->start($self->out->end - $end + $self->out->start);
190 1 $match->end($self->out->end);
191 }
192 13 bless $match, 'Bio::Coordinate::Result::Match';
193 13 $result->add_sub_Location($match);
194 }
195 #partial II
196 # |-------------------------|
197 # |------|
198 ▶ elsif ($start >= $self->out->start and $end > $self->out->end ) {
Condition66%2/3
$start >= $self->out->start and $end > $self->out->end
!ll&&!rl&&r
6021
MC/DC50%1/2
$start >= $self->out->start and $end > $self->out->end
$start >= $self->out->start $end > $self->out->end
Truth table66%2/3
A and B
A= $start >= $self->out->startB= $end > $self->out->end
ABresult
0X0
100
111
199  
200 21 $match->seq_id($self->out->seq_id);
201 21 $result->seq_id($self->out->seq_id);
202 21 ▶ if ($value->strand) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->strand) 18 3 21
203 18 $match->strand($match->strand * $value->strand);
204 18 $result->strand($match->strand);
205 }
206 21 ▶ if ($self->strand >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->strand >= 0) { } 15 6 21
207 15 $match->start($start);
208 15 $match->end($self->out->end);
209 } else {
210 6 $match->start($self->out->start);
211 6 $match->end($self->out->end - $start + $self->out->start);
212 }
213 21 bless $match, 'Bio::Coordinate::Result::Match';
214 21 $result->add_sub_Location($match);
215  
216 21 my $gap = Bio::Location::Simple->new;
217 21 $gap->start($self->in->end + 1);
218 21 $gap->end($value->end);
219 21 $gap->strand($value->strand);
220 21 $gap->seq_id($self->in->seq_id);
221 21 bless $gap, 'Bio::Coordinate::Result::Gap';
222 21 $result->add_sub_Location($gap);
223  
224 }
225 #enveloping
226 # |-------------------------|
227 # |---------------------------------|
228 ▶ elsif ($start < $self->out->start and $end > $self->out->end ) {
Condition33%1/3
$start < $self->out->start and $end > $self->out->end
!ll&&!rl&&r
006
MC/DC0%0/2
$start < $self->out->start and $end > $self->out->end
$start < $self->out->start $end > $self->out->end
Truth table33%1/3
A and B
A= $start < $self->out->startB= $end > $self->out->end
ABresult
0X0
100
111
229  
230 6 $result->seq_id($self->out->seq_id);
231 6 ▶ if ($value->strand) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->strand) 6 0 6
232 6 $match->strand($match->strand * $value->strand);
233 6 $result->strand($match->strand);
234 }
235 # gap1
236 6 my $gap1 = Bio::Location::Simple->new;
237 6 $gap1->start($value->start);
238 6 $gap1->end($self->in->start - 1);
239 6 $gap1->strand($value->strand);
240 6 $gap1->seq_id($self->in->seq_id);
241 6 bless $gap1, 'Bio::Coordinate::Result::Gap';
242 6 $result->add_sub_Location($gap1);
243  
244 # match
245 6 $match->seq_id($self->out->seq_id);
246  
247 6 $match->start($self->out->start);
248 6 $match->end($self->out->end);
249 6 bless $match, 'Bio::Coordinate::Result::Match';
250 6 $result->add_sub_Location($match);
251  
252 # gap2
253 6 my $gap2 = Bio::Location::Simple->new;
254 6 $gap2->start($self->in->end + 1);
255 6 $gap2->end($value->end);
256 6 $gap2->strand($value->strand);
257 6 $gap2->seq_id($self->in->seq_id);
258 6 bless $gap2, 'Bio::Coordinate::Result::Gap';
259 6 $result->add_sub_Location($gap2);
260  
261 } else {
262 0 $self->throw("Should not be here!");
263 }
264 75 return $result;
265 }
266  
267 7 1;
268  
269 __END__
« Coordinate/Collection.pm ↑ Summary Coordinate/Graph.pm »