Coordinate/GeneMapper.pm

filter: Statementstmt 73.4% 296 / 403 Branchbran 58.1% 93 / 160 Conditioncond 53.6% 67 / 125 MC/DCmcdc 26.0% 18 / 69 Subroutinesub 91.1% 31 / 34 Podpod 100% 15 / 15 totaltotal 64.5% 520 / 806 CC 138 SCAR 36.0
CC
138
Cov
66%
to_string
110.0
map
89.2
peptide
30.0
CRAP 36.6
↑ Summary Coordinate/Utils.pm »
1 package Bio::Coordinate::GeneMapper;
2 2 our $AUTHORITY = 'cpan:BIOPERLML';
3 2 $Bio::Coordinate::GeneMapper::VERSION = '1.007001';
4 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Bio::Coordinate::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Bio::Location::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Bio::Coordinate::Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Bio::Coordinate::Collection;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Bio::Coordinate::Pair;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Bio::Coordinate::ExtrapolatingPair;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use parent qw(Bio::Root::Root Bio::Coordinate::MapperI);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # ABSTRACT: Transformations between gene related coordinate systems.
16 # AUTHOR: Heikki Lehvaslaiho <heikki@bioperl.org>
17 # OWNER: Heikki Lehvaslaiho
18 # LICENSE: Perl_5
19  
20  
21 # first set internal values for all translation tables
22  
23 2 our %COORDINATE_SYSTEMS = (
24 peptide => 10,
25 propeptide => 9,
26 frame => 8,
27 cds => 7,
28 negative_intron => 6,
29 intron => 5,
30 exon => 4,
31 inex => 3,
32 gene => 2,
33 chr => 1,
34 );
35  
36 2 our %COORDINATE_INTS = (
37 10 => 'peptide',
38 9 => 'propeptide',
39 8 => 'frame',
40 7 => 'cds',
41 6 => 'negative_intron',
42 5 => 'intron',
43 4 => 'exon',
44 3 => 'inex',
45 2 => 'gene',
46 1 => 'chr'
47 );
48  
49 2 our $TRANSLATION = $COORDINATE_SYSTEMS{'cds'}. "-". $COORDINATE_SYSTEMS{'propeptide'};
50  
51 2 our $DAG = {
52 10 => [],
53 9 => [10],
54 8 => [],
55 7 => [8, 9],
56 6 => [],
57 5 => [6],
58 4 => [7],
59 3 => [4, 5],
60 2 => [3, 4, 5, 7],
61 1 => [2],
62 };
63  
64 2 our $NOZERO_VALUES = {
65 0 => 0,
66 'in' => 1,
67 'out' => 2,
68 'in&out' => 3,
69 };
70  
71 2 our $NOZERO_KEYS = {
72 0 => 0,
73 1 => 'in',
74 2 => 'out',
75 3 => 'in&out',
76 };
77  
78  
79 7 ▶sub new {
Subroutine new: called CC=9 SCAR=22.1
Pod documented
80 7 my($class,@args) = @_;
81 7 my $self = $class->SUPER::new(@args);
82  
83 # prime the graph
84 7 my $graph = Bio::Coordinate::Graph->new();
85 7 $graph->hash_of_arrays($DAG);
86 7 $self->graph($graph);
87  
88 7 my($in, $out, $peptide_offset, $exons,
89 $cds, $nozero, $strict) =
90 $self->_rearrange([qw(IN
91 OUT
92 PEPTIDE_OFFSET
93 EXONS
94 CDS
95 NOZERO
96 STRICT
97 )],
98 @args);
99  
100 # direction of mapping when going chr to protein
101 7 $self->{_direction} = 1;
102  
103 7 ▶ $in && $self->in($in);
Branch: 1 branch
BranchTrueFalseTotal
$in and $self->in($in) 5 2 7
104 7 ▶ $out && $self->out($out);
Branch: 1 branch
BranchTrueFalseTotal
$out and $self->out($out) 5 2 7
105 7 ▶ $cds && $self->cds($cds);
Branch: 1 branch
BranchTrueFalseTotal
$cds and $self->cds($cds) 1 6 7
106 7 ▶ $exons && ref($exons) =~ /ARRAY/i && $self->exons(@$exons);
Branch: 1 branch
BranchTrueFalseTotal
$exons and ref($exons) =~ /ARRAY/i and $self->exons(@$exons) 0 7 7
Condition66%2/3
$exons and ref($exons) =~ /ARRAY/i
!ll&&!rl&&r
610
MC/DC0%0/2
$exons and ref($exons) =~ /ARRAY/i
$exons ref($exons) =~ /ARRAY/i
Truth table66%2/3
A and B
A= $exonsB= ref($exons) =~ /ARRAY/i
ABresult
0X0
100
111
107 7 ▶ $peptide_offset && $self->peptide_offset($peptide_offset);
Branch: 1 branch
BranchTrueFalseTotal
$peptide_offset and $self->peptide_offset($peptide_offset) 1 6 7
108 7 ▶ $nozero && $self->nozero($nozero);
Branch: 1 branch
BranchTrueFalseTotal
$nozero and $self->nozero($nozero) 0 7 7
109 7 ▶ $strict && $self->strict($strict);
Branch: 1 branch
BranchTrueFalseTotal
$strict and $self->strict($strict) 0 7 7
110  
111 7 return $self; # success - we hope!
112 }
113  
114  
115 16 ▶sub in {
Subroutine in: called CC=3 SCAR=11.3
Pod documented
116 16 my ($self,$value) = @_;
117 16 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 16 0 16
118 $self->throw("Not a valid input coordinate system name [$value]\n".
119 "Valid values are ". join(", ", keys %COORDINATE_SYSTEMS ))
120 16 ▶ unless defined $COORDINATE_SYSTEMS{$value};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Bio::Coordinate::GeneMapper::COORDINATE_SYSTEMS{$value} 0 16 16
121  
122 16 $self->{'_in'} = $COORDINATE_SYSTEMS{$value};
123 }
124 16 return $COORDINATE_INTS{ $self->{'_in'} };
125 }
126  
127  
128 22 ▶sub out {
Subroutine out: called CC=3 SCAR=11.3
Pod documented
129 22 my ($self,$value) = @_;
130 22 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 22 0 22
131 $self->throw("Not a valid input coordinate system name [$value]\n".
132 "Valid values are ". join(", ", keys %COORDINATE_SYSTEMS ))
133 22 ▶ unless defined $COORDINATE_SYSTEMS{$value};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Bio::Coordinate::GeneMapper::COORDINATE_SYSTEMS{$value} 0 22 22
134  
135 22 $self->{'_out'} = $COORDINATE_SYSTEMS{$value};
136 }
137 22 return $COORDINATE_INTS{ $self->{'_out'} };
138 }
139  
140  
141 2 ▶sub strict {
Subroutine strict: called CC=4 SCAR=17.9
Pod documented
142 2 my ($self,$value) = @_;
143 2 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 2 2
144 0 ▶ $value ? ( $self->{'_strict'} = 1 ) : ( $self->{'_strict'} = 0 );
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 0 0 0
145 ## update in each mapper !!
146 }
147 2 ▶ return $self->{'_strict'} || 0 ;
Condition50%1/2
$self->{'_strict'} || 0
l!l
02
MC/DC0%0/1
$self->{'_strict'} || 0
$self->{'_strict'}
Truth table50%1/2
A
A= $self->{'_strict'}
Aresult
11
00
148 }
149  
150  
151 2 ▶sub nozero {
Subroutine nozero: called CC=4 SCAR=14.3
Pod documented
152 2 my ($self,$value) = @_;
153  
154 2 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 2 0 2
155 $self->throw("Not a valid value for nozero [$value]\n".
156 0 "Valid values are ". join(", ", keys %{$NOZERO_VALUES} ))
157 2 ▶ unless defined $NOZERO_VALUES->{$value};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Bio::Coordinate::GeneMapper::NOZERO_VALUES->{$value} 0 2 2
158 2 $self->{'_nozero'} = $NOZERO_VALUES->{$value};
159 }
160  
161 2 ▶ my $res = $self->{'_nozero'} || 0;
Condition100%2/2
$self->{'_nozero'} || 0
l!l
11
MC/DC100%1/1
$self->{'_nozero'} || 0
$self->{'_nozero'}
Truth table100%2/2
A
A= $self->{'_nozero'}
Aresult
11
00
162 2 return $NOZERO_KEYS->{$res};
163 }
164  
165  
166 7 ▶sub graph {
Subroutine graph: called CC=3 SCAR=11.3
Pod documented
167 7 my ($self,$value) = @_;
168 7 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 7 0 7
169 7 ▶ $self->throw("Not a valid graph [$value]\n")
Branch: 1 branch
BranchTrueFalseTotal
unless $value->isa("Bio::Coordinate::Graph") 0 7 7
170 unless $value->isa('Bio::Coordinate::Graph');
171 7 $self->{'_graph'} = $value;
172 }
173 7 return $self->{'_graph'};
174 }
175  
176  
177 0 ▶sub peptide {
Subroutine peptide: not called CC=5 SCAR=34.0
Pod documented
178 0 my ($self, $value) = @_;
179 0 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
180 0 ▶ $self->throw("I need a Bio::LocationI, not [". $value. "]")
Branch: 1 branch
BranchTrueFalseTotal
unless $value->isa("Bio::LocationI") 0 0 0
181 unless $value->isa('Bio::LocationI');
182  
183 0 ▶ $self->throw("Peptide start not defined")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value->start 0 0 0
184 unless defined $value->start;
185 0 $self->{'_peptide_offset'} = $value->start - 1;
186  
187 0 ▶ $self->throw("Peptide end not defined")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value->end 0 0 0
188 unless defined $value->end;
189 0 $self->{'_peptide_length'} = $value->end - $self->{'_peptide_offset'};
190  
191 my $a = $self->_create_pair
192 ('propeptide', 'peptide', $self->strict,
193 0 $self->{'_peptide_offset'}, $self->{'_peptide_length'} );
194 0 my $mapper = $COORDINATE_SYSTEMS{'propeptide'}. "-". $COORDINATE_SYSTEMS{'peptide'};
195 0 $self->{'_mappers'}->{$mapper} = $a;
196 }
197 return Bio::Location::Simple->new
198 (-seq_id => 'propeptide',
199 -start => $self->{'_peptide_offset'} + 1 ,
200 0 -end => $self->{'_peptide_length'} + $self->{'_peptide_offset'},
201 -strand => 1,
202 -verbose => $self->verbose,
203 );
204 }
205  
206  
207 2 ▶sub peptide_offset {
Subroutine peptide_offset: called CC=6 SCAR=20.8
Pod documented
208 2 my ($self,$offset, $len) = @_;
209 2 ▶ if( defined $offset) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $offset) 2 0 2
210 2 ▶ $self->throw("I need an integer, not [$offset]")
Branch: 1 branch
BranchTrueFalseTotal
unless $offset =~ /^[+-]?\d+$/ 0 2 2
211 unless $offset =~ /^[+-]?\d+$/;
212 2 $self->{'_peptide_offset'} = $offset;
213  
214 2 ▶ if (defined $len) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $len) 0 2 2
215 0 ▶ $self->throw("I need an integer, not [$len]")
Branch: 1 branch
BranchTrueFalseTotal
unless $len =~ /^[+-]?\d+$/ 0 0 0
216 unless $len =~ /^[+-]?\d+$/;
217 0 $self->{'_peptide_length'} = $len;
218 }
219  
220 my $a = $self->_create_pair
221 2 ('propeptide', 'peptide', $self->strict, $offset, $self->{'_peptide_length'} );
222 2 my $mapper = $COORDINATE_SYSTEMS{'propeptide'}. "-". $COORDINATE_SYSTEMS{'peptide'};
223 2 $self->{'_mappers'}->{$mapper} = $a;
224 }
225 2 ▶ return $self->{'_peptide_offset'} || 0;
Condition50%1/2
$self->{'_peptide_offset'} || 0
l!l
20
MC/DC0%0/1
$self->{'_peptide_offset'} || 0
$self->{'_peptide_offset'}
Truth table50%1/2
A
A= $self->{'_peptide_offset'}
Aresult
11
00
226 }
227  
228  
229 0 ▶sub peptide_length {
Subroutine peptide_length: not called CC=4 SCAR=30.0
Pod documented
230 0 my ($self, $len) = @_;
231 0 ▶ if( defined $len) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $len) 0 0 0
232 0 ▶ $self->throw("I need an integer, not [$len]")
Branch: 1 branch
BranchTrueFalseTotal
if defined $len and not $len =~ /^[+-]?\d+$/ 0 0 0
Condition0%0/3
defined $len and not $len =~ /^[+-]?\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $len and not $len =~ /^[+-]?\d+$/
defined $len not $len =~ /^[+-]?\d+$/
Truth table0%0/3
A and not(B)
A= defined $lenB= not $len =~ /^[+-]?\d+$/
ABresult
0X0
100
111
233 if defined $len && $len !~ /^[+-]?\d+$/;
234 0 $self->{'_peptide_length'} = $len;
235 }
236 0 return $self->{'_peptide_length'};
237 }
238  
239  
240 5 ▶sub exons {
Subroutine exons: called CC=20 SCAR=30.7
Pod documented
241 5 my ($self,@value) = @_;
242 5 my $cds_mapper = $COORDINATE_SYSTEMS{'gene'}. "-". $COORDINATE_SYSTEMS{'cds'};
243 my $inex_mapper =
244 5 $COORDINATE_SYSTEMS{'gene'}. "-". $COORDINATE_SYSTEMS{'inex'};
245 my $exon_mapper =
246 5 $COORDINATE_SYSTEMS{'gene'}. "-". $COORDINATE_SYSTEMS{'exon'};
247 my $intron_mapper =
248 5 $COORDINATE_SYSTEMS{'gene'}. "-". $COORDINATE_SYSTEMS{'intron'};
249 my $negative_intron_mapper =
250 5 $COORDINATE_SYSTEMS{'intron'}. "-". $COORDINATE_SYSTEMS{'negative_intron'};
251 5 my $exon_cds_mapper = $COORDINATE_SYSTEMS{'exon'}. "-". $COORDINATE_SYSTEMS{'cds'};
252  
253 5 ▶ if(@value) {
Branch: 1 branch
BranchTrueFalseTotal
if (@value) 5 0 5
254 5 ▶ if (ref($value[0]) &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value[0] and $value[0]->isa('Bio::SeqFeatureI') and $value[0]->location->isa('Bio::Location::SplitLocationI')) { } 0 5 5
Condition33%2/6
ref $value[0] and $value[0]->isa("Bio::SeqFeatureI") and $value[0]->location->isa("Bio::Location::SplitLocationI")
!ll&&!rl&&r
500
ref $value[0] and $value[0]->isa("Bio::SeqFeatureI")
!ll&&!rl&&r
050
MC/DC0%0/3
ref $value[0] and $value[0]->isa("Bio::SeqFeatureI") and $value[0]->location->isa("Bio::Location::SplitLocationI")
ref $value[0] $value[0]->isa("Bio::SeqFeatureI") $value[0]->location->isa("Bio::Location::SplitLocationI")
Truth table25%1/4
A and B and C
A= ref $value[0]B= $value[0]->isa("Bio::SeqFeatureI")C= $value[0]->location->isa("Bio::Location::SplitLocationI")
ABCresult
0XX0
10X0
1100
1111
255 $value[0]->isa('Bio::SeqFeatureI') and
256 $value[0]->location->isa('Bio::Location::SplitLocationI')) {
257 0 @value = $value[0]->location->each_Location;
258 } else {
259 5 ▶ $self->throw("I need an array , not [@value]")
Branch: 1 branch
BranchTrueFalseTotal
unless ref \@value eq "ARRAY" 0 5 5
260 unless ref \@value eq 'ARRAY';
261 5 ▶ $self->throw("I need a reference to an array of Bio::LocationIs, not to [".
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value[0] and $value[0]->isa("Bio::LocationI") 0 5 5
Condition33%1/3
ref $value[0] and $value[0]->isa("Bio::LocationI")
!ll&&!rl&&r
005
MC/DC0%0/2
ref $value[0] and $value[0]->isa("Bio::LocationI")
ref $value[0] $value[0]->isa("Bio::LocationI")
Truth table33%1/3
A and B
A= ref $value[0]B= $value[0]->isa("Bio::LocationI")
ABresult
0X0
100
111
262 $value[0]. "]")
263 unless ref $value[0] and $value[0]->isa('Bio::LocationI');
264 }
265  
266 #
267 # sort the input array
268 #
269 # and if the used has not defined CDS assume it is the complete exonic range
270 5 ▶ if (defined $value[0]->strand &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value[0]->strand and $value[0]->strand == -1) { } 2 3 5
Condition66%2/3
defined $value[0]->strand and $value[0]->strand == -1
!ll&&!rl&&r
032
MC/DC50%1/2
defined $value[0]->strand and $value[0]->strand == -1
defined $value[0]->strand $value[0]->strand == -1
Truth table66%2/3
A and B
A= defined $value[0]->strandB= $value[0]->strand == -1
ABresult
0X0
100
111
271 $value[0]->strand == - 1) { #reverse strand
272 6 @value = map { $_->[0] }
273 5 sort { $b->[1] <=> $a->[1] }
274 2 map { [ $_, $_->start] }
275 @value;
276  
277 2 ▶ unless ($self->cds) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->cds) 0 2 2
278 0 $self->cds(Bio::Location::Simple->new
279 (-start => $value[-1]->start,
280 -end => $value[0]->end,
281 -strand => $value[0]->strand,
282 -seq_id => $value[0]->seq_id,
283 -verbose => $self->verbose,
284 )
285 );
286 }
287 } else { # undef or forward strand
288 9 @value = map { $_->[0] }
289 9 sort { $a->[1] <=> $b->[1] }
290 3 map { [ $_, $_->start] }
291 @value;
292 3 ▶ unless ($self->cds) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->cds) 0 3 3
293 0 $self->cds(Bio::Location::Simple->new
294 (-start => $value[0]->start,
295 -end => $value[-1]->end,
296 -strand => $value[0]->strand,
297 -seq_id => $value[0]->seq_id,
298 -verbose => $self->verbose,
299 )
300 );
301 }
302  
303 }
304  
305 5 $self->{'_chr_exons'} = \@value;
306  
307 # transform exons from chromosome to gene coordinates
308 # but only if gene coordinate system has been set
309 5 my @exons ;
310 #my $gene_mapper = $self->$COORDINATE_SYSTEMS{'chr'}. "-". $COORDINATE_SYSTEMS{'gene'};
311 5 my $gene_mapper = "1-2";
312 5 ▶ if (defined $self->{'_mappers'}->{$gene_mapper} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'_mappers'}{$gene_mapper}) { } 5 0 5
313  
314 5 my $tmp_in = $self->{'_in'};
315 5 my $tmp_out = $self->{'_out'};
316 5 my $tmp_verb = $self->verbose;
317 5 $self->verbose(0);
318  
319 5 $self->in('chr');
320 5 $self->out('gene');
321 5 @exons = map {$self->map($_) } @value;
322  
323 5 $self->{'_in'} = ($tmp_in);
324 5 $self->{'_out'} = ($tmp_out);
325 5 $self->verbose($tmp_verb);
326 } else {
327 0 @exons = @value;
328 }
329  
330 5 my $cds_map = Bio::Coordinate::Collection->new;
331 5 my $inex_map = Bio::Coordinate::Collection->new;
332 5 my $exon_map = Bio::Coordinate::Collection->new;
333 5 my $exon_cds_map = Bio::Coordinate::Collection->new;
334 5 my $intron_map = Bio::Coordinate::Collection->new;
335 5 my $negative_intron_map = Bio::Coordinate::Collection->new;
336  
337 5 my $tr_end = 0;
338 5 my $coffset;
339 my $exon_counter;
340 5 my $prev_exon_end;
341  
342 5 for my $exon ( @exons ) {
343 15 $exon_counter++;
344  
345 #
346 # gene -> cds
347 #
348  
349 15 my $match1 = Bio::Location::Simple->new
350 (-seq_id =>'gene' ,
351 -start => $exon->start,
352 -end => $exon->end,
353 -strand => 1,
354 -verbose=> $self->verbose);
355  
356 15 my $match2 = Bio::Location::Simple->new
357 (-seq_id => 'cds',
358 -start => $tr_end + 1,
359 -end => $tr_end + $exon->end - $exon->start +1,
360 -strand=>$exon->strand,
361 -verbose=>$self->verbose);
362  
363 15 $cds_map->add_mapper(Bio::Coordinate::Pair->new
364 (-in => $match1,
365 -out => $match2,
366 )
367 );
368  
369 15 ▶ if ($exon->start <= 1 and $exon->end >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exon->start <= 1 and $exon->end >= 1) 5 10 15
Condition100%3/3
$exon->start <= 1 and $exon->end >= 1
!ll&&!rl&&r
735
MC/DC100%2/2
$exon->start <= 1 and $exon->end >= 1
$exon->start <= 1 $exon->end >= 1
Truth table100%3/3
A and B
A= $exon->start <= 1B= $exon->end >= 1
ABresult
0X0
100
111
370 5 $coffset = $tr_end - $exon->start + 1;
371 }
372 15 $tr_end = $tr_end + $exon->end - $exon->start + 1;
373  
374 #
375 # gene -> intron
376 #
377  
378 15 ▶ if (defined $prev_exon_end) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prev_exon_end) 10 5 15
379 10 my $match3 = Bio::Location::Simple->new
380 (-seq_id => 'gene',
381 -start => $prev_exon_end + 1,
382 -end => $exon->start -1,
383 -strand => $exon->strand,
384 -verbose => $self->verbose);
385  
386 10 my $match4 = Bio::Location::Simple->new
387 (-seq_id => 'intron'. ($exon_counter -1),
388 -start => 1,
389 -end => $exon->start - 1 - $prev_exon_end,
390 -strand =>$exon->strand,
391 -verbose => $self->verbose,);
392  
393 # negative intron coordinates
394 10 my $match5 = Bio::Location::Simple->new
395 (-seq_id => 'intron'. ($exon_counter -1),
396 -start => -1 * ($exon->start - 2 - $prev_exon_end) -1,
397 -end => -1,
398 -strand => $exon->strand,
399 -verbose => $self->verbose);
400  
401 10 $inex_map->add_mapper(Bio::Coordinate::Pair->new
402 (-in => $match3,
403 -out => $match4
404 )
405 );
406 10 $intron_map->add_mapper(Bio::Coordinate::Pair->new
407 (-in => $self->_clone_loc($match3),
408 -out => $self->_clone_loc($match4)
409 )
410 );
411 10 $negative_intron_map->add_mapper(Bio::Coordinate::Pair->new
412 (-in => $self->_clone_loc($match4),
413 -out => $match5
414 ));
415  
416 }
417  
418 # store the value
419 15 $prev_exon_end = $exon->end;
420  
421 #
422 # gene -> exon
423 #
424 15 my $match6 = Bio::Location::Simple->new
425 (-seq_id => 'exon'. $exon_counter,
426 -start => 1,
427 -end => $exon->end - $exon->start +1,
428 -strand => $exon->strand,
429 -verbose=> $self->verbose,);
430  
431 15 my $pair2 = Bio::Coordinate::Pair->new(-in => $self->_clone_loc($match1),
432 -out => $match6
433 );
434 15 my $pair3 = Bio::Coordinate::Pair->new(-in => $self->_clone_loc($match6),
435 -out => $self->_clone_loc($match2)
436 );
437 15 $inex_map->add_mapper(Bio::Coordinate::Pair->new
438 (-in => $self->_clone_loc($match1),
439 -out => $match6
440 )
441 );
442 15 $exon_map->add_mapper(Bio::Coordinate::Pair->new
443 (-in => $self->_clone_loc($match1),
444 -out => $self->_clone_loc($match6)
445 )
446 );
447 15 $exon_cds_map->add_mapper(Bio::Coordinate::Pair->new
448 (-in => $self->_clone_loc($match6),
449 -out => $self->_clone_loc($match2)
450 )
451 );
452  
453 }
454  
455 # move coordinate start if exons have negative values
456 5 ▶ if ($coffset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($coffset) 4 1 5
457 4 foreach my $m ($cds_map->each_mapper) {
458 12 $m->out->start($m->out->start - $coffset);
459 12 $m->out->end($m->out->end - $coffset);
460 }
461  
462 }
463  
464 5 $self->{'_mappers'}->{$cds_mapper} = $cds_map;
465 5 $self->{'_mappers'}->{$exon_cds_mapper} = $exon_cds_map;
466 5 $self->{'_mappers'}->{$inex_mapper} = $inex_map;
467 5 $self->{'_mappers'}->{$exon_mapper} = $exon_map;
468 5 $self->{'_mappers'}->{$intron_mapper} = $intron_map;
469 5 $self->{'_mappers'}->{$negative_intron_mapper} = $negative_intron_map;
470 }
471 5 ▶ return @{$self->{'_chr_exons'}} || 0;
Condition50%1/2
@{$self->{'_chr_exons'};} || 0
l!l
50
MC/DC0%0/1
@{$self->{'_chr_exons'};} || 0
@{$self->{'_chr_exons'};}
Truth table50%1/2
A
A= @{$self->{'_chr_exons'};}
Aresult
11
00
472 }
473  
474  
475 150 ▶sub _clone_loc { # clone a simple location
Subroutine _clone_loc: called CC=2 SCAR=7.1
476 150 my ($self,$loc) = @_;
477  
478 150 ▶ $self->throw("I need a Bio::Location::Simple , not [". ref $loc. "]")
Branch: 1 branch
BranchTrueFalseTotal
unless $loc->isa("Bio::Location::Simple") 0 150 150
479 unless $loc->isa('Bio::Location::Simple');
480  
481 150 return Bio::Location::Simple->new
482 (-verbose => $self->verbose,
483 -seq_id => $loc->seq_id,
484 -start => $loc->start,
485 -end => $loc->end,
486 -strand => $loc->strand,
487 -location_type => $loc->location_type
488 );
489 }
490  
491  
492 11 ▶sub cds {
Subroutine cds: called CC=8 SCAR=22.6
Pod documented
493 11 my ($self,$value) = @_;
494 11 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 6 5 11
495 6 ▶ if ($value =~ /^[+-]?\d+$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value =~ /^[+-]?\d+$/) { } 3 3 6
elsif (ref $value and $value->isa('Bio::RangeI')) { } 3 0 3
496 3 my $loc = Bio::Location::Simple->new(-start=>$value, -end => $value,
497 -verbose=>$self->verbose);
498 3 $self->{'_cds'} = $loc;
499 }
500 ▶ elsif (ref $value && $value->isa('Bio::RangeI') ) {
Condition33%1/3
ref $value and $value->isa("Bio::RangeI")
!ll&&!rl&&r
003
MC/DC0%0/2
ref $value and $value->isa("Bio::RangeI")
ref $value $value->isa("Bio::RangeI")
Truth table33%1/3
A and B
A= ref $valueB= $value->isa("Bio::RangeI")
ABresult
0X0
100
111
501 3 $self->{'_cds'} = $value;
502 } else {
503 0 $self->throw("I need an integer or Bio::RangeI, not [$value]")
504 }
505 # strand !!
506 6 my $len;
507  
508 $len = $self->{'_cds'}->end - $self->{'_cds'}->start +1
509 6 ▶ if defined $self->{'_cds'}->end;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_cds"}->end 6 0 6
510  
511 my $a = $self->_create_pair
512 ('chr', 'gene', 0,
513 $self->{'_cds'}->start-1,
514 $len,
515 6 $self->{'_cds'}->strand);
516 6 my $mapper = $COORDINATE_SYSTEMS{'chr'}. "-". $COORDINATE_SYSTEMS{'gene'};
517 6 $self->{'_mappers'}->{$mapper} = $a;
518  
519 # recalculate exon-based mappers
520 6 ▶ if ( defined $self->{'_chr_exons'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_chr_exons"}) 0 6 6
521 0 $self->exons(@{$self->{'_chr_exons'}});
522 }
523  
524 }
525 11 ▶ return $self->{'_cds'} || 0;
Condition50%1/2
$self->{'_cds'} || 0
l!l
110
MC/DC0%0/1
$self->{'_cds'} || 0
$self->{'_cds'}
Truth table50%1/2
A
A= $self->{'_cds'}
Aresult
11
00
526 }
527  
528  
529 35 ▶sub map {
Subroutine map: called CC=44 SCAR=44.9
Pod documented
530 35 my ($self,$value) = @_;
531 35 my ($res);
532 35 ▶ $self->throw("Need to pass me a Bio::Location::Simple or ".
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value and $value->isa("Bio::Location::Simple") || $value->isa("Bio::Location::SplitLocationI") || $value->isa("Bio::SeqFeatureI") 0 35 35
Condition44%4/9
ref $value and $value->isa("Bio::Location::Simple") || $value->isa("Bio::Location::SplitLocationI") || $value->isa("Bio::SeqFeatureI")
!ll&&!rl&&r
0035
$value->isa("Bio::Location::Simple") or $value->isa("Bio::Location::SplitLocationI") or $value->isa("Bio::SeqFeatureI")
l!l&&r!l&&!r
3500
$value->isa("Bio::Location::Simple") or $value->isa("Bio::Location::SplitLocationI")
l!l&&r!l&&!r
3410
MC/DC0%0/4
ref $value and $value->isa("Bio::Location::Simple") || $value->isa("Bio::Location::SplitLocationI") || $value->isa("Bio::SeqFeatureI")
ref $value $value->isa("Bio::Location::Simple") $value->isa("Bio::Location::SplitLocationI") $value->isa("Bio::SeqFeatureI")
Truth table40%2/5
A and B or C or D
A= ref $valueB= $value->isa("Bio::Location::Simple")C= $value->isa("Bio::Location::SplitLocationI")D= $value->isa("Bio::SeqFeatureI")
ABCDresult
0XXX0
10000
11XX1
101X1
10011
533 "Bio::Location::Simple or Bio::SeqFeatureI, not [".
534 ref($value). "]")
535 unless ref($value) && ($value->isa('Bio::Location::Simple') or
536 $value->isa('Bio::Location::SplitLocationI') or
537 $value->isa('Bio::SeqFeatureI'));
538 $self->throw("Input coordinate system not set")
539 35 ▶ unless $self->{'_in'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_in"} 0 35 35
540 $self->throw("Output coordinate system not set")
541 35 ▶ unless $self->{'_out'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_out"} 0 35 35
542 $self->throw("Do not be silly. Input and output coordinate ".
543 "systems are the same!")
544 35 ▶ unless $self->{'_in'} != $self->{'_out'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_in"} != $self->{"_out"} 0 35 35
545  
546 35 $self->_check_direction();
547  
548 35 ▶ $value = $value->location if $value->isa('Bio::SeqFeatureI');
Branch: 1 branch
BranchTrueFalseTotal
if $value->isa("Bio::SeqFeatureI") 0 35 35
549 35 ▶ $self->debug( "=== Start location: ". $value->start. ",".
Condition100%2/2
$value->strand || ''
l!l
341
MC/DC100%1/1
$value->strand || ''
$value->strand
Truth table100%2/2
A
A= $value->strand
Aresult
11
00
550 $value->end. " (". ($value->strand || ''). ")\n");
551  
552 # if nozero coordinate system is used in the input values
553 35 ▶ if ( defined $self->{'_nozero'} &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_nozero"} and $self->{"_nozero"} == 1 || $self->{"_nozero"} == 3) 1 34 35
Condition83%5/6
defined $self->{"_nozero"} and $self->{"_nozero"} == 1 || $self->{"_nozero"} == 3
!ll&&!rl&&r
3131
$self->{"_nozero"} == 1 or $self->{"_nozero"} == 3
l!l&&r!l&&!r
013
MC/DC66%2/3
defined $self->{"_nozero"} and $self->{"_nozero"} == 1 || $self->{"_nozero"} == 3
defined $self->{"_nozero"} $self->{"_nozero"} == 1 $self->{"_nozero"} == 3
Truth table75%3/4
A and B or C
A= defined $self->{"_nozero"}B= $self->{"_nozero"} == 1C= $self->{"_nozero"} == 3
ABCresult
0XX0
1000
11X1
1011
554 ( $self->{'_nozero'} == 1 || $self->{'_nozero'} == 3 ) ) {
555 1 ▶ $value->start($value->start + 1)
Branch: 1 branch
BranchTrueFalseTotal
if defined $value->start and $value->start < 1 0 1 1
Condition33%1/3
defined $value->start and $value->start < 1
!ll&&!rl&&r
010
MC/DC0%0/2
defined $value->start and $value->start < 1
defined $value->start $value->start < 1
Truth table33%1/3
A and B
A= defined $value->startB= $value->start < 1
ABresult
0X0
100
111
556 if defined $value->start && $value->start < 1;
557 1 ▶ $value->end($value->end + 1)
Branch: 1 branch
BranchTrueFalseTotal
if defined $value->end and $value->end < 1 0 1 1
Condition33%1/3
defined $value->end and $value->end < 1
!ll&&!rl&&r
010
MC/DC0%0/2
defined $value->end and $value->end < 1
defined $value->end $value->end < 1
Truth table33%1/3
A and B
A= defined $value->endB= $value->end < 1
ABresult
0X0
100
111
558 if defined $value->end && $value->end < 1;
559 }
560  
561 35 my @steps = $self->_get_path();
562 35 $self->debug( "mapping ". $self->{'_in'}. "->". $self->{'_out'}.
563 " Mappers: ". join(", ", @steps). "\n");
564  
565 35 foreach my $mapper (@steps) {
566 45 ▶ if ($mapper eq $TRANSLATION) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mapper eq $Bio::Coordinate::GeneMapper::TRANSLATION) { } 2 43 45
elsif (not defined $self->{'_mappers'}{$mapper}) { } 0 43 43
567 2 ▶ if ($self->direction == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->direction == 1) { } 2 0 2
568  
569 2 $value = $self->_translate($value);
570 2 $self->debug( "+ $TRANSLATION cds -> propeptide (translate) \n");
571 } else {
572 0 $value = $self->_reverse_translate($value);
573 0 $self->debug("+ $TRANSLATION propeptide -> cds (reverse translate) \n");
574 }
575 }
576 # keep the start and end values, and go on to next iteration
577 # if this mapper is not set
578 elsif ( ! defined $self->{'_mappers'}->{$mapper} ) {
579 # update mapper name
580 0 $mapper =~ /\d+-(\d+)/; my ($counter) = $1;
581 0 $value->seq_id($COORDINATE_INTS{$counter});
582 0 $self->debug( "- $mapper\n");
583 } else {
584 #
585 # the DEFAULT : generic mapping
586 #
587  
588 43 $value = $self->{'_mappers'}->{$mapper}->map($value);
589  
590 43 ▶ $value->purge_gaps
Branch: 1 branch
BranchTrueFalseTotal
if $value and $value->isa("Bio::Location::SplitLocationI") and $value->can("gap") 16 27 43
Condition66%4/6
$value and $value->isa("Bio::Location::SplitLocationI") and $value->can("gap")
!ll&&!rl&&r
27016
$value and $value->isa("Bio::Location::SplitLocationI")
!ll&&!rl&&r
02716
MC/DC33%1/3
$value and $value->isa("Bio::Location::SplitLocationI") and $value->can("gap")
$value $value->isa("Bio::Location::SplitLocationI") $value->can("gap")
Truth table50%2/4
A and B and C
A= $valueB= $value->isa("Bio::Location::SplitLocationI")C= $value->can("gap")
ABCresult
0XX0
10X0
1100
1111
591 if ($value && $value->isa('Bio::Location::SplitLocationI') &&
592 $value->can('gap'));
593  
594 43 ▶ $self->debug( "+ $mapper (". $self->direction. "): start ".
Branch: 1 branch
BranchTrueFalseTotal
if $value and $self->verbose > 0 0 43 43
Condition33%1/3
$value and $self->verbose > 0
!ll&&!rl&&r
0430
MC/DC0%0/2
$value and $self->verbose > 0
$value $self->verbose > 0
Truth table33%1/3
A and B
A= $valueB= $self->verbose > 0
ABresult
0X0
100
111
595 $value->start. " end ". $value->end. "\n")
596 if $value && $self->verbose > 0;
597 }
598 }
599  
600 # if nozero coordinate system is asked to be used in the output values
601 35 ▶ if ( defined $value && defined $self->{'_nozero'} &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and defined $self->{"_nozero"} and $self->{"_nozero"} == 2 || $self->{"_nozero"} == 3) 1 34 35
Condition77%7/9
defined $value and defined $self->{"_nozero"} and $self->{"_nozero"} == 2 || $self->{"_nozero"} == 3
!ll&&!rl&&r
3131
defined $value and defined $self->{"_nozero"}
!ll&&!rl&&r
0314
$self->{"_nozero"} == 2 or $self->{"_nozero"} == 3
l!l&&r!l&&!r
013
MC/DC50%2/4
defined $value and defined $self->{"_nozero"} and $self->{"_nozero"} == 2 || $self->{"_nozero"} == 3
defined $value defined $self->{"_nozero"} $self->{"_nozero"} == 2 $self->{"_nozero"} == 3
Truth table60%3/5
A and B and C or D
A= defined $valueB= defined $self->{"_nozero"}C= $self->{"_nozero"} == 2D= $self->{"_nozero"} == 3
ABCDresult
0XXX0
10XX0
11000
111X1
11011
602 ( $self->{'_nozero'} == 2 || $self->{'_nozero'} == 3 ) ) {
603  
604 1 ▶ $value->start($value->start - 1)
Branch: 1 branch
BranchTrueFalseTotal
if defined $value->start and $value->start < 1 1 0 1
Condition33%1/3
defined $value->start and $value->start < 1
!ll&&!rl&&r
001
MC/DC0%0/2
defined $value->start and $value->start < 1
defined $value->start $value->start < 1
Truth table33%1/3
A and B
A= defined $value->startB= $value->start < 1
ABresult
0X0
100
111
605 if defined $value->start && $value->start < 1;
606 1 ▶ $value->end($value->end - 1)
Branch: 1 branch
BranchTrueFalseTotal
if defined $value->end and $value->end < 1 1 0 1
Condition33%1/3
defined $value->end and $value->end < 1
!ll&&!rl&&r
001
MC/DC0%0/2
defined $value->end and $value->end < 1
defined $value->end $value->end < 1
Truth table33%1/3
A and B
A= defined $value->endB= $value->end < 1
ABresult
0X0
100
111
607 if defined $value->end && $value->end < 1;
608 }
609  
610 # handle merging of adjacent split locations!
611  
612 35 ▶ if (ref $value eq "Bio::Coordinate::Result" && $value->each_match > 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'Bio::Coordinate::Result' and $value->each_match > 1) { } 7 28 35
elsif (ref $value eq 'Bio::Coordinate::Result' and $value->each_match == 1) { } 5 46 51
Condition100%3/3
ref $value eq "Bio::Coordinate::Result" and $value->each_match > 1
!ll&&!rl&&r
2357
MC/DC100%2/2
ref $value eq "Bio::Coordinate::Result" and $value->each_match > 1
ref $value eq "Bio::Coordinate::Result" $value->each_match > 1
Truth table100%3/3
A and B
A= ref $value eq "Bio::Coordinate::Result"B= $value->each_match > 1
ABresult
0X0
100
111
613 7 my $prevloc;
614 7 my $merging = 0;
615 7 my $newvalue;
616 my @matches;
617 7 foreach my $loc ( $value->each_Location(1) ) {
618 16 ▶ unless ($prevloc) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prevloc) 7 9 16
619 7 $prevloc = $loc;
620 7 push @matches, $prevloc;
621 7 next;
622 }
623 9 ▶ if ($prevloc->end == ($loc->start - 1) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($prevloc->end == $loc->start - 1 and $prevloc->seq_id eq $loc->seq_id) { } 5 4 9
Condition66%2/3
$prevloc->end == $loc->start - 1 and $prevloc->seq_id eq $loc->seq_id
!ll&&!rl&&r
405
MC/DC50%1/2
$prevloc->end == $loc->start - 1 and $prevloc->seq_id eq $loc->seq_id
$prevloc->end == $loc->start - 1 $prevloc->seq_id eq $loc->seq_id
Truth table66%2/3
A and B
A= $prevloc->end == $loc->start - 1B= $prevloc->seq_id eq $loc->seq_id
ABresult
0X0
100
111
624 $prevloc->seq_id eq $loc->seq_id) {
625 5 $prevloc->end($loc->end);
626 5 $merging = 1;
627 } else {
628 4 push @matches, $loc;
629 4 $prevloc = $loc;
630 }
631 }
632 7 ▶ if ($merging) {
Branch: 1 branch
BranchTrueFalseTotal
if ($merging) 4 3 7
633 4 ▶ if (@matches > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@matches > 1) { } 0 4 4
634 0 $newvalue = Bio::Coordinate::Result->new;
635 0 map {$newvalue->add_sub_Location} @matches;
636 } else {
637 4 $newvalue = Bio::Coordinate::Result::Match->new
638 (-seq_id => $matches[0]->seq_id,
639 -start => $matches[0]->start,
640 -end => $matches[0]->end,
641 -strand => $matches[0]->strand,
642 -verbose => $self->verbose,);
643 }
644 4 $value = $newvalue;
645 }
646 }
647 ▶ elsif (ref $value eq "Bio::Coordinate::Result" &&
Condition66%2/3
ref $value eq "Bio::Coordinate::Result" and $value->each_match == 1
!ll&&!rl&&r
2305
MC/DC50%1/2
ref $value eq "Bio::Coordinate::Result" and $value->each_match == 1
ref $value eq "Bio::Coordinate::Result" $value->each_match == 1
Truth table66%2/3
A and B
A= ref $value eq "Bio::Coordinate::Result"B= $value->each_match == 1
ABresult
0X0
100
111
648 $value->each_match == 1 ){
649 5 $value = $value->match;
650 }
651  
652 35 return $value;
653 }
654  
655  
656 2 ▶sub direction {
Subroutine direction: called CC=1 SCAR=0.0
Pod documented
657 2 my ($self) = @_;
658 2 return $self->{'_direction'};
659 }
660  
661  
662 1 ▶sub swap {
Subroutine swap: called CC=1 SCAR=0.0
Pod documented
663 1 my ($self,$value) = @_;
664  
665 1 ($self->{'_in'}, $self->{'_out'}) = ($self->{'_out'}, $self->{'_in'});
666 1 map { $self->{'_mappers'}->{$_}->swap } keys %{$self->{'_mappers'}};
667  
668 # record the changed direction;
669 1 $self->{_direction} *= -1;
670  
671 1 return 1;
672 }
673  
674  
675 0 ▶sub to_string {
Subroutine to_string: not called CC=10 SCAR=47.0
Pod documented
676 0 my ($self) = shift;
677  
678 0 print "-" x 40, "\n";
679  
680 # chr-gene
681 0 my $mapper_str = 'chr-gene';
682 0 my $mapper = $self->_mapper_string2code($mapper_str);
683  
684 0 printf "\n %-12s (%s)\n", $mapper_str, $mapper ;
685 0 ▶ if (defined $self->cds) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->cds) 0 0 0
686 0 ▶ my $end = $self->cds->end -1 if defined $self->cds->end;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->cds->end 0 0 0
687 0 ▶ printf "%16s%s: %s (%s)\n", ' ', 'gene offset', $self->cds->start-1 , $end || '';
Condition0%0/2
$end || ''
l!l
00
MC/DC0%0/1
$end || ''
$end
Truth table0%0/2
A
A= $end
Aresult
11
00
688 0 ▶ printf "%16s%s: %s\n", ' ', 'gene strand', $self->cds->strand || 0;
Condition0%0/2
$self->cds->strand || 0
l!l
00
MC/DC0%0/1
$self->cds->strand || 0
$self->cds->strand
Truth table0%0/2
A
A= $self->cds->strand
Aresult
11
00
689 }
690  
691 # gene-intron
692 0 $mapper_str = 'gene-intron';
693 0 $mapper = $self->_mapper_string2code($mapper_str);
694 0 printf "\n %-12s (%s)\n", $mapper_str, $mapper ;
695  
696 0 my $i = 1;
697 0 foreach my $pair ( $self->{'_mappers'}->{$mapper}->each_mapper ) {
698 0 printf "%8s :%8s -> %-12s\n", $i, $pair->in->start, $pair->out->start ;
699 0 printf "%8s :%8s -> %-12s\n", '', $pair->in->end, $pair->out->end ;
700 0 $i++;
701 }
702  
703 # intron-negative_intron
704 0 $mapper_str = 'intron-negative_intron';
705 0 $mapper = $self->_mapper_string2code($mapper_str);
706 0 printf "\n %-12s (%s)\n", $mapper_str, $mapper ;
707  
708 0 $i = 1;
709 0 foreach my $pair ( $self->{'_mappers'}->{$mapper}->each_mapper ) {
710 0 printf "%8s :%8s -> %-12s\n", $i, $pair->in->start, $pair->out->start ;
711 0 printf "%8s :%8s -> %-12s\n", '', $pair->in->end, $pair->out->end ;
712 0 $i++;
713 }
714  
715 # gene-exon
716 0 $mapper_str = 'gene-exon';
717 0 $mapper = $self->_mapper_string2code($mapper_str);
718 0 printf "\n %-12s (%s)\n", $mapper_str, $mapper ;
719  
720 0 $i = 1;
721 0 foreach my $pair ( $self->{'_mappers'}->{$mapper}->each_mapper ) {
722 0 printf "%8s :%8s -> %-12s\n", $i, $pair->in->start, $pair->out->start ;
723 0 printf "%8s :%8s -> %-12s\n", '', $pair->in->end, $pair->out->end ;
724 0 $i++;
725 }
726  
727 # gene-cds
728 0 $mapper_str = 'gene-cds';
729 0 $mapper = $self->_mapper_string2code($mapper_str);
730 0 printf "\n %-12s (%s)\n", $mapper_str, $mapper ;
731  
732 0 $i = 1;
733 0 foreach my $pair ( $self->{'_mappers'}->{$mapper}->each_mapper ) {
734 0 printf "%8s :%8s -> %-12s\n", $i, $pair->in->start, $pair->out->start ;
735 0 printf "%8s :%8s -> %-12s\n", '', $pair->in->end, $pair->out->end ;
736 0 $i++;
737 }
738  
739 # cds-propeptide
740 0 $mapper_str = 'cds-propeptide';
741 0 $mapper = $self->_mapper_string2code($mapper_str);
742 0 printf "\n %-12s (%s)\n", $mapper_str, $mapper ;
743 0 printf "%9s%-12s\n", "", '"translate"';
744  
745 # propeptide-peptide
746 0 $mapper_str = 'propeptide-peptide';
747 0 $mapper = $self->_mapper_string2code($mapper_str);
748 0 printf "\n %-12s (%s)\n", $mapper_str, $mapper ;
749 0 printf "%16s%s: %s\n", ' ', "peptide offset", $self->peptide_offset;
750  
751 0 print "\nin : ", $self->in, "\n";
752 0 print "out: ", $self->out, "\n";
753 0 my $dir;
754 0 ▶ $self->direction ? ($dir='forward') : ($dir='reverse');
Branch: 1 branch
BranchTrueFalseTotal
$self->direction ? : 0 0 0
755 0 printf "direction: %-8s(%s)\n", $dir, $self->direction;
756 0 print "\n", "-" x 40, "\n";
757  
758 0 1;
759 }
760  
761  
762 1 ▶sub _mapper_code2string {
Subroutine _mapper_code2string: called CC=1 SCAR=0.0
763 1 my ($self, $code) = @_;
764 1 my ($a, $b) = $code =~ /(\d+)-(\d+)/;
765 1 return $COORDINATE_INTS{$a}. '-'. $COORDINATE_INTS{$b};
766  
767 }
768  
769  
770 1 ▶sub _mapper_string2code {
Subroutine _mapper_string2code: called CC=1 SCAR=0.0
771 1 my ($self, $string) =@_;
772 1 my ($a, $b) = $string =~ /([^-]+)-(.*)/;
773 1 return $COORDINATE_SYSTEMS{$a}. '-'. $COORDINATE_SYSTEMS{$b};
774 }
775  
776  
777 8 ▶sub _create_pair {
Subroutine _create_pair: called CC=4 SCAR=13.9
778 8 my ($self, $in, $out, $strict, $offset, $length, $strand ) = @_;
779 8 ▶ $strict ||= 0;
Condition50%1/2
$strict ||= 0
l!l
08
MC/DC0%0/1
$strict ||= 0
$strict
Truth table50%1/2
A
A= $strict
Aresult
11
00
780 8 ▶ $strand ||= 1;
Condition100%2/2
$strand ||= 1
l!l
35
MC/DC100%1/1
$strand ||= 1
$strand
Truth table100%2/2
A
A= $strand
Aresult
11
00
781 8 ▶ $length ||= 20;
Condition100%2/2
$length ||= 20
l!l
62
MC/DC100%1/1
$length ||= 20
$length
Truth table100%2/2
A
A= $length
Aresult
11
00
782  
783 8 my $match1 = Bio::Location::Simple->new
784 (-seq_id => $in,
785 -start => $offset+1,
786 -end => $offset+$length,
787 -strand => 1,
788 -verbose => $self->verbose);
789  
790 8 my $match2 = Bio::Location::Simple->new
791 (-seq_id => $out,
792 -start => 1,
793 -end => $length,
794 -strand => $strand,
795 -verbose => $self->verbose);
796  
797 8 my $pair = Bio::Coordinate::ExtrapolatingPair->new
798 (-in => $match1,
799 -out => $match2,
800 -strict => $strict,
801 -verbose => $self->verbose,
802 );
803  
804 8 return $pair;
805 }
806  
807  
808 3 ▶sub _translate {
Subroutine _translate: called CC=6 SCAR=24.8
809 3 my ($self,$value) = @_;
810  
811 3 ▶ $self->throw("Need to pass me a Bio::Location::Simple or ".
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and $value->isa("Bio::Location::Simple") || $value->isa("Bio::Location::SplitLocationI") 0 3 3
Condition33%2/6
defined $value and $value->isa("Bio::Location::Simple") || $value->isa("Bio::Location::SplitLocationI")
!ll&&!rl&&r
003
$value->isa("Bio::Location::Simple") or $value->isa("Bio::Location::SplitLocationI")
l!l&&r!l&&!r
300
MC/DC0%0/3
defined $value and $value->isa("Bio::Location::Simple") || $value->isa("Bio::Location::SplitLocationI")
defined $value $value->isa("Bio::Location::Simple") $value->isa("Bio::Location::SplitLocationI")
Truth table25%1/4
A and B or C
A= defined $valueB= $value->isa("Bio::Location::Simple")C= $value->isa("Bio::Location::SplitLocationI")
ABCresult
0XX0
1000
11X1
1011
812 "Bio::Location::SplitLocationI, not [". ref($value). "]")
813 unless defined $value &&
814 ($value->isa('Bio::Location::Simple') || $value->isa('Bio::Location::SplitLocationI'));
815  
816 3 my $seqid = 'propeptide';
817  
818 3 ▶ if ($value->isa("Bio::Location::SplitLocationI") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->isa('Bio::Location::SplitLocationI')) { } 0 3 3
819 0 my $split = Bio::Location::Split->new(-seq_id=>$seqid);
820 0 foreach my $loc ( $value->each_Location(1) ) {
821 0 my $match = Bio::Location::Simple->new
822 (-start => int ($loc->start / 3 ) +1,
823 -end => int ($loc->end / 3 ) +1,
824 -seq_id => $seqid,
825 -strand => 1,
826 -verbose => $self->verbose,
827 );
828 0 $split->add_sub_Location($match);
829 }
830 0 return $split;
831  
832 } else {
833 3 return new Bio::Location::Simple(-start => int($value->start / 3 )+1,
834 -end => int($value->end / 3 )+1,
835 -seq_id => $seqid,
836 -strand => 1,
837 -verbose=> $self->verbose,
838 );
839 }
840 }
841  
842  
843 1 ▶sub _frame {
Subroutine _frame: called CC=6 SCAR=24.8
844 1 my ($self,$value) = @_;
845  
846 1 ▶ $self->throw("Need to pass me a Bio::Location::Simple or ".
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and $value->isa("Bio::Location::Simple") || $value->isa("Bio::Location::SplitLocationI") 0 1 1
Condition33%2/6
defined $value and $value->isa("Bio::Location::Simple") || $value->isa("Bio::Location::SplitLocationI")
!ll&&!rl&&r
001
$value->isa("Bio::Location::Simple") or $value->isa("Bio::Location::SplitLocationI")
l!l&&r!l&&!r
100
MC/DC0%0/3
defined $value and $value->isa("Bio::Location::Simple") || $value->isa("Bio::Location::SplitLocationI")
defined $value $value->isa("Bio::Location::Simple") $value->isa("Bio::Location::SplitLocationI")
Truth table25%1/4
A and B or C
A= defined $valueB= $value->isa("Bio::Location::Simple")C= $value->isa("Bio::Location::SplitLocationI")
ABCresult
0XX0
1000
11X1
1011
847 "Bio::Location::SplitLocationI, not [". ref($value). "]")
848 unless defined $value &&
849 ($value->isa('Bio::Location::Simple') || $value->isa('Bio::Location::SplitLocationI'));
850  
851 1 my $seqid = 'propeptide';
852  
853 1 ▶ if ($value->isa("Bio::Location::SplitLocationI")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->isa('Bio::Location::SplitLocationI')) { } 0 1 1
854 0 my $split = Bio::Location::Split->new(-seq_id=>$seqid);
855 0 foreach my $loc ( $value->each_Location(1) ) {
856  
857 0 my $match = Bio::Location::Simple->new
858 (-start => ($value->start-1) % 3 +1,
859 -end => ($value->end-1) % 3 +1,
860 -seq_id => 'frame',
861 -strand => 1,
862 -verbose=> $self->verbose);
863 0 $split->add_sub_Location($match);
864 }
865 0 return $split;
866 } else {
867 1 return new Bio::Location::Simple(-start => ($value->start-1) % 3 +1,
868 -end => ($value->end-1) % 3 +1,
869 -seq_id => 'frame',
870 -strand => 1,
871 -verbose => $self->verbose,
872 );
873 }
874 }
875  
876  
877 1 ▶sub _reverse_translate {
Subroutine _reverse_translate: called CC=6 SCAR=24.8
878 1 my ($self,$value) = @_;
879  
880 1 ▶ $self->throw("Need to pass me a Bio::Location::Simple or ".
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and $value->isa("Bio::Location::Simple") || $value->isa("Bio::Location::SplitLocationI") 0 1 1
Condition33%2/6
defined $value and $value->isa("Bio::Location::Simple") || $value->isa("Bio::Location::SplitLocationI")
!ll&&!rl&&r
001
$value->isa("Bio::Location::Simple") or $value->isa("Bio::Location::SplitLocationI")
l!l&&r!l&&!r
100
MC/DC0%0/3
defined $value and $value->isa("Bio::Location::Simple") || $value->isa("Bio::Location::SplitLocationI")
defined $value $value->isa("Bio::Location::Simple") $value->isa("Bio::Location::SplitLocationI")
Truth table25%1/4
A and B or C
A= defined $valueB= $value->isa("Bio::Location::Simple")C= $value->isa("Bio::Location::SplitLocationI")
ABCresult
0XX0
1000
11X1
1011
881 "Bio::Location::SplitLocationI, not [". ref($value). "]")
882 unless defined $value &&
883 ($value->isa('Bio::Location::Simple') || $value->isa('Bio::Location::SplitLocationI'));
884  
885 1 my $seqid = 'cds';
886  
887 1 ▶ if ($value->isa("Bio::Location::SplitLocationI")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->isa('Bio::Location::SplitLocationI')) { } 0 1 1
888 0 my $split = Bio::Location::Split->new(-seq_id=>$seqid);
889 0 foreach my $loc ( $value->each_Location(1) ) {
890  
891 0 my $match = Bio::Location::Simple->new
892 (-start => $value->start * 3 - 2,
893 -end => $value->end * 3,
894 -seq_id => $seqid,
895 -strand => 1,
896 -verbose => $self->verbose,
897 );
898 0 $split->add_sub_Location($match);
899 }
900 0 return $split;
901  
902 } else {
903 1 return new Bio::Location::Simple(-start => $value->start * 3 - 2,
904 -end => $value->end * 3,
905 -seq_id => $seqid,
906 -strand => 1,
907 -verbose => $self->verbose,
908 );
909 }
910 }
911  
912  
913 35 ▶sub _check_direction {
Subroutine _check_direction: called CC=3 SCAR=11.0
914 35 my ($self) = @_;
915  
916 35 my $new_direction = 1;
917 35 ▶ $new_direction = -1 if $self->{'_in'} > $self->{'_out'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_in"} > $self->{"_out"} 3 32 35
918  
919 35 ▶ unless ($new_direction == $self->{_direction} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($new_direction == $self->{"_direction"}) 4 31 35
920 4 map { $self->{'_mappers'}->{$_}->swap } keys %{$self->{'_mappers'}};
921 # record the changed direction;
922 4 $self->{_direction} *= -1;
923 }
924 35 1;
925 }
926  
927  
928 35 ▶sub _get_path {
Subroutine _get_path: called CC=7 SCAR=19.5
929 35 my ($self) = @_;
930  
931 35 ▶ my $start = $self->{'_in'} || 0;
Condition50%1/2
$self->{'_in'} || 0
l!l
350
MC/DC0%0/1
$self->{'_in'} || 0
$self->{'_in'}
Truth table50%1/2
A
A= $self->{'_in'}
Aresult
11
00
932 35 ▶ my $end = $self->{'_out'} || 0;
Condition50%1/2
$self->{'_out'} || 0
l!l
350
MC/DC0%0/1
$self->{'_out'} || 0
$self->{'_out'}
Truth table50%1/2
A
A= $self->{'_out'}
Aresult
11
00
933  
934 # note the order
935 # always go from smaller to bigger: it makes caching more efficient
936 35 my $reverse;
937 35 ▶ if ($start > $end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start > $end) 3 32 35
938 3 ($start, $end) = ($end, $start );
939 3 $reverse++;
940 }
941  
942 35 my @mappers;
943 35 ▶ if (exists $self->{'_previous_path'} and
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'_previous_path'} and $self->{'_previous_path'} eq "$start$end") { } 18 17 35
Condition100%3/3
exists $self->{"_previous_path"} and $self->{"_previous_path"} eq "$start$end"
!ll&&!rl&&r
61118
MC/DC100%2/2
exists $self->{"_previous_path"} and $self->{"_previous_path"} eq "$start$end"
exists $self->{"_previous_path"} $self->{"_previous_path"} eq "$start$end"
Truth table100%3/3
A and B
A= exists $self->{"_previous_path"}B= $self->{"_previous_path"} eq "$start$end"
ABresult
0X0
100
111
944 $self->{'_previous_path'} eq "$start$end" ) {
945 # use cache
946 18 @mappers = @{$self->{'_mapper_path'}};
947 } else {
948 17 my $mapper;
949 17 my $prev_node = '';
950 @mappers =
951 41 map { $mapper = "$prev_node-$_"; $prev_node = $_; $mapper; }
952 17 $self->{'_graph'}->shortest_path($start, $end);
953 17 shift @mappers;
954  
955 17 $self->{'_previous_path'} = "$start$end";
956 17 $self->{'_mapper_path'} = \@mappers;
957 }
958  
959 35 ▶ $reverse ? return reverse @mappers : return @mappers;
Branch: 1 branch
BranchTrueFalseTotal
$reverse ? : 3 32 35
960 }
961  
962 2 1;
963  
964 __END__
↑ Summary Coordinate/Utils.pm »