Coordinate/Collection.pm

filter: Statementstmt 80.5% 91 / 113 Branchbran 54.0% 27 / 50 Conditioncond 50.0% 10 / 20 MC/DCmcdc 30.7% 4 / 13 Subroutinesub 88.2% 15 / 17 Podpod 100% 9 / 9 totaltotal 70.2% 156 / 222 CC 37 SCAR 24.5
CC
37
Cov
70%
mappers
42.0
_map
16.9
test
12.0
CRAP 11.6
« Coordinate/Utils.pm ↑ Summary Coordinate/Pair.pm »
1 package Bio::Coordinate::Collection;
2 6 our $AUTHORITY = 'cpan:BIOPERLML';
3 6 $Bio::Coordinate::Collection::VERSION = '1.007001';
4 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Bio::Coordinate::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Bio::Coordinate::Result::Gap;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use parent qw(Bio::Root::Root Bio::Coordinate::MapperI);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # ABSTRACT: Noncontinuous match between two coordinate sets.
12 # AUTHOR: Heikki Lehvaslaiho <heikki@bioperl.org>
13 # OWNER: Heikki Lehvaslaiho
14 # LICENSE: Perl_5
15  
16 # CONTRIBUTOR: Ewan Birney <birney@ebi.ac.uk>
17  
18  
19  
20 35 ▶sub new {
Subroutine new: called CC=5 SCAR=16.4
Pod documented
21 35 my($class,@args) = @_;
22 35 my $self = $class->SUPER::new(@args);
23  
24 35 $self->{'_mappers'} = [];
25  
26 35 my($in, $out, $strict, $mappers, $return_match) =
27 $self->_rearrange([qw(IN
28 OUT
29 STRICT
30 MAPPERS
31 RETURN_MATCH
32 )],
33 @args);
34  
35 35 ▶ $in && $self->in($in);
Branch: 1 branch
BranchTrueFalseTotal
$in and $self->in($in) 0 35 35
36 35 ▶ $out && $self->out($out);
Branch: 1 branch
BranchTrueFalseTotal
$out and $self->out($out) 0 35 35
37 35 ▶ $mappers && $self->mappers($mappers);
Branch: 1 branch
BranchTrueFalseTotal
$mappers and $self->mappers($mappers) 0 35 35
38 35 ▶ $return_match && $self->return_match('return_match');
Branch: 1 branch
BranchTrueFalseTotal
$return_match and $self->return_match("return_match") 1 34 35
39 35 return $self; # success - we hope!
40 }
41  
42  
43 199 ▶sub add_mapper {
Subroutine add_mapper: called CC=4 SCAR=15.0
Pod documented
44 199 my ($self,$value) = @_;
45  
46 199 ▶ $self->throw("Is not a Bio::Coordinate::MapperI but a [$self]")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and $value->isa("Bio::Coordinate::MapperI") 0 199 199
Condition33%1/3
defined $value and $value->isa("Bio::Coordinate::MapperI")
!ll&&!rl&&r
00199
MC/DC0%0/2
defined $value and $value->isa("Bio::Coordinate::MapperI")
defined $value $value->isa("Bio::Coordinate::MapperI")
Truth table33%1/3
A and B
A= defined $valueB= $value->isa("Bio::Coordinate::MapperI")
ABresult
0X0
100
111
47 unless defined $value && $value->isa('Bio::Coordinate::MapperI');
48  
49 # test pair range lengths
50 199 ▶ $self->warn("Coordinates in pair [". $value . ":" .
Branch: 1 branch
BranchTrueFalseTotal
unless $value->test 0 199 199
51 $value->in->seq_id . "/". $value->out->seq_id .
52 "] are not right.")
53 unless $value->test;
54  
55 199 $self->_is_sorted(0);
56 199 push(@{$self->{'_mappers'}},$value);
57 }
58  
59  
60 0 ▶sub mappers{
Subroutine mappers: not called CC=6 SCAR=37.4
Pod documented
61 0 my ($self,@args) = @_;
62  
63 0 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 0 0
64 0 ▶ if (@args == 1 && ref $args[0] eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (@args == 1 and ref $args[0] eq "ARRAY") 0 0 0
Condition0%0/3
@args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
@args == 1 and ref $args[0] eq "ARRAY"
@args == 1 ref $args[0] eq "ARRAY"
Truth table0%0/3
A and B
A= @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
65 0 @args = @{$args[0]};
66 }
67 0 ▶ $self->throw("Is not a Bio::Coordinate::MapperI but a [$self]")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args[0] and $args[0]->isa("Bio::Coordinate::MapperI") 0 0 0
Condition0%0/3
defined $args[0] and $args[0]->isa("Bio::Coordinate::MapperI")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args[0] and $args[0]->isa("Bio::Coordinate::MapperI")
defined $args[0] $args[0]->isa("Bio::Coordinate::MapperI")
Truth table0%0/3
A and B
A= defined $args[0]B= $args[0]->isa("Bio::Coordinate::MapperI")
ABresult
0X0
100
111
68 unless defined $args[0] && $args[0]->isa('Bio::Coordinate::MapperI');
69 0 push(@{$self->{'_mappers'}}, @args);
70 }
71  
72 0 return @{$self->{'_mappers'}};
73 }
74  
75  
76 72 ▶sub each_mapper{
Subroutine each_mapper: called CC=1 SCAR=0.0
Pod documented
77 72 my ($self) = @_;
78 72 return @{$self->{'_mappers'}};
79 }
80  
81  
82 1 ▶sub mapper_count{
Subroutine mapper_count: called CC=2 SCAR=7.1
Pod documented
83 1 my $self = shift;
84 1 ▶ return scalar @{$self->{'_mappers'} || []};
Condition50%1/2
$self->{'_mappers'} || []
l!l
10
MC/DC0%0/1
$self->{'_mappers'} || []
$self->{'_mappers'}
Truth table50%1/2
A
A= $self->{'_mappers'}
Aresult
11
00
85 }
86  
87  
88 19 ▶sub swap {
Subroutine swap: called CC=2 SCAR=6.9
Pod documented
89 19 my ($self) = @_;
90  
91 19 ▶ $self->sort unless $self->_is_sorted;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_sorted 8 11 19
92 19 map {$_->swap;} @{$self->{'_mappers'}};
93 ($self->{'_in_ids'}, $self->{'_out_ids'}) =
94 19 ($self->{'_out_ids'}, $self->{'_in_ids'});
95 19 1;
96 }
97  
98  
99 0 ▶sub test {
Subroutine test: not called CC=3 SCAR=24.8
Pod documented
100 0 my ($self) = @_;
101  
102 0 my $res = 1;
103  
104 0 foreach my $mapper ($self->each_mapper) {
105 0 ▶ unless( $mapper->test ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mapper->test) 0 0 0
106 0 $self->warn("Coordinates in pair [". $mapper . ":" .
107 $mapper->in->seq_id . "/". $mapper->out->seq_id .
108 "] are not right.");
109 0 $res = 0;
110 }
111 }
112 0 $res;
113 }
114  
115  
116 23 ▶sub map {
Subroutine map: called CC=7 SCAR=19.6
Pod documented
117 23 my ($self,$value) = @_;
118  
119 23 ▶ $self->throw("Need to pass me a value.")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 23 23
120 unless defined $value;
121 23 ▶ $self->throw("I need a Bio::Location, not [$value]")
Branch: 1 branch
BranchTrueFalseTotal
unless $value->isa("Bio::LocationI") 0 23 23
122 unless $value->isa('Bio::LocationI');
123 23 ▶ $self->throw("No coordinate mappers!")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->each_mapper 0 23 23
124 unless $self->each_mapper;
125  
126 23 ▶ $self->sort unless $self->_is_sorted;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_sorted 8 15 23
127  
128 23 ▶ if ($value->isa("Bio::Location::SplitLocationI")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->isa('Bio::Location::SplitLocationI')) { } 3 20 23
129  
130 3 my $result = Bio::Coordinate::Result->new();
131 3 foreach my $loc ( $value->sub_Location(1) ) {
132  
133 5 my $res = $self->_map($loc);
134 5 map { $result->add_sub_Location($_) } $res->each_Location;
135  
136 }
137 3 return $result;
138  
139 } else {
140 20 return $self->_map($value);
141 }
142  
143 }
144  
145  
146 25 ▶sub _map {
Subroutine _map: called CC=12 SCAR=28.3
147 25 my ($self,$value) = @_;
148  
149 25 my $result = Bio::Coordinate::Result->new(-is_remote=>1);
150  
151 IDMATCH: {
152  
153 # bail out now we if are forcing the use of an ID
154 # and it is not in this collection
155 25 last IDMATCH if defined $value->seq_id &&
156 25 ▶ ! $self->{'_in_ids'}->{$value->seq_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $value->seq_id and not $self->{"_in_ids"}{$value->seq_id} 0 25 25
Condition66%2/3
defined $value->seq_id and not $self->{"_in_ids"}{$value->seq_id}
!ll&&!rl&&r
10150
MC/DC0%0/2
defined $value->seq_id and not $self->{"_in_ids"}{$value->seq_id}
defined $value->seq_id not $self->{"_in_ids"}{$value->seq_id}
Truth table66%2/3
A and not(B)
A= defined $value->seq_idB= not $self->{"_in_ids"}{$value->seq_id}
ABresult
0X0
100
111
157  
158 25 foreach my $pair ($self->each_mapper) {
159  
160 # if we are limiting input to a certain ID
161 167 ▶ next if defined $value->seq_id && $value->seq_id ne $pair->in->seq_id;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value->seq_id and $value->seq_id ne $pair->in->seq_id 100 67 167
Condition100%3/3
defined $value->seq_id and $value->seq_id ne $pair->in->seq_id
!ll&&!rl&&r
3631100
MC/DC100%2/2
defined $value->seq_id and $value->seq_id ne $pair->in->seq_id
defined $value->seq_id $value->seq_id ne $pair->in->seq_id
Truth table100%3/3
A and B
A= defined $value->seq_idB= $value->seq_id ne $pair->in->seq_id
ABresult
0X0
100
111
162  
163 # if we haven't even reached the start, move on
164 67 ▶ next if $pair->in->end < $value->start;
Branch: 1 branch
BranchTrueFalseTotal
if $pair->in->end < $value->start 18 49 67
165 # if we have over run, break
166 49 ▶ last if $pair->in->start > $value->end;
Branch: 1 branch
BranchTrueFalseTotal
if $pair->in->start > $value->end 13 36 49
167  
168 36 my $subres = $pair->map($value);
169 36 $result->add_result($subres);
170 }
171 }
172  
173 25 ▶ $result->seq_id($result->match->seq_id) if $result->match;
Branch: 1 branch
BranchTrueFalseTotal
if $result->match 25 0 25
174 25 ▶ unless ($result->each_Location) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result->each_Location) 0 25 25
175 #build one gap;
176 0 my $gap = Bio::Location::Simple->new(-start => $value->start,
177 -end => $value->end,
178 -strand => $value->strand,
179 -location_type => $value->location_type
180 );
181 0 ▶ $gap->seq_id($value->seq_id) if defined $value->seq_id;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value->seq_id 0 0 0
182 0 bless $gap, 'Bio::Coordinate::Result::Gap';
183 0 ▶ $result->seq_id($value->seq_id) if defined $value->seq_id;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value->seq_id 0 0 0
184 0 $result->add_sub_Location($gap);
185 }
186 25 return $result;
187 }
188  
189  
190 17 ▶sub sort{
Subroutine sort: called CC=2 SCAR=6.9
Pod documented
191 17 my ($self) = @_;
192  
193 139 @{$self->{'_mappers'}} = map { $_->[0] }
194 132 sort { $a->[1] <=> $b->[1] }
195 139 map { [ $_, $_->in->start] }
196 17 @{$self->{'_mappers'}};
197  
198 #create hashes for sequence ids
199 17 $self->{'_in_ids'} = ();
200 17 $self->{'_out_ids'} = ();
201 17 foreach ($self->each_mapper) {
202 139 $self->{'_in_ids'}->{$_->in->seq_id} = 1;
203 139 $self->{'_out_ids'}->{$_->out->seq_id} = 1;
204 }
205  
206 17 $self->_is_sorted(1);
207 }
208  
209  
210 258 ▶sub _is_sorted{
Subroutine _is_sorted: called CC=3 SCAR=11.0
211 258 my ($self,$value) = @_;
212  
213 258 ▶ $self->{'_is_sorted'} = 1 if defined $value && $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and $value 17 241 258
Condition100%3/3
defined $value and $value
!ll&&!rl&&r
4219917
MC/DC100%2/2
defined $value and $value
defined $value $value
Truth table100%3/3
A and B
A= defined $valueB= $value
ABresult
0X0
100
111
214 258 return $self->{'_is_sorted'};
215 }
216  
217 6 1;
218  
219 __END__
« Coordinate/Utils.pm ↑ Summary Coordinate/Pair.pm »