lib/Bio/ToolBox/Data/Feature.pm

filter: Statementstmt 42.5% 344 / 809 Branchbran 31.2% 152 / 486 Conditioncond 15.7% 66 / 419 MC/DCmcdc 1.7% 4 / 226 Subroutinesub 66.0% 35 / 53 Podpod 100% 37 / 37 totaltotal 31.4% 638 / 2030 CC 413 SCAR 54.0
CC
413
Cov
33%
gff_string
1190.0
bed_string
702.0
fetch_alignments
506.0
CRAP 222.4
« lib/Bio/ToolBox/db_helper/alignment_callbacks.pm ↑ Summary script/get_relative_data.pl »
1 package Bio::ToolBox::Data::Feature;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Carp qw(carp cluck croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Module::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Bio::ToolBox::db_helper qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
9 get_db_feature
10 get_segment_score
11 calculate_score
12 get_genomic_sequence
13 low_level_bam_fetch
14 4 );
15 4 ▶use Bio::ToolBox::db_helper::constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 4 our $VERSION = '2.03';
18  
19 4 my $GENETOOL_LOADED = 0;
20  
21 ### Initialization
22  
23 368 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
24  
25 # this should ONLY be called from Bio::ToolBox::Data* iterators
26 368 my $class = shift;
27 368 my %self = @_;
28  
29 # we trust that new is called properly with data and index values
30 368 return bless \%self, $class;
31 }
32  
33 ### Set and retrieve values
34  
35 0 ▶sub data {
Subroutine data: not called CC=1 SCAR=6.9
Pod documented
36 0 return shift->{data};
37 }
38  
39 0 ▶sub column_name {
Subroutine column_name: not called CC=2 SCAR=17.9
Pod documented
40 0 my ( $self, $column ) = @_;
41 0 ▶ return unless defined $column;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $column 0 0 0
42 0 return $self->{data}->name($column);
43 }
44  
45 24 ▶sub feature_type {
Subroutine feature_type: called CC=2 SCAR=7.1
Pod documented
46 24 my $self = shift;
47 24 ▶ carp 'ERROR: feature_type is a read only method' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 24 24
48 24 return $self->{data}->feature_type;
49 }
50  
51 69 ▶sub row_index {
Subroutine row_index: called CC=2 SCAR=7.1
Pod documented
52 69 my $self = shift;
53 69 ▶ carp 'ERROR: row_index is a read only method' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 69 69
54 69 return $self->{'index'};
55 }
56  
57 0 ▶sub line_number {
Subroutine line_number: not called CC=4 SCAR=30.0
Pod documented
58 0 my $self = shift;
59 0 ▶ carp 'ERROR: line_number is a read only method' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
60 0 ▶ if ( exists $self->{data}->{line_count} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'data'}{'line_count'}) { } 0 0 0
elsif (exists $self->{'data'}{'header_line_count'}) { } 0 0 0
61 0 return $self->{data}->{line_count};
62 }
63 elsif ( exists $self->{data}->{header_line_count} ) {
64 0 return $self->{data}->{header_line_count} + $self->row_index;
65 }
66 else {
67 0 return;
68 }
69 }
70  
71 199 ▶sub row_values {
Subroutine row_values: called CC=3 SCAR=11.0
Pod documented
72 199 my $self = shift;
73 199 ▶ carp 'ERROR: row_values is a read only method' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 199 199
74 199 my $row = $self->{'index'};
75 199 my @data = @{ $self->{data}->{data_table}->[$row] }
76 199 [ 1 .. $#{ $self->{data}->{data_table}->[$row] } ];
77 199 ▶ return wantarray ? @data : \@data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 121 78 199
78 }
79  
80 303 ▶sub value {
Subroutine value: called CC=5 SCAR=16.4
Pod documented
81 303 my ( $self, $column, $value ) = @_;
82 303 ▶ return unless ( defined $column and $column =~ /^\d+/ );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $column and $column =~ /^\d+/ 0 303 303
Condition33%1/3
defined $column and $column =~ /^\d+/
!ll&&!rl&&r
00303
MC/DC0%0/2
defined $column and $column =~ /^\d+/
defined $column $column =~ /^\d+/
Truth table33%1/3
A and B
A= defined $columnB= $column =~ /^\d+/
ABresult
0X0
100
111
83 303 my $row = $self->{'index'};
84  
85 # set a value
86 303 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 85 218 303
87 85 $self->{data}->{data_table}->[$row][$column] = $value;
88 }
89  
90 303 my $v = $self->{data}->{data_table}->[$row][$column];
91 303 ▶ return length($v) ? $v : '.'; # internal null value, inherited from GFF definition
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $v ? : 302 1 303
92 }
93  
94 31 ▶sub seq_id {
Subroutine seq_id: called CC=11 SCAR=28.7
Pod documented
95 31 my $self = shift;
96 31 ▶ if ( $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) 1 30 31
97 1 my $i = $self->{data}->chromo_column;
98  
99 # update only if we have an actual column
100 1 ▶ if ($i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i) { } 1 0 1
elsif (exists $self->{'feature'}) { } 0 0 0
101 1 $self->value( $i, $_[0] );
102 1 $self->{seqid} = $_[0];
103 }
104 elsif ( exists $self->{feature} ) {
105 0 carp 'ERROR: Unable to update seq_id for parsed SeqFeature objects';
106 }
107 else {
108 0 carp 'ERROR: No Chromosome column to update!';
109 }
110 }
111  
112 # return cached value
113 31 ▶ return $self->{seqid} if exists $self->{seqid};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"seqid"} 15 16 31
114  
115 # get seq_id value
116 16 my $c;
117 16 my $i = $self->{data}->chromo_column;
118 16 my $j = $self->{data}->coord_column;
119 16 ▶ if ($i) {
Branch: 4 branches
BranchTrueFalseTotal
if ($i) { } 11 5 16
elsif (exists $self->{'feature'}) { } 0 5 5
elsif ($j) { } 5 0 5
elsif ($self->feature_type eq 'named') { } 0 0 0
120 11 $c = $self->value($i);
121 }
122 elsif ( exists $self->{feature} ) {
123 0 $c = $self->{feature}->seq_id;
124 }
125 elsif ($j) {
126 5 $self->_extract_coordinate_string($j);
127 5 return $self->{seqid};
128 }
129 elsif ( $self->feature_type eq 'named' ) {
130 0 my $f = $self->seqfeature;
131 0 ▶ if ($f) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f) 0 0 0
132 0 $c = $f->seq_id;
133 }
134 }
135 11 ▶ $self->{seqid} = $c if defined $c;
Branch: 1 branch
BranchTrueFalseTotal
if defined $c 11 0 11
136 11 return $c;
137 }
138  
139 132 ▶sub start {
Subroutine start: called CC=16 SCAR=33.5
Pod documented
140 132 my $self = shift;
141 132 ▶ if ( $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) 5 127 132
142 5 my $i = $self->{data}->start_column;
143  
144 # update only if we have an actual column
145 5 ▶ my $d = $_[0] =~ /^\d+$/ ? 1 : 0; # looks like an integer
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^\d+$/ ? : 5 0 5
146 5 ▶ if ( $i and $d ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($i and $d) { } 1 4 5
elsif (not $d) { } 0 4 4
elsif (exists $self->{'feature'}) { } 4 0 4
Condition66%2/3
$i and $d
!ll&&!rl&&r
401
MC/DC50%1/2
$i and $d
$i $d
Truth table66%2/3
A and B
A= $iB= $d
ABresult
0X0
100
111
147 1 ▶ if ( $self->{data}->interbase ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'data'}->interbase) { } 1 0 1
148  
149 # compensate for 0-based, assuming we're always working with 1-based
150 1 $self->value( $i, $_[0] - 1 );
151 1 $self->{start} = $_[0];
152 }
153 else {
154 0 $self->value( $i, $_[0] );
155 0 $self->{start} = $_[0];
156 }
157 }
158 elsif ( not $d ) {
159 0 carp 'ERROR: Start coordinate value is not an integer';
160 }
161 elsif ( exists $self->{feature} ) {
162 4 carp 'ERROR: Unable to update Start coordinate for parsed SeqFeature objects';
163 }
164 else {
165 0 carp 'ERROR: No Start coordinate column to update!';
166 }
167 }
168  
169 # return cached value
170 132 ▶ return $self->{start} if exists $self->{start};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"start"} 35 97 132
171  
172 # get start value
173 97 my $s;
174 97 my $i = $self->{data}->start_column;
175 97 my $j = $self->{data}->coord_column;
176 97 ▶ if ($i) {
Branch: 4 branches
BranchTrueFalseTotal
if ($i) { } 92 5 97
elsif (exists $self->{'feature'}) { } 5 0 5
elsif ($j) { } 0 0 0
elsif ($self->feature_type eq 'named') { } 0 0 0
177  
178 # collect from table
179 92 $s = int $self->value($i);
180 92 ▶ if ( $self->{data}->interbase ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"data"}->interbase) 11 81 92
181 11 $s += 1; # compensate for 0-based index
182 }
183 }
184 elsif ( exists $self->{feature} ) {
185 5 $s = $self->{feature}->start;
186 }
187 elsif ($j) {
188 0 $self->_extract_coordinate_string($j);
189 0 return $self->{start};
190 }
191 elsif ( $self->feature_type eq 'named' ) {
192 0 my $f = $self->seqfeature;
193 0 ▶ if ($f) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f) 0 0 0
194 0 $s = $f->start;
195 }
196 }
197 97 ▶ $self->{start} = $s if defined $s;
Branch: 1 branch
BranchTrueFalseTotal
if defined $s 97 0 97
198 97 return $s;
199 }
200  
201 4 *stop = \&end;
202 4 *stop if 0; # avoid once warning
203  
204 48 ▶sub end {
Subroutine end: called CC=14 SCAR=35.4
Pod documented
205 48 my $self = shift;
206 48 ▶ if ( $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) 2 46 48
207 2 my $i = $self->{data}->stop_column;
208  
209 # update only if we have an actual column
210 2 ▶ my $d = $_[0] =~ /^\d+$/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^\d+$/ ? : 2 0 2
211 2 ▶ if ( $i and $d ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($i and $d) { } 2 0 2
elsif (not $d) { } 0 0 0
elsif (exists $self->{'feature'}) { } 0 0 0
Condition33%1/3
$i and $d
!ll&&!rl&&r
002
MC/DC0%0/2
$i and $d
$i $d
Truth table33%1/3
A and B
A= $iB= $d
ABresult
0X0
100
111
212 2 $self->value( $i, $_[0] );
213 2 $self->{end} = $_[0];
214 }
215 elsif ( not $d ) {
216 0 carp 'ERROR: End coordinate value is not an integer';
217 }
218 elsif ( exists $self->{feature} ) {
219 0 carp 'ERROR: Unable to update End coordinate for parsed SeqFeature objects';
220 }
221 else {
222 0 carp 'ERROR: No End coordinate column to update!';
223 }
224 }
225  
226 # return cached value
227 48 ▶ return $self->{end} if exists $self->{end};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"end"} 32 16 48
228  
229 # get end value
230 16 my $e;
231 16 my $i = $self->{data}->stop_column;
232 16 my $j = $self->{data}->coord_column;
233 16 ▶ if ($i) {
Branch: 4 branches
BranchTrueFalseTotal
if ($i) { } 15 1 16
elsif (exists $self->{'feature'}) { } 1 0 1
elsif ($j) { } 0 0 0
elsif ($self->feature_type eq 'named') { } 0 0 0
234 15 $e = int $self->value($i);
235 }
236 elsif ( exists $self->{feature} ) {
237 1 $e = $self->{feature}->end;
238 }
239 elsif ($j) {
240 0 $self->_extract_coordinate_string($j);
241 0 return $self->{end};
242 }
243 elsif ( $self->feature_type eq 'named' ) {
244 0 my $f = $self->seqfeature;
245 0 ▶ if ($f) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f) 0 0 0
246 0 $e = $f->end;
247 }
248 }
249 16 ▶ $self->{end} = $e if defined $e;
Branch: 1 branch
BranchTrueFalseTotal
if defined $e 16 0 16
250 16 return $e;
251 }
252  
253 30 ▶sub strand {
Subroutine strand: called CC=9 SCAR=24.6
Pod documented
254 30 my $self = shift;
255 30 ▶ if ( $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) 1 29 30
256  
257 # update only if we have an actual column
258 1 my $i = $self->{data}->strand_column;
259 1 ▶ if ($i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i) { } 0 1 1
elsif (exists $self->{'feature'}) { } 0 1 1
260 0 $self->value( $i, $_[0] );
261 0 $self->{strand} = $self->_strand( $_[0] );
262 }
263 elsif ( exists $self->{feature} ) {
264 0 carp 'ERROR: Unable to update Strand for parsed SeqFeature objects';
265 }
266 else {
267 1 carp 'ERROR: No Strand column to update!';
268 }
269 }
270  
271 # return cached value
272 30 ▶ return $self->{strand} if exists $self->{strand};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"strand"} 22 8 30
273  
274 # get strand value
275 8 my $s = 0;
276 8 ▶ if ( my $i = $self->{data}->strand_column ) {
Branch: 3 branches
BranchTrueFalseTotal
if (my $i = $self->{'data'}->strand_column) { } 2 6 8
elsif (exists $self->{'feature'}) { } 5 1 6
elsif ($self->feature_type eq 'named') { } 0 1 1
277 2 $s = $self->_strand( $self->value($i) );
278 }
279 elsif ( exists $self->{feature} ) {
280 5 $s = $self->{feature}->strand;
281 }
282 elsif ( $self->feature_type eq 'named' ) {
283 0 my $f = $self->seqfeature;
284 0 ▶ if ($f) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f) 0 0 0
285 0 $s = $f->strand;
286 }
287 }
288 8 $self->{strand} = $s;
289 8 return $s;
290 }
291  
292 2 ▶sub _strand {
Subroutine _strand: called CC=9 SCAR=35.4
293 2 my $self = shift;
294 2 my $str = shift;
295 2 ▶ if ( $str eq '1' or $str eq '-1' or $str eq '0' ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($str eq '1' or $str eq '-1' or $str eq '0') { } 0 2 2
elsif ($str eq '+') { } 0 2 2
elsif ($str eq '-') { } 2 0 2
elsif ($str eq '.') { } 0 0 0
elsif ($str eq '2') { } 0 0 0
elsif ($str eq '*') { } 0 0 0
Condition33%2/6
$str eq 1 or $str eq -1 or $str eq 0
l!l&&r!l&&!r
002
$str eq 1 or $str eq -1
l!l&&r!l&&!r
002
MC/DC0%0/3
$str eq 1 or $str eq -1 or $str eq 0
$str eq 1 $str eq -1 $str eq 0
Truth table25%1/4
A or B or C
A= $str eq 1B= $str eq -1C= $str eq 0
ABCresult
1XX1
01X1
0011
0000
296 0 return $str;
297 }
298 elsif ( $str eq '+' ) {
299 0 return 1;
300 }
301 elsif ( $str eq '-' ) {
302 2 return -1;
303 }
304 elsif ( $str eq '.' ) {
305 0 return 0;
306 }
307 elsif ( $str eq '2' ) {
308  
309 # R packages use 1 for + and 2 for -
310 0 return -1;
311 }
312 elsif ( $str eq '*' ) {
313  
314 # R packages use * for .
315 0 return 0;
316 }
317 else {
318 0 return 0;
319 }
320 }
321  
322 5 ▶sub _extract_coordinate_string {
Subroutine _extract_coordinate_string: called CC=5 SCAR=19.4
323 5 my ( $self, $i ) = @_;
324 5 my $v = $self->value($i);
325 5 $v =~ s/,//g;
326 5 ▶ if ( $v =~ /^ ([\w\.\-]+) : (\d+) (?: (?: \- | \.\. ) (\d+))? (?: : (\-|\+) )? $/x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /^ ([\w\.\-]+) : (\d+) (?: (?: \- | \.\. ) (\d+))? (?: : (\-|\+) )? $/x) 5 0 5
327 5 $self->{seqid} = $1;
328 5 $self->{start} = $2;
329 5 ▶ if (defined $3) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $3) { } 5 0 5
330 5 $self->{end} = $3;
331 }
332 else {
333 0 $self->{end} = $2;
334 }
335 5 ▶ if (defined $4) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $4) 0 5 5
336 0 ▶ if ($4 eq '+') {
Branch: 1 branch
BranchTrueFalseTotal
if ($4 eq '+') { } 0 0 0
337 0 $self->{strand} = 1;
338 }
339 else {
340 0 $self->{strand} = -1;
341 }
342 }
343 }
344 }
345  
346 4 ▶sub peak {
Subroutine peak: called CC=4 SCAR=13.9
Pod documented
347 4 my $self = shift;
348 4 ▶ if ( $self->{data}->format eq 'narrowPeak' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'data'}->format eq 'narrowPeak') { } 3 1 4
349 3 ▶ if ( exists $self->{feature} and $self->{feature}->has_tag('peak') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'feature'} and $self->{'feature'}->has_tag('peak')) { } 2 1 3
Condition66%2/3
exists $self->{"feature"} and $self->{"feature"}->has_tag("peak")
!ll&&!rl&&r
102
MC/DC50%1/2
exists $self->{"feature"} and $self->{"feature"}->has_tag("peak")
exists $self->{"feature"} $self->{"feature"}->has_tag("peak")
Truth table66%2/3
A and B
A= exists $self->{"feature"}B= $self->{"feature"}->has_tag("peak")
ABresult
0X0
100
111
350 return (
351 int( $self->{feature}->get_tag_values('peak') ) +
352 2 $self->{feature}->start );
353 }
354 else {
355 # hard coded start and peak columns
356 1 return ( int $self->value(2) + int $self->value(10) + 1 );
357 }
358 }
359 else {
360 1 return $self->midpoint;
361 }
362 }
363  
364 5 ▶sub midpoint {
Subroutine midpoint: called CC=3 SCAR=12.3
Pod documented
365 5 my $self = shift;
366 5 my $s = $self->start;
367 5 my $e = $self->end;
368 5 ▶ if ( $s and $e ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s and $e) { } 5 0 5
Condition33%1/3
$s and $e
!ll&&!rl&&r
005
MC/DC0%0/2
$s and $e
$s $e
Truth table33%1/3
A and B
A= $sB= $e
ABresult
0X0
100
111
369 5 return int( ( $s + $e ) / 2 );
370 }
371 else {
372 0 return undef;
373 }
374 }
375  
376 4 *name = \&display_name;
377 4 *name if 0; # avoid once warning
378  
379 16 ▶sub display_name {
Subroutine display_name: called CC=11 SCAR=34.6
Pod documented
380 16 my $self = shift;
381 16 ▶ if ( $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) 1 15 16
382  
383 # update only if we have an actual column
384 1 my $i = $self->{data}->name_column;
385 1 ▶ if ($i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i) { } 1 0 1
elsif (exists $self->{'feature'}) { } 0 0 0
386 1 return $self->value( $i, $_[0] );
387 }
388 elsif ( exists $self->{feature} ) {
389 0 carp 'ERROR: Unable to update display_name for parsed SeqFeature objects';
390 }
391 else {
392 0 carp 'ERROR: No Name column to update!';
393 }
394 }
395  
396 # seqfeature
397 15 ▶ if ( exists $self->{feature} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"feature"}) 5 10 15
398 5 return $self->{feature}->display_name;
399 }
400  
401 # collect from table
402 10 my $i = $self->{data}->name_column;
403 10 ▶ if ($i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i) { } 10 0 10
elsif (my $att = $self->gff_attributes) { } 0 0 0
404 10 return $self->value($i);
405 }
406 elsif ( my $att = $self->gff_attributes ) {
407 return
408 $att->{Name}
409 || $att->{ID}
410 || $att->{transcript_name}
411 || $att->{gene_name}
412 0 ▶ || undef;
Condition0%0/11
$att->{'Name'} || $att->{'ID'} || $att->{'transcript_name'} || $att->{'gene_name'} || undef
l!l
00
$att->{"Name"} or $att->{"ID"} or $att->{"transcript_name"} or $att->{"gene_name"}
l!l&&r!l&&!r
000
$att->{"Name"} or $att->{"ID"} or $att->{"transcript_name"}
l!l&&r!l&&!r
000
$att->{"Name"} or $att->{"ID"}
l!l&&r!l&&!r
000
MC/DC0%0/4
$att->{'Name'} || $att->{'ID'} || $att->{'transcript_name'} || $att->{'gene_name'} || undef
$att->{"Name"} $att->{"ID"} $att->{"transcript_name"} $att->{"gene_name"}
Truth table0%0/5
A or B or C or D
A= $att->{"Name"}B= $att->{"ID"}C= $att->{"transcript_name"}D= $att->{"gene_name"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
413 }
414 }
415  
416 8 ▶sub coordinate {
Subroutine coordinate: called CC=7 SCAR=26.9
Pod documented
417 8 my $self = shift;
418 8 ▶ carp 'ERROR: name is a read only method' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 8 8
419 8 my $c = $self->seq_id;
420 8 my $s = $self->start;
421 8 my $e = $self->end;
422 8 ▶ if ( $c and $s and $e ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($c and $s and $e) { } 8 0 8
elsif ($c and $s) { } 0 0 0
Condition33%2/6
$c and $s and $e
!ll&&!rl&&r
008
$c and $s
!ll&&!rl&&r
008
MC/DC0%0/3
$c and $s and $e
$c $s $e
Truth table25%1/4
A and B and C
A= $cB= $sC= $e
ABCresult
0XX0
10X0
1100
1111
423 8 return sprintf "%s:%d-%d", $c, $s, $e;
424 }
425 ▶ elsif ( $c and $s ) {
Condition0%0/3
$c and $s
!ll&&!rl&&r
000
MC/DC0%0/2
$c and $s
$c $s
Truth table0%0/3
A and B
A= $cB= $s
ABresult
0X0
100
111
426 0 return sprintf "%s:%d", $c, $s;
427 }
428 else {
429 0 return undef;
430 }
431 }
432  
433 9 ▶sub type {
Subroutine type: called CC=7 SCAR=21.1
Pod documented
434 9 my $self = shift;
435 9 ▶ if ( $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) 1 8 9
436  
437 # update only if we have an actual column
438 1 my $i = $self->{data}->type_column;
439 1 ▶ if ($i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i) { } 0 1 1
elsif (exists $self->{'feature'}) { } 0 1 1
440 0 return $self->value( $i, $_[0] );
441 }
442 elsif ( exists $self->{feature} ) {
443 0 carp 'ERROR: Unable to update primary_tag for parsed SeqFeature objects';
444 }
445 else {
446 1 carp 'ERROR: No Type column to update!';
447 }
448 }
449  
450 # collect from table
451 9 my $i = $self->{data}->type_column;
452 9 ▶ if ($i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i) 0 9 9
453 0 return $self->value($i);
454 }
455  
456 # seqfeature
457 9 ▶ if ( exists $self->{feature} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"feature"}) 4 5 9
458 4 return $self->{feature}->primary_tag;
459 }
460  
461 # general metadata
462 5 ▶ if ( $self->{data}->feature ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"data"}->feature) 5 0 5
463 5 return $self->{data}->feature;
464 }
465 0 return undef;
466 }
467  
468 4 *id = \&primary_id;
469 4 *id if 0; # avoid once warning
470  
471 66 ▶sub primary_id {
Subroutine primary_id: called CC=9 SCAR=33.9
Pod documented
472 66 my $self = shift;
473 66 ▶ carp 'ERROR: id is a read only method' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 66 66
474 66 my $i = $self->{data}->id_column;
475 66 ▶ if ($i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i) 66 0 66
476 66 my $v = $self->value($i);
477 66 ▶ if ( defined $v and $v ne '.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v and $v ne ".") 66 0 66
Condition33%1/3
defined $v and $v ne "."
!ll&&!rl&&r
0066
MC/DC0%0/2
defined $v and $v ne "."
defined $v $v ne "."
Truth table33%1/3
A and B
A= defined $vB= $v ne "."
ABresult
0X0
100
111
478 66 return $v;
479 }
480 }
481 0 ▶ return $self->{feature}->primary_id if exists $self->{feature};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"feature"} 0 0 0
482 0 ▶ if ( my $att = $self->gff_attributes ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $att = $self->gff_attributes) 0 0 0
483 0 ▶ return $att->{ID} || $att->{Name} || $att->{transcript_id};
Condition0%0/6
$att->{'ID'} || $att->{'Name'} || $att->{'transcript_id'}
l!l&&r!l&&!r
000
$att->{"ID"} or $att->{"Name"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$att->{'ID'} || $att->{'Name'} || $att->{'transcript_id'}
$att->{"ID"} $att->{"Name"} $att->{'transcript_id'}
Truth table0%0/4
A or B || C
A= $att->{"ID"}B= $att->{"Name"}C= $att->{'transcript_id'}
ABCresult
1XX1
01X1
0011
0000
484 }
485 0 return undef;
486 }
487  
488 2 ▶sub length {
Subroutine length: called CC=6 SCAR=22.9
Pod documented
489 2 my $self = shift;
490 2 ▶ carp 'ERROR: length is a read only method' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
491 2 ▶ if ( $self->{data}->vcf ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"data"}->vcf) 0 2 2
492  
493 # special case for vcf files, measure the length of the ALT allele
494 0 return CORE::length( $self->value(5) );
495 }
496 2 my $s = $self->start;
497 2 my $e = $self->end;
498 2 ▶ if ( defined $s and defined $e ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $s and defined $e) { } 2 0 2
elsif (defined $s) { } 0 0 0
Condition33%1/3
defined $s and defined $e
!ll&&!rl&&r
002
MC/DC0%0/2
defined $s and defined $e
defined $s defined $e
Truth table33%1/3
A and B
A= defined $sB= defined $e
ABresult
0X0
100
111
499 2 return $e - $s + 1;
500 }
501 elsif ( defined $s ) {
502 0 return 1;
503 }
504 else {
505 0 return undef;
506 }
507 }
508  
509 5 ▶sub score {
Subroutine score: called CC=2 SCAR=7.1
Pod documented
510 5 my $self = shift;
511 5 my $c = $self->{data}->score_column;
512 5 ▶ return $c ? $self->value($c) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$c ? : 5 0 5
513 }
514  
515 0 ▶sub attributes {
Subroutine attributes: not called CC=3 SCAR=24.8
Pod documented
516 0 my $self = shift;
517 0 ▶ return $self->gff_attributes if ( $self->{data}->gff );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"data"}->gff 0 0 0
518 0 ▶ return $self->vcf_attributes if ( $self->{data}->vcf );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"data"}->vcf 0 0 0
519 0 return;
520 }
521  
522 1 ▶sub gff_attributes {
Subroutine gff_attributes: called CC=6 SCAR=18.7
Pod documented
523 1 my $self = shift;
524 1 ▶ return unless ( $self->{data}->gff );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data"}->gff 0 1 1
525 1 ▶ return $self->{attributes} if ( exists $self->{attributes} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"attributes"} 0 1 1
526 1 $self->{attributes} = {};
527 1 foreach my $g ( split( /\s*;\s*/, $self->value(9) ) ) {
528 3 my ( $tag, $value ) = split /\s+|=/, $g;
529 3 ▶ next unless ( $tag and $value );
Branch: 1 branch
BranchTrueFalseTotal
unless $tag and $value 0 3 3
Condition33%1/3
$tag and $value
!ll&&!rl&&r
003
MC/DC0%0/2
$tag and $value
$tag $value
Truth table33%1/3
A and B
A= $tagB= $value
ABresult
0X0
100
111
530  
531 # unescape URL encoded values, borrowed from Bio::DB::GFF
532 3 $value =~ tr/+/ /;
533 3 $value =~ s/%( [0-9a-fA-F]{2} )/chr hex($1)/xge;
534 3 $self->{attributes}->{$tag} = $value;
535 }
536 1 return $self->{attributes};
537 }
538  
539 0 ▶sub vcf_attributes {
Subroutine vcf_attributes: not called CC=8 SCAR=42.8
Pod documented
540 0 my $self = shift;
541 0 ▶ return unless ( $self->{data}->vcf );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data"}->vcf 0 0 0
542 0 ▶ return $self->{attributes} if ( exists $self->{attributes} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"attributes"} 0 0 0
543 0 $self->{attributes} = {};
544  
545 # INFO attributes
546 0 my %info;
547 0 ▶ if ( $self->{data}->name(8) eq 'INFO' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"data"}->name(8) eq "INFO") 0 0 0
548 0 ▶ %info = map { $_->[0] => defined $_->[1] ? $_->[1] : undef }
Branch: 1 branch
BranchTrueFalseTotal
defined $_->[1] ? : 0 0 0
549  
550 # some tags are simple and have no value, eg SOMATIC
551 0 map { [ split(/=/) ] }
552 split( /;/, $self->value(8) );
553 }
554 0 $self->{attributes}->{INFO} = \%info;
555 0 $self->{attributes}->{8} = \%info;
556  
557 # Sample attributes
558 0 ▶ if ( $self->{data}->number_columns > 9 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"data"}->number_columns > 9) 0 0 0
559 0 my @formatKeys = split /:/, $self->value(9);
560 0 foreach my $i ( 10 .. $self->{data}->last_column ) {
561 0 my $name = $self->{data}->name($i);
562 0 my @sampleVals = split /:/, $self->value($i);
563 my %sample = map {
564 0 ▶ $formatKeys[$_] => defined $sampleVals[$_] ? $sampleVals[$_] : undef
Branch: 1 branch
BranchTrueFalseTotal
defined $sampleVals[$_] ? : 0 0 0
565 } ( 0 .. $#formatKeys );
566 0 $self->{attributes}->{$name} = \%sample;
567 0 $self->{attributes}->{$i} = \%sample;
568 }
569 }
570 0 return $self->{attributes};
571 }
572  
573 0 ▶sub rewrite_attributes {
Subroutine rewrite_attributes: not called CC=3 SCAR=24.8
Pod documented
574 0 my $self = shift;
575 0 ▶ return $self->rewrite_gff_attributes if ( $self->{data}->gff );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"data"}->gff 0 0 0
576 0 ▶ return $self->rewrite_vcf_attributes if ( $self->{data}->vcf );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"data"}->vcf 0 0 0
577 0 return;
578 }
579  
580 1 ▶sub rewrite_gff_attributes {
Subroutine rewrite_gff_attributes: called CC=8 SCAR=21.2
Pod documented
581 1 my $self = shift;
582 1 ▶ return unless ( $self->{data}->gff );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data"}->gff 0 1 1
583 1 ▶ return unless exists $self->{attributes};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"attributes"} 0 1 1
584 1 my @pairs; # of key=value items
585 1 ▶ if ( exists $self->{attributes}{ID} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"attributes"}{"ID"}) 1 0 1
586  
587 # I assume this does not need to be escaped!
588 1 push @pairs, 'ID=' . $self->{attributes}{ID};
589 }
590 1 ▶ if ( exists $self->{attributes}{Name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"attributes"}{"Name"}) 1 0 1
591 1 my $name = $self->{attributes}{Name};
592 0 $name =~ s/( [\t\n\r%&\=;,\ ] ) /sprintf("%%%X",ord($1))/xge;
593 1 push @pairs, "Name=$name";
594 }
595 1 foreach my $key ( sort { $a cmp $b } keys %{ $self->{attributes} } ) {
596 3 ▶ next if $key eq 'ID';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "ID" 1 2 3
597 2 ▶ next if $key eq 'Name';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "Name" 1 1 2
598 1 my $value = $self->{attributes}{$key};
599 0 $key =~ s/( [\t\n\r%&\=;,\ ] ) /sprintf("%%%X",ord($1))/xge;
600 1 $value =~ s/( [\t\n\r%&\=;,\ ] ) /sprintf("%%%X",ord($1))/xge;
601 1 push @pairs, "$key=$value";
602 }
603 1 $self->value( 9, join( '; ', @pairs ) );
604 1 return 1;
605 }
606  
607 0 ▶sub rewrite_vcf_attributes {
Subroutine rewrite_vcf_attributes: not called CC=11 SCAR=48.8
Pod documented
608 0 my $self = shift;
609 0 ▶ return unless ( $self->{data}->vcf );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data"}->vcf 0 0 0
610 0 ▶ return unless exists $self->{attributes};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"attributes"} 0 0 0
611  
612 # INFO
613 my $info = join(
614 ';',
615 map {
616 defined $self->{attributes}->{INFO}{$_}
617 0 ▶ ? join( '=', $_, $self->{attributes}->{INFO}{$_} )
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'attributes'}{'INFO'}{$_} ? : 0 0 0
618 : $_
619 }
620 0 sort { $a cmp $b }
621 0 keys %{ $self->{attributes}->{INFO} }
622 );
623 0 ▶ $info ||= '.'; # sometimes we have nothing left
Condition0%0/2
$info ||= "."
l!l
00
MC/DC0%0/1
$info ||= "."
$info
Truth table0%0/2
A
A= $info
Aresult
11
00
624 0 $self->value( 8, $info );
625  
626 # FORMAT
627 0 my @order;
628 0 ▶ push @order, 'GT' if exists $self->{attributes}{10}{GT};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"attributes"}{10}{"GT"} 0 0 0
629 0 foreach my $key ( sort { $a cmp $b } keys %{ $self->{attributes}{10} } ) {
630 0 ▶ next if $key eq 'GT';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "GT" 0 0 0
631 0 push @order, $key;
632 }
633 0 ▶ if (@order) {
Branch: 1 branch
BranchTrueFalseTotal
if (@order) { } 0 0 0
634 0 $self->value( 9, join( ':', @order ) );
635 }
636 else {
637 0 $self->value( 9, '.' );
638 }
639  
640 # SAMPLES
641 0 foreach my $i ( 10 .. $self->{data}->last_column ) {
642 0 ▶ if (@order) {
Branch: 1 branch
BranchTrueFalseTotal
if (@order) { } 0 0 0
643 0 $self->value( $i, join( ':', map { $self->{attributes}{$i}{$_} } @order ) );
644 }
645 else {
646 0 $self->value( $i, '.' );
647 }
648 }
649 0 return 1;
650 }
651  
652 ### Data collection convenience methods
653  
654 4 *feature = \&seqfeature;
655 4 *feature if 0; # avoid once warning
656  
657 4 ▶sub seqfeature {
Subroutine seqfeature: called CC=12 SCAR=42.4
Pod documented
658 4 my $self = shift;
659 4 ▶ my $force = shift || 0;
Condition50%1/2
shift() || 0
l!l
04
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
660 4 ▶ carp 'ERROR: feature is a read only method' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 4 4
661 4 ▶ return $self->{feature} if exists $self->{feature};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"feature"} 0 4 4
662  
663 # normally this is only for named features in a data table
664 # skip this for coordinate features like bed files
665 4 ▶ return unless $self->feature_type eq 'named' or $force;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->feature_type eq "named" or $force 4 0 4
Condition33%1/3
$self->feature_type eq "named" or $force
l!l&&r!l&&!r
004
MC/DC0%0/2
$self->feature_type eq "named" or $force
$self->feature_type eq "named" $force
Truth table33%1/3
A or B
A= $self->feature_type eq "named"B= $force
ABresult
1X1
011
000
666  
667 # retrieve from main Data store
668 0 my $f = $self->{data}->get_seqfeature( $self->{'index'} );
669 0 ▶ if ($f) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f) 0 0 0
670 0 $self->{feature} = $f;
671 0 return $f;
672 }
673  
674 # retrieve the feature from the database
675 0 ▶ return unless $self->{data}->database;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data"}->database 0 0 0
676 $f = get_db_feature(
677 'db' => $self->{data}->open_meta_database,
678 'id' => $self->id || undef,
679 'name' => $self->name || undef,
680 'type' => $self->type || $self->{data}->feature,
681 0 ▶ );
Condition0%0/7
$self->id || undef
l!l
00
$self->name || undef
l!l
00
$self->type || $self->{'data'}->feature
l!l&&r!l&&!r
000
MC/DC0%0/1
$self->id || undef
$self->id
MC/DC0%0/1
$self->name || undef
$self->name
MC/DC0%0/2
$self->type || $self->{'data'}->feature
$self->type $self->{'data'}->feature
Truth table0%0/2
A
A= $self->id
Aresult
11
00
Truth table0%0/2
A
A= $self->name
Aresult
11
00
Truth table0%0/3
A || B
A= $self->typeB= $self->{'data'}->feature
ABresult
1X1
011
000
682 0 ▶ return unless $f;
Branch: 1 branch
BranchTrueFalseTotal
unless $f 0 0 0
683 0 $self->{feature} = $f;
684 0 return $f;
685 }
686  
687 1 ▶sub segment {
Subroutine segment: called CC=8 SCAR=27.2
Pod documented
688 1 my $self = shift;
689 1 ▶ carp 'ERROR: segment is a read only method' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
690 1 ▶ return unless $self->{data}->database;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data"}->database 0 1 1
691 1 ▶ if ( $self->feature_type eq 'coordinate' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->feature_type eq 'coordinate') { } 1 0 1
elsif ($self->feature_type eq 'named') { } 0 0 0
692 1 my $chromo = $self->seq_id;
693 1 my $start = $self->start;
694 1 ▶ my $stop = $self->end || $start;
Condition33%1/3
$self->end || $start
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->end || $start
$self->end $start
Truth table33%1/3
A || B
A= $self->endB= $start
ABresult
1X1
011
000
695 1 my $db = $self->{data}->open_meta_database;
696 1 ▶ return $db ? $db->segment( $chromo, $start, $stop ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$db ? : 1 0 1
697 }
698 elsif ( $self->feature_type eq 'named' ) {
699 0 my $f = $self->feature;
700 0 ▶ return $f ? $f->segment : undef;
Branch: 1 branch
BranchTrueFalseTotal
$f ? : 0 0 0
701 }
702 else {
703 0 return undef;
704 }
705 }
706  
707 0 ▶sub get_features {
Subroutine get_features: not called CC=9 SCAR=45.0
Pod documented
708 0 my $self = shift;
709 0 my %args = @_;
710 0 ▶ my $db = $args{db} || $self->{data}->open_meta_database || undef;
Condition0%0/5
$args{'db'} || $self->{'data'}->open_meta_database || undef
l!l
00
$args{"db"} or $self->{"data"}->open_meta_database
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'db'} || $self->{'data'}->open_meta_database || undef
$args{"db"} $self->{"data"}->open_meta_database
Truth table0%0/3
A or B
A= $args{"db"}B= $self->{"data"}->open_meta_database
ABresult
1X1
011
000
711 0 ▶ carp 'ERROR: no database defined to get features!' unless defined $db;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $db 0 0 0
712 0 ▶ return unless $db->can('features');
Branch: 1 branch
BranchTrueFalseTotal
unless $db->can("features") 0 0 0
713  
714 # convert the argument style for most bioperl db APIs
715 0 my %opts;
716 0 ▶ $opts{-seq_id} = $args{chromo} || $self->seq_id;
Condition0%0/3
$args{'chromo'} || $self->seq_id
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'chromo'} || $self->seq_id
$args{'chromo'} $self->seq_id
Truth table0%0/3
A || B
A= $args{'chromo'}B= $self->seq_id
ABresult
1X1
011
000
717 0 ▶ $opts{-start} = $args{start} || $self->start;
Condition0%0/3
$args{'start'} || $self->start
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'start'} || $self->start
$args{'start'} $self->start
Truth table0%0/3
A || B
A= $args{'start'}B= $self->start
ABresult
1X1
011
000
718 0 ▶ $opts{-end} = $args{end} || $self->end;
Condition0%0/3
$args{'end'} || $self->end
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'end'} || $self->end
$args{'end'} $self->end
Truth table0%0/3
A || B
A= $args{'end'}B= $self->end
ABresult
1X1
011
000
719 0 ▶ $opts{-type} = $args{type} || $self->type;
Condition0%0/3
$args{'type'} || $self->type
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'type'} || $self->type
$args{'type'} $self->type
Truth table0%0/3
A || B
A= $args{'type'}B= $self->type
ABresult
1X1
011
000
720  
721 0 return $db->features(%opts);
722 }
723  
724 0 ▶sub get_sequence {
Subroutine get_sequence: not called CC=21 SCAR=61.4
Pod documented
725 0 my $self = shift;
726 0 my %args = @_;
727 0 ▶ my $db = $args{db} || $args{database} || $self->{data}->open_meta_database || undef;
Condition0%0/8
$args{'db'} || $args{'database'} || $self->{'data'}->open_meta_database || undef
l!l
00
$args{"db"} or $args{"database"} or $self->{"data"}->open_meta_database
l!l&&r!l&&!r
000
$args{"db"} or $args{"database"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{'db'} || $args{'database'} || $self->{'data'}->open_meta_database || undef
$args{"db"} $args{"database"} $self->{"data"}->open_meta_database
Truth table0%0/4
A or B or C
A= $args{"db"}B= $args{"database"}C= $self->{"data"}->open_meta_database
ABCresult
1XX1
01X1
0011
0000
728  
729 # this will fail immediately if user doesn't provide valid database
730  
731 # get sequence over subfeatures
732 0 ▶ $args{subfeature} ||= undef;
Condition0%0/2
$args{"subfeature"} ||= undef
l!l
00
MC/DC0%0/1
$args{"subfeature"} ||= undef
$args{"subfeature"}
Truth table0%0/2
A
A= $args{"subfeature"}
Aresult
11
00
733 0 ▶ if ( $self->feature_type eq 'named' and $args{subfeature} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->feature_type eq "named" and $args{"subfeature"}) 0 0 0
Condition0%0/3
$self->feature_type eq "named" and $args{"subfeature"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->feature_type eq "named" and $args{"subfeature"}
$self->feature_type eq "named" $args{"subfeature"}
Truth table0%0/3
A and B
A= $self->feature_type eq "named"B= $args{"subfeature"}
ABresult
0X0
100
111
734  
735 # this is more complicated so we have a dedicated method
736 0 return $self->_get_subfeature_sequence( $db, \%args );
737 }
738  
739 # get coordinates
740 0 ▶ my $seqid = $args{seq_id} || $args{chromo} || $self->seq_id;
Condition0%0/6
$args{'seq_id'} || $args{'chromo'} || $self->seq_id
l!l&&r!l&&!r
000
$args{"seq_id"} or $args{"chromo"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{'seq_id'} || $args{'chromo'} || $self->seq_id
$args{"seq_id"} $args{"chromo"} $self->seq_id
Truth table0%0/4
A or B || C
A= $args{"seq_id"}B= $args{"chromo"}C= $self->seq_id
ABCresult
1XX1
01X1
0011
0000
741 0 ▶ my $start = $args{start} || $self->start;
Condition0%0/3
$args{'start'} || $self->start
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'start'} || $self->start
$args{'start'} $self->start
Truth table0%0/3
A || B
A= $args{'start'}B= $self->start
ABresult
1X1
011
000
742 0 ▶ my $stop = $args{stop} || $args{end} || $self->end;
Condition0%0/6
$args{'stop'} || $args{'end'} || $self->end
l!l&&r!l&&!r
000
$args{"stop"} or $args{"end"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{'stop'} || $args{'end'} || $self->end
$args{"stop"} $args{"end"} $self->end
Truth table0%0/4
A or B || C
A= $args{"stop"}B= $args{"end"}C= $self->end
ABCresult
1XX1
01X1
0011
0000
743 0 my $strand = $self->strand;
744 0 ▶ if ( exists $args{strand} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"strand"}) 0 0 0
745  
746 # user supplied strand, gotta check it
747 0 ▶ $strand = $args{strand} =~ /\-|r/i ? -1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$args{'strand'} =~ /\-|r/i ? : 0 0 0
748 }
749 0 ▶ if ( exists $args{extend} and $args{extend} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"extend"} and $args{"extend"}) 0 0 0
Condition0%0/3
exists $args{"extend"} and $args{"extend"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args{"extend"} and $args{"extend"}
exists $args{"extend"} $args{"extend"}
Truth table0%0/3
A and B
A= exists $args{"extend"}B= $args{"extend"}
ABresult
0X0
100
111
750 0 $start -= $args{extend};
751 0 ▶ $start = 1 if $start <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $start <= 0 0 0 0
752 0 $stop += $args{extend};
753 }
754 0 ▶ return unless ( defined $seqid and defined $start and defined $stop );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seqid and defined $start and defined $stop 0 0 0
Condition0%0/6
defined $seqid and defined $start and defined $stop
!ll&&!rl&&r
000
defined $seqid and defined $start
!ll&&!rl&&r
000
MC/DC0%0/3
defined $seqid and defined $start and defined $stop
defined $seqid defined $start defined $stop
Truth table0%0/4
A and B and C
A= defined $seqidB= defined $startC= defined $stop
ABCresult
0XX0
10X0
1100
1111
755  
756 # retrieve and return sequence
757 0 my $seq = get_genomic_sequence( $db, $seqid, $start, $stop );
758 0 ▶ if ( $strand == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strand == -1) 0 0 0
759 0 $seq =~ tr/gatcGATC/ctagCTAG/;
760 0 $seq = reverse $seq;
761 }
762 0 return $seq;
763 }
764  
765 0 ▶sub _get_subfeature_sequence {
Subroutine _get_subfeature_sequence: not called CC=5 SCAR=34.0
766 0 my ( $self, $db, $args ) = @_;
767  
768 # get the subfeatures
769 0 my $subfeatures = $self->_get_subfeatures( $args->{subfeature} );
770 0 ▶ unless ( @{$subfeatures} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$subfeatures;}) 0 0 0
771 0 carp 'ERROR: no subfeatures available! Returning parent sequence!';
772  
773 # just return the parent
774 0 undef $args->{subfeature};
775 0 return $self->get_sequence( @{$args} );
776 }
777  
778 # sort subfeatures
779 # this should be done by GeneTools in most cases but just to be sure
780 # note that this does NOT merge redundant or overlapping exons!!!!
781 0 my @sorted = map { $_->[0] }
782 0 ▶ sort { $a->[1] <=> $b->[1] or $a->[2] <=> $b->[2] }
Condition0%0/3
$Bio::ToolBox::Data::Feature::a->[1] <=> $Bio::ToolBox::Data::Feature::b->[1] || $Bio::ToolBox::Data::Feature::a->[2] <=> $Bio::ToolBox::Data::Feature::b->[2]
l!l&&r!l&&!r
000
MC/DC0%0/2
$Bio::ToolBox::Data::Feature::a->[1] <=> $Bio::ToolBox::Data::Feature::b->[1] || $Bio::ToolBox::Data::Feature::a->[2] <=> $Bio::ToolBox::Data::Feature::b->[2]
$Bio::ToolBox::Data::Feature::a->[1] <=> $Bio::ToolBox::Data::Feature::b->[1] $Bio::ToolBox::Data::Feature::a->[2] <=> $Bio::ToolBox::Data::Feature::b->[2]
Truth table0%0/3
A || B
A= $Bio::ToolBox::Data::Feature::a->[1] <=> $Bio::ToolBox::Data::Feature::b->[1]B= $Bio::ToolBox::Data::Feature::a->[2] <=> $Bio::ToolBox::Data::Feature::b->[2]
ABresult
1X1
011
000
783 0 map { [ $_, $_->start, $_->end ] } @{$subfeatures};
784  
785 # collect sequence
786 0 my $sequence;
787 0 foreach my $subf (@sorted) {
788 0 my $seq = get_genomic_sequence( $db, $subf->seq_id, $subf->start, $subf->stop );
789 0 $sequence .= $seq;
790 }
791  
792 # flip the sequence
793 0 ▶ if ( $self->strand == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->strand == -1) 0 0 0
794 0 $sequence =~ tr/gatcGATC/ctagCTAG/;
795 0 $sequence = reverse $sequence;
796 }
797 0 return $sequence;
798 }
799  
800 0 ▶sub _get_subfeatures {
Subroutine _get_subfeatures: not called CC=9 SCAR=45.0
801 0 my $self = shift;
802 0 my $subf = lc shift;
803  
804 # load GeneTools
805 0 ▶ unless ($GENETOOL_LOADED) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($GENETOOL_LOADED) 0 0 0
806 0 load(
807 'Bio::ToolBox::GeneTools', qw(get_exons get_cds get_5p_utrs get_3p_utrs
808 get_introns)
809 );
810 0 ▶ if ($EVAL_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::ToolBox::Data::Feature::EVAL_ERROR) { } 0 0 0
811 0 croak "FATAL: missing required modules! $EVAL_ERROR";
812 }
813 else {
814 0 $GENETOOL_LOADED = 1;
815 }
816 }
817  
818 # feature
819 0 my $feature = $self->seqfeature;
820 0 ▶ return unless ($feature);
Branch: 1 branch
BranchTrueFalseTotal
unless $feature 0 0 0
821  
822 # get the subfeatures
823 0 my @subfeatures;
824 0 ▶ if ( $subf eq 'exon' ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($subf eq 'exon') { } 0 0 0
elsif ($subf eq 'cds') { } 0 0 0
elsif ($subf eq '5p_utr') { } 0 0 0
elsif ($subf eq '3p_utr') { } 0 0 0
elsif ($subf eq 'intron') { } 0 0 0
825 0 @subfeatures = get_exons($feature);
826 }
827 elsif ( $subf eq 'cds' ) {
828 0 @subfeatures = get_cds($feature);
829 }
830 elsif ( $subf eq '5p_utr' ) {
831 0 @subfeatures = get_5p_utrs($feature);
832 }
833 elsif ( $subf eq '3p_utr' ) {
834 0 @subfeatures = get_3p_utrs($feature);
835 }
836 elsif ( $subf eq 'intron' ) {
837 0 @subfeatures = get_introns($feature);
838 }
839 else {
840 0 croak "ERROR: unrecognized subfeature parameter '$subf'!";
841 }
842  
843 0 return \@subfeatures;
844 }
845  
846 7 ▶sub get_score {
Subroutine get_score: called CC=33 SCAR=55.0
Pod documented
847 7 my $self = shift;
848 7 my %args = @_; # passed arguments to this method
849  
850 # verify the dataset for the user, cannot trust whether it has been done or not
851 7 ▶ my $db = $args{ddb} || $args{db} || $self->{data}->open_meta_database || undef;
Condition62%5/8
$args{'ddb'} || $args{'db'} || $self->{'data'}->open_meta_database || undef
l!l
70
$args{"ddb"} or $args{"db"} or $self->{"data"}->open_meta_database
l!l&&r!l&&!r
430
$args{"ddb"} or $args{"db"}
l!l&&r!l&&!r
043
MC/DC0%0/3
$args{'ddb'} || $args{'db'} || $self->{'data'}->open_meta_database || undef
$args{"ddb"} $args{"db"} $self->{"data"}->open_meta_database
Truth table50%2/4
A or B or C
A= $args{"ddb"}B= $args{"db"}C= $self->{"data"}->open_meta_database
ABCresult
1XX1
01X1
0011
0000
852 7 $args{dataset} = $self->{data}->verify_dataset( $args{dataset}, $db );
853 7 ▶ unless ( $args{dataset} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"dataset"}) 0 7 7
854 0 croak
855 'FATAL: provided dataset was unrecognized format or otherwise could not be verified!';
856 }
857  
858 # get positioned scores over subfeatures only
859 7 ▶ $args{subfeature} ||= q();
Condition50%1/2
$args{"subfeature"} ||= ""
l!l
07
MC/DC0%0/1
$args{"subfeature"} ||= ""
$args{"subfeature"}
Truth table50%1/2
A
A= $args{"subfeature"}
Aresult
11
00
860 7 ▶ if ( $self->feature_type eq 'named' and $args{subfeature} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->feature_type eq "named" and $args{"subfeature"}) 0 7 7
Condition33%1/3
$self->feature_type eq "named" and $args{"subfeature"}
!ll&&!rl&&r
700
MC/DC0%0/2
$self->feature_type eq "named" and $args{"subfeature"}
$self->feature_type eq "named" $args{"subfeature"}
Truth table33%1/3
A and B
A= $self->feature_type eq "named"B= $args{"subfeature"}
ABresult
0X0
100
111
861  
862 # this is more complicated so we have a dedicated method
863 0 return $self->_get_subfeature_scores( $db, \%args );
864 }
865  
866 # build parameter array to pass on to the adapter
867 7 my @params;
868  
869 # verify coordinates based on type of feature
870 7 ▶ if ( $self->feature_type eq 'coordinate' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->feature_type eq 'coordinate') { } 7 0 7
elsif ($self->feature_type eq 'named') { } 0 0 0
871  
872 # coordinates are already in the table, use those
873 7 ▶ $params[CHR] = $args{seq_id} || $self->seq_id;
Condition33%1/3
$args{'seq_id'} || $self->seq_id
l!l&&r!l&&!r
070
MC/DC0%0/2
$args{'seq_id'} || $self->seq_id
$args{'seq_id'} $self->seq_id
Truth table33%1/3
A || B
A= $args{'seq_id'}B= $self->seq_id
ABresult
1X1
011
000
874 7 ▶ $params[STRT] = $args{start} || $self->start;
Condition33%1/3
$args{'start'} || $self->start
l!l&&r!l&&!r
070
MC/DC0%0/2
$args{'start'} || $self->start
$args{'start'} $self->start
Truth table33%1/3
A || B
A= $args{'start'}B= $self->start
ABresult
1X1
011
000
875 7 ▶ $params[STOP] = $args{stop} || $args{end} || $self->end;
Condition33%2/6
$args{'stop'} || $args{'end'} || $self->end
l!l&&r!l&&!r
070
$args{"stop"} or $args{"end"}
l!l&&r!l&&!r
007
MC/DC0%0/3
$args{'stop'} || $args{'end'} || $self->end
$args{"stop"} $args{"end"} $self->end
Truth table25%1/4
A or B || C
A= $args{"stop"}B= $args{"end"}C= $self->end
ABCresult
1XX1
01X1
0011
0000
876 $params[STR] =
877 ( exists $args{strand} and defined $args{strand} )
878 ? $args{strand}
879 7 ▶ : $self->strand;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'strand'} && defined $args{'strand'} ? : 0 7 7
Condition33%1/3
exists $args{"strand"} and defined $args{"strand"}
!ll&&!rl&&r
700
MC/DC0%0/2
exists $args{"strand"} and defined $args{"strand"}
exists $args{"strand"} defined $args{"strand"}
Truth table33%1/3
A and B
A= exists $args{"strand"}B= defined $args{"strand"}
ABresult
0X0
100
111
880 }
881 elsif ( $self->feature_type eq 'named' ) {
882  
883 # must retrieve feature from the database first
884 0 my $f = $self->seqfeature;
885 0 ▶ return unless $f;
Branch: 1 branch
BranchTrueFalseTotal
unless $f 0 0 0
886 0 ▶ $params[CHR] = $args{seq_id} || $f->seq_id;
Condition0%0/3
$args{'seq_id'} || $f->seq_id
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'seq_id'} || $f->seq_id
$args{'seq_id'} $f->seq_id
Truth table0%0/3
A || B
A= $args{'seq_id'}B= $f->seq_id
ABresult
1X1
011
000
887 0 ▶ $params[STRT] = $args{start} || $f->start;
Condition0%0/3
$args{'start'} || $f->start
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'start'} || $f->start
$args{'start'} $f->start
Truth table0%0/3
A || B
A= $args{'start'}B= $f->start
ABresult
1X1
011
000
888 0 ▶ $params[STOP] = $args{stop} || $args{end} || $f->end;
Condition0%0/6
$args{'stop'} || $args{'end'} || $f->end
l!l&&r!l&&!r
000
$args{"stop"} or $args{"end"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{'stop'} || $args{'end'} || $f->end
$args{"stop"} $args{"end"} $f->end
Truth table0%0/4
A or B || C
A= $args{"stop"}B= $args{"end"}C= $f->end
ABCresult
1XX1
01X1
0011
0000
889 $params[STR] =
890 ( exists $args{strand} and defined $args{strand} )
891 ? $args{strand}
892 0 ▶ : $f->strand;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'strand'} && defined $args{'strand'} ? : 0 0 0
Condition0%0/3
exists $args{"strand"} and defined $args{"strand"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args{"strand"} and defined $args{"strand"}
exists $args{"strand"} defined $args{"strand"}
Truth table0%0/3
A and B
A= exists $args{"strand"}B= defined $args{"strand"}
ABresult
0X0
100
111
893 }
894 else {
895 0 croak
896 'FATAL: data table does not have identifiable coordinate or feature identification columns for score collection';
897 }
898  
899 # adjust coordinates as necessary
900 7 ▶ if ( exists $args{extend} and $args{extend} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"extend"} and $args{"extend"}) 0 7 7
Condition33%1/3
exists $args{"extend"} and $args{"extend"}
!ll&&!rl&&r
700
MC/DC0%0/2
exists $args{"extend"} and $args{"extend"}
exists $args{"extend"} $args{"extend"}
Truth table33%1/3
A and B
A= exists $args{"extend"}B= $args{"extend"}
ABresult
0X0
100
111
901 0 $params[STRT] -= $args{extend};
902 0 $params[STOP] += $args{extend};
903 }
904  
905 # check coordinates
906 7 ▶ $params[STRT] = 1 if $params[STRT] <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $params[1] <= 0 0 7 7
907 7 ▶ if ( $params[STOP] < $params[STRT] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params[2] < $params[1]) 0 7 7
908  
909 # coordinates are flipped, reverse strand
910 0 ▶ return if ( $params[STOP] <= 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $params[2] <= 0 0 0 0
911 0 my $stop = $params[STRT];
912 0 $params[STRT] = $params[STOP];
913 0 $params[STOP] = $stop;
914 0 $params[STR] = -1;
915 }
916 7 ▶ return unless ( $params[CHR] and defined $params[STRT] );
Branch: 1 branch
BranchTrueFalseTotal
unless $params[0] and defined $params[1] 0 7 7
Condition33%1/3
$params[0] and defined $params[1]
!ll&&!rl&&r
007
MC/DC0%0/2
$params[0] and defined $params[1]
$params[0] defined $params[1]
Truth table33%1/3
A and B
A= $params[0]B= defined $params[1]
ABresult
0X0
100
111
917  
918 # score attributes
919 7 ▶ $params[METH] = $args{'method'} || 'mean';
Condition50%1/2
$args{'method'} || 'mean'
l!l
70
MC/DC0%0/1
$args{'method'} || 'mean'
$args{'method'}
Truth table50%1/2
A
A= $args{'method'}
Aresult
11
00
920 7 ▶ $params[STND] = $args{strandedness} || $args{stranded} || 'all';
Condition80%4/5
$args{'strandedness'} || $args{'stranded'} || 'all'
l!l
34
$args{"strandedness"} or $args{"stranded"}
l!l&&r!l&&!r
034
MC/DC50%1/2
$args{'strandedness'} || $args{'stranded'} || 'all'
$args{"strandedness"} $args{"stranded"}
Truth table66%2/3
A or B
A= $args{"strandedness"}B= $args{"stranded"}
ABresult
1X1
011
000
921  
922 # other parameters
923 7 $params[DB] = $db;
924 7 $params[RETT] = 0; # return type should be a calculated value
925 7 $params[DATA] = $args{dataset};
926  
927 # get the score
928 7 return get_segment_score(@params);
929 }
930  
931 0 ▶sub _get_subfeature_scores {
Subroutine _get_subfeature_scores: not called CC=8 SCAR=42.8
932 0 my ( $self, $db, $args ) = @_;
933  
934 # get the subfeatures
935 0 my $subfeatures = $self->_get_subfeatures( $args->{subfeature} );
936 0 ▶ unless ( @{$subfeatures} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$subfeatures;}) 0 0 0
937  
938 # no subfeatures, nothing to collect
939 0 return;
940 }
941  
942 # collect over each subfeature
943 0 my @scores;
944 0 foreach my $exon ( @{$subfeatures} ) {
945 0 my @params; # parameters to pass on to adapter
946 0 $params[CHR] = $exon->seq_id;
947 0 $params[STRT] = $exon->start;
948 0 $params[STOP] = $exon->end;
949 0 ▶ $params[STR] = defined $args->{strand} ? $args->{strand} : $exon->strand;
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'strand'} ? : 0 0 0
950 0 ▶ $params[STND] = $args->{strandedness} || $args->{stranded} || 'all';
Condition0%0/5
$args->{'strandedness'} || $args->{'stranded'} || 'all'
l!l
00
$args->{"strandedness"} or $args->{"stranded"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'strandedness'} || $args->{'stranded'} || 'all'
$args->{"strandedness"} $args->{"stranded"}
Truth table0%0/3
A or B
A= $args->{"strandedness"}B= $args->{"stranded"}
ABresult
1X1
011
000
951 0 ▶ $params[METH] = $args->{method} || 'mean';
Condition0%0/2
$args->{'method'} || 'mean'
l!l
00
MC/DC0%0/1
$args->{'method'} || 'mean'
$args->{'method'}
Truth table0%0/2
A
A= $args->{'method'}
Aresult
11
00
952 0 $params[RETT] = 1; # return type should be an array reference of scores
953 0 $params[DB] = $db;
954 0 $params[DATA] = $args->{dataset};
955  
956 0 my $exon_scores = get_segment_score(@params);
957 0 ▶ push @scores, @{$exon_scores} if defined $exon_scores;
Branch: 1 branch
BranchTrueFalseTotal
if defined $exon_scores 0 0 0
958 }
959  
960 # combine all the scores based on the requested method
961 0 return calculate_score( $args->{method}, \@scores );
962 }
963  
964 1 ▶sub get_relative_point_position_scores {
Subroutine get_relative_point_position_scores: called CC=19 SCAR=36.5
Pod documented
965 1 my $self = shift;
966 1 my %args = @_;
967  
968 # get the database and verify the dataset
969 1 ▶ my $ddb = $args{ddb} || $args{db} || $self->{data}->open_meta_database;
Condition33%2/6
$args{'ddb'} || $args{'db'} || $self->{'data'}->open_meta_database
l!l&&r!l&&!r
010
$args{"ddb"} or $args{"db"}
l!l&&r!l&&!r
001
MC/DC0%0/3
$args{'ddb'} || $args{'db'} || $self->{'data'}->open_meta_database
$args{"ddb"} $args{"db"} $self->{'data'}->open_meta_database
Truth table25%1/4
A or B || C
A= $args{"ddb"}B= $args{"db"}C= $self->{'data'}->open_meta_database
ABCresult
1XX1
01X1
0011
0000
970 1 $args{dataset} = $self->{data}->verify_dataset( $args{dataset}, $ddb );
971 1 ▶ unless ( $args{dataset} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"dataset"}) 0 1 1
972 0 croak
973 'FATAL: provided dataset was unrecognized format or otherwise could not be verified!';
974 }
975  
976 # assign some defaults
977 1 ▶ $args{strandedness} ||= $args{stranded} || 'all';
Condition40%2/5
$args{"strandedness"} ||= $args{"stranded"} || "all"
l!l&&r!l&&!r
010
$args{'stranded'} || 'all'
l!l
10
MC/DC0%0/2
$args{"strandedness"} ||= $args{"stranded"} || "all"
$args{"strandedness"} $args{'stranded'}
Truth table33%1/3
A ||= B
A= $args{"strandedness"}B= $args{'stranded'}
ABresult
1X1
011
000
978 1 ▶ $args{position} ||= 5;
Condition50%1/2
$args{"position"} ||= 5
l!l
10
MC/DC0%0/1
$args{"position"} ||= 5
$args{"position"}
Truth table50%1/2
A
A= $args{"position"}
Aresult
11
00
979 1 ▶ $args{coordinate} ||= undef;
Condition50%1/2
$args{"coordinate"} ||= undef
l!l
01
MC/DC0%0/1
$args{"coordinate"} ||= undef
$args{"coordinate"}
Truth table50%1/2
A
A= $args{"coordinate"}
Aresult
11
00
980 1 ▶ $args{avoid} ||= undef;
Condition50%1/2
$args{"avoid"} ||= undef
l!l
01
MC/DC0%0/1
$args{"avoid"} ||= undef
$args{"avoid"}
Truth table50%1/2
A
A= $args{"avoid"}
Aresult
11
00
981 1 ▶ $args{'method'} ||= 'mean'; # in most cases this doesn't do anything
Condition50%1/2
$args{"method"} ||= "mean"
l!l
01
MC/DC0%0/1
$args{"method"} ||= "mean"
$args{"method"}
Truth table50%1/2
A
A= $args{"method"}
Aresult
11
00
982 1 ▶ unless ( $args{extend} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"extend"}) 0 1 1
983 0 croak 'FATAL: must provide an extend value!';
984 }
985 1 ▶ $args{avoid} = undef unless ( $args{db} or $self->{data}->open_meta_database );
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"db"} or $self->{"data"}->open_meta_database 0 1 1
Condition33%1/3
$args{"db"} or $self->{"data"}->open_meta_database
l!l&&r!l&&!r
010
MC/DC0%0/2
$args{"db"} or $self->{"data"}->open_meta_database
$args{"db"} $self->{"data"}->open_meta_database
Truth table33%1/3
A or B
A= $args{"db"}B= $self->{"data"}->open_meta_database
ABresult
1X1
011
000
986  
987 # determine reference coordinate
988 1 ▶ unless ( defined $args{coordinate} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"coordinate"}) 1 0 1
989 1 $args{coordinate} = $self->calculate_reference( \%args );
990 }
991  
992 # build parameter array to pass on to the adapter
993 1 my @params;
994 1 $params[CHR] = $self->seq_id;
995 1 $params[STRT] = $args{coordinate} - $args{extend};
996 1 ▶ $params[STRT] = 1 if $params[STRT] < 1; # sanity check
Branch: 1 branch
BranchTrueFalseTotal
if $params[1] < 1 0 1 1
997 1 $params[STOP] = $args{coordinate} + $args{extend};
998 1 ▶ $params[STR] = defined $args{strand} ? $args{strand} : $self->strand;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'strand'} ? : 0 1 1
999 1 $params[STND] = $args{strandedness};
1000 1 $params[METH] = $args{'method'};
1001 1 $params[RETT] = 2; # return type should be a hash reference of positioned scores
1002 1 $params[DB] = $ddb;
1003 1 $params[DATA] = $args{dataset};
1004  
1005 # Data collection
1006 1 my $pos2data = get_segment_score(@params);
1007  
1008 # Avoid positions
1009 1 ▶ if ( $args{avoid} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"avoid"}) 0 1 1
1010 0 $self->_avoid_positions( $pos2data, \%args, $params[CHR], $params[STRT],
1011 $params[STOP] );
1012 }
1013  
1014 # covert to relative positions
1015 1 ▶ if ( $args{absolute} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'absolute'}) { } 0 1 1
1016  
1017 # do not convert to relative positions
1018 0 ▶ return wantarray ? %{$pos2data} : $pos2data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1019 }
1020 else {
1021 # return the collected dataset hash
1022 return $self->_convert_to_relative_positions( $pos2data,
1023 1 $args{coordinate}, $params[STR] );
1024 }
1025 }
1026  
1027 4 ▶sub get_region_position_scores {
Subroutine get_region_position_scores: called CC=27 SCAR=45.6
Pod documented
1028 4 my $self = shift;
1029 4 my %args = @_;
1030  
1031 # get the database and verify the dataset
1032 4 ▶ my $ddb = $args{ddb} || $args{db} || $self->{data}->open_meta_database;
Condition33%2/6
$args{'ddb'} || $args{'db'} || $self->{'data'}->open_meta_database
l!l&&r!l&&!r
040
$args{"ddb"} or $args{"db"}
l!l&&r!l&&!r
004
MC/DC0%0/3
$args{'ddb'} || $args{'db'} || $self->{'data'}->open_meta_database
$args{"ddb"} $args{"db"} $self->{'data'}->open_meta_database
Truth table25%1/4
A or B || C
A= $args{"ddb"}B= $args{"db"}C= $self->{'data'}->open_meta_database
ABCresult
1XX1
01X1
0011
0000
1033 4 $args{dataset} = $self->{data}->verify_dataset( $args{dataset}, $ddb );
1034 4 ▶ unless ( $args{dataset} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"dataset"}) 0 4 4
1035 0 croak
1036 'FATAL: provided dataset was unrecognized format or otherwise could not be verified!';
1037 }
1038  
1039 # assign some defaults here, in case we get passed on to subfeature method
1040 4 ▶ $args{strandedness} ||= $args{stranded} || 'all';
Condition40%2/5
$args{"strandedness"} ||= $args{"stranded"} || "all"
l!l&&r!l&&!r
040
$args{'stranded'} || 'all'
l!l
40
MC/DC0%0/2
$args{"strandedness"} ||= $args{"stranded"} || "all"
$args{"strandedness"} $args{'stranded'}
Truth table33%1/3
A ||= B
A= $args{"strandedness"}B= $args{'stranded'}
ABresult
1X1
011
000
1041 4 ▶ $args{extend} ||= 0;
Condition50%1/2
$args{"extend"} ||= 0
l!l
04
MC/DC0%0/1
$args{"extend"} ||= 0
$args{"extend"}
Truth table50%1/2
A
A= $args{"extend"}
Aresult
11
00
1042 4 ▶ $args{position} ||= 5;
Condition50%1/2
$args{"position"} ||= 5
l!l
04
MC/DC0%0/1
$args{"position"} ||= 5
$args{"position"}
Truth table50%1/2
A
A= $args{"position"}
Aresult
11
00
1043 4 ▶ $args{'method'} ||= 'mean'; # in most cases this doesn't do anything
Condition100%2/2
$args{"method"} ||= "mean"
l!l
31
MC/DC100%1/1
$args{"method"} ||= "mean"
$args{"method"}
Truth table100%2/2
A
A= $args{"method"}
Aresult
11
00
1044 4 ▶ $args{avoid} = undef unless ( $args{db} or $self->{data}->open_meta_database );
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"db"} or $self->{"data"}->open_meta_database 0 4 4
Condition33%1/3
$args{"db"} or $self->{"data"}->open_meta_database
l!l&&r!l&&!r
040
MC/DC0%0/2
$args{"db"} or $self->{"data"}->open_meta_database
$args{"db"} $self->{"data"}->open_meta_database
Truth table33%1/3
A or B
A= $args{"db"}B= $self->{"data"}->open_meta_database
ABresult
1X1
011
000
1045  
1046 # get positioned scores over subfeatures only
1047 4 ▶ $args{subfeature} ||= q();
Condition50%1/2
$args{"subfeature"} ||= ""
l!l
04
MC/DC0%0/1
$args{"subfeature"} ||= ""
$args{"subfeature"}
Truth table50%1/2
A
A= $args{"subfeature"}
Aresult
11
00
1048 4 ▶ if ( $self->feature_type eq 'named' and $args{subfeature} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->feature_type eq "named" and $args{"subfeature"}) 0 4 4
Condition33%1/3
$self->feature_type eq "named" and $args{"subfeature"}
!ll&&!rl&&r
400
MC/DC0%0/2
$self->feature_type eq "named" and $args{"subfeature"}
$self->feature_type eq "named" $args{"subfeature"}
Truth table33%1/3
A and B
A= $self->feature_type eq "named"B= $args{"subfeature"}
ABresult
0X0
100
111
1049  
1050 # this is more complicated so we have a dedicated method
1051 0 return $self->_get_subfeature_position_scores( \%args, $ddb );
1052 }
1053  
1054 # Assign coordinates
1055 # build parameter array to pass on to the adapter
1056 4 my @params;
1057 4 ▶ my $feature = $self->seqfeature || $self;
Condition33%1/3
$self->seqfeature || $self
l!l&&r!l&&!r
040
MC/DC0%0/2
$self->seqfeature || $self
$self->seqfeature $self
Truth table33%1/3
A || B
A= $self->seqfeatureB= $self
ABresult
1X1
011
000
1058 4 ▶ $params[CHR] = $args{chromo} || $args{seq_id} || $feature->seq_id;
Condition33%2/6
$args{'chromo'} || $args{'seq_id'} || $feature->seq_id
l!l&&r!l&&!r
040
$args{"chromo"} or $args{"seq_id"}
l!l&&r!l&&!r
004
MC/DC0%0/3
$args{'chromo'} || $args{'seq_id'} || $feature->seq_id
$args{"chromo"} $args{"seq_id"} $feature->seq_id
Truth table25%1/4
A or B || C
A= $args{"chromo"}B= $args{"seq_id"}C= $feature->seq_id
ABCresult
1XX1
01X1
0011
0000
1059 4 ▶ $params[STRT] = $args{start} || $feature->start;
Condition33%1/3
$args{'start'} || $feature->start
l!l&&r!l&&!r
040
MC/DC0%0/2
$args{'start'} || $feature->start
$args{'start'} $feature->start
Truth table33%1/3
A || B
A= $args{'start'}B= $feature->start
ABresult
1X1
011
000
1060 4 ▶ $params[STOP] = $args{stop} || $args{end} || $feature->end;
Condition33%2/6
$args{'stop'} || $args{'end'} || $feature->end
l!l&&r!l&&!r
040
$args{"stop"} or $args{"end"}
l!l&&r!l&&!r
004
MC/DC0%0/3
$args{'stop'} || $args{'end'} || $feature->end
$args{"stop"} $args{"end"} $feature->end
Truth table25%1/4
A or B || C
A= $args{"stop"}B= $args{"end"}C= $feature->end
ABCresult
1XX1
01X1
0011
0000
1061 4 ▶ $params[STR] = defined $args{strand} ? $args{strand} : $feature->strand;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'strand'} ? : 0 4 4
1062 4 ▶ if ( $args{extend} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"extend"}) 0 4 4
1063 0 $params[STRT] -= $args{extend};
1064 0 $params[STOP] += $args{extend};
1065 0 ▶ $params[STRT] = 1 if $params[STRT] < 1; # sanity check
Branch: 1 branch
BranchTrueFalseTotal
if $params[1] < 1 0 0 0
1066 }
1067 4 $params[STND] = $args{strandedness};
1068 4 $params[METH] = $args{method};
1069 4 $params[RETT] = 2; # return type should be a hash reference of positioned scores
1070 4 $params[DB] = $ddb;
1071 4 $params[DATA] = $args{dataset};
1072  
1073 # Data collection
1074 4 my $pos2data = get_segment_score(@params);
1075  
1076 # Avoid positions
1077 4 ▶ if ( $args{avoid} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"avoid"}) 0 4 4
1078 0 $self->_avoid_positions( $pos2data, \%args, $params[CHR], $params[STRT],
1079 $params[STOP] );
1080 }
1081  
1082 # covert to relative positions
1083 4 ▶ if ( $args{absolute} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'absolute'}) { } 0 4 4
1084 0 ▶ return wantarray ? %{$pos2data} : $pos2data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1085 }
1086 else {
1087 # return data converted to relative positions
1088 4 ▶ unless ( defined $args{coordinate} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"coordinate"}) 4 0 4
1089 4 $args{coordinate} = $self->calculate_reference( \%args );
1090 }
1091 return $self->_convert_to_relative_positions( $pos2data,
1092 4 $args{coordinate}, $params[STR] );
1093 }
1094 }
1095  
1096 0 ▶sub _get_subfeature_position_scores {
Subroutine _get_subfeature_position_scores: not called CC=8 SCAR=42.8
1097 0 my ( $self, $args, $ddb ) = @_;
1098  
1099 # get the subfeatures
1100 0 my $subfeatures = $self->_get_subfeatures( $args->{subfeature} );
1101 0 ▶ unless ( @{$subfeatures} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$subfeatures;}) 0 0 0
1102 0 carp 'ERROR: no subfeatures available! Returning parent score data!';
1103  
1104 # just return the parent
1105 0 undef $args->{subfeature};
1106 0 ▶ delete $args->{exon} if exists $args->{exon};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"exon"} 0 0 0
1107 0 return $self->get_sequence( @{$args} );
1108 }
1109  
1110 # reset the practical start and stop to the actual subfeatures' final start and stop
1111 # we can no longer rely on the feature start and stop, consider CDS
1112 # these subfeatures should already be genomic sorted by GeneTools
1113 0 my $practical_start = $subfeatures->[0]->start;
1114 0 my $practical_stop = $subfeatures->[-1]->end;
1115  
1116 # collect over each exon
1117 # we will adjust the positions of each reported score so that
1118 # it will appear as if all the exons are adjacent to each other
1119 # and no introns exist
1120 0 my $pos2data = {};
1121 0 my $namecheck = {}; # to check unique names when using ncount method....
1122 0 my $current_end = $practical_start;
1123 0 my $adjustment = 0;
1124 0 ▶ my $fstrand = defined $args->{strand} ? $args->{strand} : $self->strand;
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'strand'} ? : 0 0 0
1125 0 foreach my $exon ( @{$subfeatures} ) {
1126  
1127 0 my @params; # parameters to pass on to adapter
1128 0 $params[CHR] = $exon->seq_id;
1129 0 $params[STRT] = $exon->start;
1130 0 $params[STOP] = $exon->end;
1131 0 $params[STR] = $fstrand;
1132 0 $params[STND] = $args->{strandedness};
1133 0 $params[METH] = $args->{method};
1134 0 $params[RETT] = 2; # return type should be a hash reference of positioned scores
1135 0 $params[DB] = $ddb;
1136 0 $params[DATA] = $args->{dataset};
1137  
1138 # collect scores
1139 0 my $exon_scores = get_segment_score(@params);
1140  
1141 # adjust the scores
1142 0 $adjustment = $params[STRT] - $current_end;
1143 $self->_process_exon_scores(
1144 $exon_scores, $pos2data, $adjustment, $params[STRT],
1145 $params[STOP], $namecheck, $args->{method}
1146 0 );
1147  
1148 # reset
1149 0 $current_end += $exon->length;
1150 }
1151  
1152 # collect extensions if requested
1153 0 ▶ if ( $args->{extend} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"extend"}) 0 0 0
1154  
1155 # left side
1156 0 my @params; # parameters to pass on to adapter
1157 0 $params[CHR] = $self->seq_id;
1158 0 $params[STRT] = $practical_start - $args->{extend};
1159 0 $params[STOP] = $practical_start - 1;
1160 0 $params[STR] = $fstrand;
1161 0 $params[STND] = $args->{strandedness};
1162 0 $params[METH] = $args->{method};
1163 0 $params[RETT] = 2; # return type should be a hash reference of positioned scores
1164 0 $params[DB] = $ddb;
1165 0 $params[DATA] = $args->{dataset};
1166  
1167 0 my $ext_scores = get_segment_score(@params);
1168  
1169 # no adjustment should be needed
1170 $self->_process_exon_scores( $ext_scores, $pos2data, 0, $params[STRT],
1171 0 $params[STOP], $namecheck, $args->{method} );
1172  
1173 # right side
1174 # we can reuse our parameter array
1175 0 $params[STRT] = $practical_stop + 1;
1176 0 $params[STOP] = $practical_stop + $args->{extend};
1177 0 $ext_scores = get_segment_score(@params);
1178  
1179 # the adjustment should be the same as the last exon
1180 $self->_process_exon_scores(
1181 $ext_scores, $pos2data, $adjustment, $params[STRT],
1182 $params[STOP], $namecheck, $args->{method}
1183 0 );
1184 }
1185  
1186 # covert to relative positions
1187 0 ▶ if ( $args->{absolute} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'absolute'}) { } 0 0 0
1188 0 ▶ return wantarray ? %{$pos2data} : $pos2data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1189 }
1190 else {
1191 # return data converted to relative positions
1192 # can no longer use original coordinates, but instead the new shifted coordinates
1193 0 $args->{practical_start} = $practical_start;
1194 0 $args->{practical_stop} = $current_end;
1195 0 my $reference = $self->calculate_reference($args);
1196 0 return $self->_convert_to_relative_positions( $pos2data, $reference, $fstrand );
1197 }
1198 }
1199  
1200 10 ▶sub calculate_reference {
Subroutine calculate_reference: called CC=16 SCAR=31.8
Pod documented
1201  
1202 # my ($self, $args) = @_;
1203 # I need position
1204 # optionally alternate start, stop, and/or strand
1205 10 my $self = shift;
1206 10 my $args;
1207 10 ▶ if ( scalar @_ == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 10 0 10
1208  
1209 # single variable passed
1210 10 ▶ if ( ref( $_[0] ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 6 4 10
1211 6 $args = shift @_;
1212 }
1213 else {
1214 # assumed to be the position
1215 4 $args = { position => $_[0] };
1216 }
1217 }
1218 else {
1219 # multiple variables
1220 0 $args = {@_};
1221 }
1222  
1223 # calculate reference coordinate
1224 10 my $coordinate;
1225 10 ▶ my $strand = defined $args->{strand} ? $args->{strand} : $self->strand;
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'strand'} ? : 0 10 10
1226 10 ▶ if ( $args->{position} == 5 ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($args->{'position'} == 5) { } 6 4 10
elsif ($args->{'position'} == 3) { } 1 3 4
elsif ($args->{'position'} == 4) { } 2 1 3
elsif ($args->{'position'} == 10 or $args->{'position'} == 9) { } 1 0 1
1227 6 ▶ if ( $strand >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strand >= 0) { } 1 5 6
1228 1 ▶ $coordinate = $args->{practical_start} || $self->start;
Condition33%1/3
$args->{'practical_start'} || $self->start
l!l&&r!l&&!r
010
MC/DC0%0/2
$args->{'practical_start'} || $self->start
$args->{'practical_start'} $self->start
Truth table33%1/3
A || B
A= $args->{'practical_start'}B= $self->start
ABresult
1X1
011
000
1229 }
1230 else {
1231 5 ▶ $coordinate = $args->{practical_stop} || $self->end;
Condition33%1/3
$args->{'practical_stop'} || $self->end
l!l&&r!l&&!r
050
MC/DC0%0/2
$args->{'practical_stop'} || $self->end
$args->{'practical_stop'} $self->end
Truth table33%1/3
A || B
A= $args->{'practical_stop'}B= $self->end
ABresult
1X1
011
000
1232 }
1233 }
1234 elsif ( $args->{position} == 3 ) {
1235 1 ▶ if ( $strand >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strand >= 0) { } 1 0 1
1236 1 ▶ $coordinate = $args->{practical_stop} || $self->end;
Condition33%1/3
$args->{'practical_stop'} || $self->end
l!l&&r!l&&!r
010
MC/DC0%0/2
$args->{'practical_stop'} || $self->end
$args->{'practical_stop'} $self->end
Truth table33%1/3
A || B
A= $args->{'practical_stop'}B= $self->end
ABresult
1X1
011
000
1237 }
1238 else {
1239 0 ▶ $coordinate = $args->{practical_start} || $self->start;
Condition0%0/3
$args->{'practical_start'} || $self->start
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'practical_start'} || $self->start
$args->{'practical_start'} $self->start
Truth table0%0/3
A || B
A= $args->{'practical_start'}B= $self->start
ABresult
1X1
011
000
1240 }
1241 }
1242 elsif ( $args->{position} == 4 ) {
1243  
1244 # strand doesn't matter here
1245 # but practical coordinates do
1246 2 ▶ if ( exists $args->{practical_start} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{'practical_start'}) { } 1 1 2
1247 $coordinate =
1248 1 int( ( ( $args->{practical_start} + $args->{practical_stop} ) / 2 ) +
1249 0.5 );
1250 }
1251 else {
1252 1 $coordinate = $self->midpoint;
1253 }
1254 }
1255 ▶ elsif ( $args->{position} == 10 or $args->{position} == 9 ) {
Condition33%1/3
$args->{"position"} == 10 or $args->{"position"} == 9
l!l&&r!l&&!r
010
MC/DC0%0/2
$args->{"position"} == 10 or $args->{"position"} == 9
$args->{"position"} == 10 $args->{"position"} == 9
Truth table33%1/3
A or B
A= $args->{"position"} == 10B= $args->{"position"} == 9
ABresult
1X1
011
000
1256  
1257 # also accept old 0-based index of 9 for narrowPeak
1258 1 $coordinate = $self->peak;
1259 }
1260 else {
1261 0 confess 'FATAL: position must be one of 5, 3, 4, or 10';
1262 }
1263 10 return $coordinate;
1264 }
1265  
1266 0 ▶sub _avoid_positions {
Subroutine _avoid_positions: not called CC=12 SCAR=50.5
1267 0 my ( $self, $pos2data, $args, $seqid, $start, $stop ) = @_;
1268  
1269 # first check the list of avoid types
1270 0 ▶ if ( ref( $args->{avoid} ) eq 'ARRAY' ) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $args->{'avoid'} eq 'ARRAY') { } 0 0 0
elsif ($args->{'avoid'} eq '1') { } 0 0 0
elsif ($args->{'avoid'} =~ /w+/i) { } 0 0 0
1271  
1272 # we have types, presume they're ok
1273 }
1274 elsif ( $args->{avoid} eq '1' ) {
1275  
1276 # old style boolean value
1277 0 ▶ if ( defined $args->{type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{'type'}) { } 0 0 0
1278 0 $args->{avoid} = [ $args->{type} ];
1279 }
1280 else {
1281 # no type provided, we can't avoid that which is not defined!
1282 # this is an error, but won't complain as we never did before
1283 0 $args->{avoid} = $self->type;
1284 }
1285 }
1286 elsif ( $args->{avoid} =~ /w+/i ) {
1287  
1288 # someone passed a string, a feature type perhaps?
1289 0 $args->{avoid} = [ $args->{avoid} ];
1290 }
1291  
1292 ### Check for conflicting features
1293 0 ▶ my $db = $args->{db} || $self->{data}->open_meta_database;
Condition0%0/3
$args->{'db'} || $self->{'data'}->open_meta_database
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'db'} || $self->{'data'}->open_meta_database
$args->{'db'} $self->{'data'}->open_meta_database
Truth table0%0/3
A || B
A= $args->{'db'}B= $self->{'data'}->open_meta_database
ABresult
1X1
011
000
1294 my @overlap_features = $self->get_features(
1295 seq_id => $seqid,
1296 start => $start,
1297 end => $stop,
1298 type => $args->{avoid},
1299 0 );
1300  
1301 # get the overlapping features of the same type
1302 0 ▶ if (@overlap_features) {
Branch: 1 branch
BranchTrueFalseTotal
if (@overlap_features) 0 0 0
1303 0 my $primary = $self->primary_id;
1304  
1305 # there are one or more feature of the type in this region
1306 # one of them is likely the one we're working with
1307 # but not necessarily - user may be looking outside original feature
1308 # the others are not what we want and therefore need to be
1309 # avoided
1310 0 foreach my $feat (@overlap_features) {
1311  
1312 # skip the one we want
1313 0 ▶ next if ( $feat->primary_id eq $primary );
Branch: 1 branch
BranchTrueFalseTotal
if $feat->primary_id eq $primary 0 0 0
1314  
1315 # now eliminate those scores which overlap this feature
1316 0 my $f_start = $feat->start;
1317 0 my $f_stop = $feat->end;
1318 0 foreach my $position ( keys %{$pos2data} ) {
1319  
1320 # delete the scored position if it overlaps with
1321 # the offending feature
1322 0 ▶ if ( $position >= $f_start
Branch: 1 branch
BranchTrueFalseTotal
if ($position >= $f_start and $position <= $f_stop) 0 0 0
Condition0%0/3
$position >= $f_start and $position <= $f_stop
!ll&&!rl&&r
000
MC/DC0%0/2
$position >= $f_start and $position <= $f_stop
$position >= $f_start $position <= $f_stop
Truth table0%0/3
A and B
A= $position >= $f_startB= $position <= $f_stop
ABresult
0X0
100
111
1323 and $position <= $f_stop )
1324 {
1325 0 delete $pos2data->{$position};
1326 }
1327 }
1328 }
1329 }
1330 }
1331  
1332 5 ▶sub _convert_to_relative_positions {
Subroutine _convert_to_relative_positions: called CC=6 SCAR=20.7
1333 5 my ( $self, $pos2data, $position, $strand ) = @_;
1334  
1335 5 my %relative_pos2data;
1336 5 ▶ if ( $strand >= 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($strand >= 0) { } 0 5 5
elsif ($strand < 0) { } 5 0 5
1337 0 foreach my $p ( keys %{$pos2data} ) {
1338 0 $relative_pos2data{ $p - $position } = $pos2data->{$p};
1339 }
1340 }
1341 elsif ( $strand < 0 ) {
1342 5 foreach my $p ( keys %{$pos2data} ) {
1343 223 $relative_pos2data{ $position - $p } = $pos2data->{$p};
1344 }
1345 }
1346 5 ▶ return wantarray ? %relative_pos2data : \%relative_pos2data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 0 5
1347 }
1348  
1349 0 ▶sub _process_exon_scores {
Subroutine _process_exon_scores: not called CC=11 SCAR=48.8
1350 0 my ( $self, $exon_scores, $pos2data, $adjustment, $start, $end, $namecheck, $method )
1351 = @_;
1352  
1353 # ncount method
1354 0 ▶ if ( $method eq 'ncount' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq 'ncount') { } 0 0 0
1355  
1356 # we need to check both names and adjust position
1357 0 foreach my $p ( keys %{$exon_scores} ) {
1358 0 ▶ next unless ( $p >= $start and $p <= $end );
Branch: 1 branch
BranchTrueFalseTotal
unless $p >= $start and $p <= $end 0 0 0
Condition0%0/3
$p >= $start and $p <= $end
!ll&&!rl&&r
000
MC/DC0%0/2
$p >= $start and $p <= $end
$p >= $start $p <= $end
Truth table0%0/3
A and B
A= $p >= $startB= $p <= $end
ABresult
0X0
100
111
1359 0 foreach my $n ( @{ $exon_scores->{$p} } ) {
1360 0 ▶ if ( exists $namecheck->{$n} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $namecheck->{$n}) { } 0 0 0
1361 0 $namecheck->{$n}++;
1362 0 next;
1363 }
1364 else {
1365 0 $namecheck->{$n} = 1;
1366 0 my $a = $p - $adjustment;
1367 0 ▶ $pos2data->{$a} ||= [];
Condition0%0/2
$pos2data->{$a} ||= []
l!l
00
MC/DC0%0/1
$pos2data->{$a} ||= []
$pos2data->{$a}
Truth table0%0/2
A
A= $pos2data->{$a}
Aresult
11
00
1368 0 push @{ $pos2data->{$a} }, $n;
1369 }
1370 }
1371 }
1372 }
1373 else {
1374 # just adjust scores
1375 0 foreach my $p ( keys %{$exon_scores} ) {
1376 0 ▶ next unless ( $p >= $start and $p <= $end );
Branch: 1 branch
BranchTrueFalseTotal
unless $p >= $start and $p <= $end 0 0 0
Condition0%0/3
$p >= $start and $p <= $end
!ll&&!rl&&r
000
MC/DC0%0/2
$p >= $start and $p <= $end
$p >= $start $p <= $end
Truth table0%0/3
A and B
A= $p >= $startB= $p <= $end
ABresult
0X0
100
111
1377 0 $pos2data->{ $p - $adjustment } = $exon_scores->{$p};
1378 }
1379 }
1380 }
1381  
1382 0 ▶sub fetch_alignments {
Subroutine fetch_alignments: not called CC=22 SCAR=62.3
Pod documented
1383 0 my $self = shift;
1384 0 my %args = @_;
1385 0 ▶ $args{db} ||= $args{dataset} || undef;
Condition0%0/5
$args{"db"} ||= $args{"dataset"} || undef
l!l&&r!l&&!r
000
$args{'dataset'} || undef
l!l
00
MC/DC0%0/2
$args{"db"} ||= $args{"dataset"} || undef
$args{"db"} $args{'dataset'}
Truth table0%0/3
A ||= B
A= $args{"db"}B= $args{'dataset'}
ABresult
1X1
011
000
1386 0 ▶ $args{data} ||= undef;
Condition0%0/2
$args{"data"} ||= undef
l!l
00
MC/DC0%0/1
$args{"data"} ||= undef
$args{"data"}
Truth table0%0/2
A
A= $args{"data"}
Aresult
11
00
1387 0 ▶ $args{callback} ||= undef;
Condition0%0/2
$args{"callback"} ||= undef
l!l
00
MC/DC0%0/1
$args{"callback"} ||= undef
$args{"callback"}
Truth table0%0/2
A
A= $args{"callback"}
Aresult
11
00
1388 0 ▶ $args{subfeature} ||= q();
Condition0%0/2
$args{"subfeature"} ||= ""
l!l
00
MC/DC0%0/1
$args{"subfeature"} ||= ""
$args{"subfeature"}
Truth table0%0/2
A
A= $args{"subfeature"}
Aresult
11
00
1389  
1390 # verify - trusting that these are valid, else they will fail lower down in the code
1391 0 ▶ unless ( $args{db} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"db"}) 0 0 0
1392 0 croak 'FATAL: must provide a Bam object database to fetch alignments!';
1393 }
1394 0 ▶ unless ( $args{data} and ref( $args{data} ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"data"} and ref $args{"data"} eq "HASH") 0 0 0
Condition0%0/3
$args{"data"} and ref $args{"data"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"data"} and ref $args{"data"} eq "HASH"
$args{"data"} ref $args{"data"} eq "HASH"
Truth table0%0/3
A and B
A= $args{"data"}B= ref $args{"data"} eq "HASH"
ABresult
0X0
100
111
1395 0 croak 'FATAL: must provide a data HASH for the fetch callback!';
1396 }
1397 0 ▶ unless ( $args{callback} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"callback"}) 0 0 0
1398 0 croak 'FATAL: must provide a callback code reference!';
1399 }
1400  
1401 # array of features to iterate, probably just one or subfeatures
1402 0 my @intervals;
1403 0 ▶ if ( $self->feature_type eq 'named' and $args{subfeature} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->feature_type eq 'named' and $args{'subfeature'}) { } 0 0 0
Condition0%0/3
$self->feature_type eq "named" and $args{"subfeature"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->feature_type eq "named" and $args{"subfeature"}
$self->feature_type eq "named" $args{"subfeature"}
Truth table0%0/3
A and B
A= $self->feature_type eq "named"B= $args{"subfeature"}
ABresult
0X0
100
111
1404  
1405 # we have subfeatures to iterate over
1406  
1407 # get the subfeatures
1408 0 my $subfeatures = $self->_get_subfeatures( $args{subfeature} );
1409 0 ▶ if ( @{$subfeatures} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$subfeatures;}) { } 0 0 0
1410 0 foreach my $sf ( @{$subfeatures} ) {
1411 0 push @intervals, [ $sf->start - 1, $sf->end ];
1412 }
1413 }
1414 else {
1415 # zere subfeatures? just take the parent then
1416 push @intervals,
1417 [
1418 ( $args{start} || $self->start ) - 1,
1419 0 ▶ $args{stop} || $args{end} || $self->end
Condition0%0/9
$args{'start'} || $self->start
l!l&&r!l&&!r
000
$args{'stop'} || $args{'end'} || $self->end
l!l&&r!l&&!r
000
$args{"stop"} or $args{"end"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'start'} || $self->start
$args{'start'} $self->start
MC/DC0%0/3
$args{'stop'} || $args{'end'} || $self->end
$args{"stop"} $args{"end"} $self->end
Truth table0%0/3
A || B
A= $args{'start'}B= $self->start
ABresult
1X1
011
000
Truth table0%0/4
A or B || C
A= $args{"stop"}B= $args{"end"}C= $self->end
ABCresult
1XX1
01X1
0011
0000
1420 ];
1421 }
1422 }
1423 else {
1424 # take feature as is
1425 push @intervals,
1426 [
1427 ( $args{start} || $self->start ) - 1,
1428 0 ▶ $args{stop} || $args{end} || $self->end
Condition0%0/9
$args{'start'} || $self->start
l!l&&r!l&&!r
000
$args{'stop'} || $args{'end'} || $self->end
l!l&&r!l&&!r
000
$args{"stop"} or $args{"end"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'start'} || $self->start
$args{'start'} $self->start
MC/DC0%0/3
$args{'stop'} || $args{'end'} || $self->end
$args{"stop"} $args{"end"} $self->end
Truth table0%0/3
A || B
A= $args{'start'}B= $self->start
ABresult
1X1
011
000
Truth table0%0/4
A or B || C
A= $args{"stop"}B= $args{"end"}C= $self->end
ABCresult
1XX1
01X1
0011
0000
1429 ];
1430 }
1431  
1432 # get the target id for the chromosome
1433 # this will fail if the user didn't provide a real bam object!!!
1434 0 my ( $tid, undef, undef ) = $args{db}->header->parse_region( $self->seq_id );
1435 0 ▶ return unless defined $tid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tid 0 0 0
1436  
1437 # now iterate over the intervals
1438 0 foreach my $i (@intervals) {
1439 0 $args{data}->{start} = $i->[0];
1440 0 $args{data}->{end} = $i->[1];
1441 0 $args{data}->{strand} = $self->strand;
1442 low_level_bam_fetch( $args{db}, $tid, $i->[0], $i->[1], $args{callback},
1443 0 $args{data} );
1444 }
1445  
1446 # nothing to return since we're using a data reference
1447 0 return 1;
1448 }
1449  
1450 ### String export
1451  
1452 0 ▶sub bed_string {
Subroutine bed_string: not called CC=26 SCAR=65.5
Pod documented
1453 0 my $self = shift;
1454 0 my %args = @_;
1455 0 ▶ $args{bed} ||= 6; # number of bed columns
Condition0%0/2
$args{"bed"} ||= 6
l!l
00
MC/DC0%0/1
$args{"bed"} ||= 6
$args{"bed"}
Truth table0%0/2
A
A= $args{"bed"}
Aresult
11
00
1456 0 ▶ croak 'FATAL: bed count must be an integer!' unless $args{bed} =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"bed"} =~ /^\d+$/ 0 0 0
1457 0 ▶ croak 'FATAL: bed count must be at least 3!' unless $args{bed} >= 3;
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"bed"} >= 3 0 0 0
1458  
1459 # coordinate information
1460 0 $self->seqfeature; # retrieve the seqfeature object first
1461 0 ▶ my $chr = $args{chromo} || $args{seq_id} || $self->seq_id;
Condition0%0/6
$args{'chromo'} || $args{'seq_id'} || $self->seq_id
l!l&&r!l&&!r
000
$args{"chromo"} or $args{"seq_id"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{'chromo'} || $args{'seq_id'} || $self->seq_id
$args{"chromo"} $args{"seq_id"} $self->seq_id
Truth table0%0/4
A or B || C
A= $args{"chromo"}B= $args{"seq_id"}C= $self->seq_id
ABCresult
1XX1
01X1
0011
0000
1462 0 ▶ my $start = $args{start} || $self->start;
Condition0%0/3
$args{'start'} || $self->start
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'start'} || $self->start
$args{'start'} $self->start
Truth table0%0/3
A || B
A= $args{'start'}B= $self->start
ABresult
1X1
011
000
1463 my $stop =
1464 $args{stop}
1465 || $args{end}
1466 0 ▶ || $self->stop
Condition0%0/12
$args{'stop'} || $args{'end'} || $self->stop || $start + $self->length - 1 || $start
l!l&&r!l&&!r
000
$args{"stop"} or $args{"end"} or $self->stop or $start + $self->length - 1
l!l&&r!l&&!r
000
$args{"stop"} or $args{"end"} or $self->stop
l!l&&r!l&&!r
000
$args{"stop"} or $args{"end"}
l!l&&r!l&&!r
000
MC/DC0%0/5
$args{'stop'} || $args{'end'} || $self->stop || $start + $self->length - 1 || $start
$args{"stop"} $args{"end"} $self->stop $start + $self->length - 1 $start
Truth table0%0/6
A or B or C or D || E
A= $args{"stop"}B= $args{"end"}C= $self->stopD= $start + $self->length - 1E= $start
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1467 || $start + $self->length - 1
1468 || $start;
1469 0 ▶ if ( $chr eq '.'
Branch: 1 branch
BranchTrueFalseTotal
if ($chr eq "." or not CORE::length $chr or $start eq "." or not CORE::length $start) 0 0 0
Condition0%0/9
$chr eq "." or not CORE::length $chr or $start eq "." or not CORE::length $start
l!l&&r!l&&!r
000
$chr eq "." or not CORE::length $chr or $start eq "."
l!l&&r!l&&!r
000
$chr eq "." or not CORE::length $chr
l!l&&r!l&&!r
000
MC/DC0%0/4
$chr eq "." or not CORE::length $chr or $start eq "." or not CORE::length $start
$chr eq "." not CORE::length $chr $start eq "." not CORE::length $start
Truth table0%0/5
A or not(B) or C or not(D)
A= $chr eq "."B= not CORE::length $chrC= $start eq "."D= not CORE::length $start
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1470 or not CORE::length($chr)
1471 or $start eq '.'
1472 or not CORE::length($start) )
1473 {
1474 0 carp sprintf( "ERROR: no valid seq_id or start for data line %d",
1475 $self->line_number );
1476 0 return;
1477 }
1478 0 ▶ if ( $start > $stop ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start > $stop) 0 0 0
1479  
1480 # reversed coordinates? old school way of setting reverse strand
1481 0 my $s = $start;
1482 0 $start = $stop;
1483 0 $stop = $s;
1484 0 $args{strand} = -1; # this will override any user provided data?
1485 }
1486 0 $start -= 1; # 0-based coordinates
1487 0 my $string = "$chr\t$start\t$stop";
1488  
1489 # additional information
1490 0 ▶ if ( $args{bed} >= 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"bed"} >= 4) 0 0 0
1491 0 ▶ my $name = $args{name} || $self->name || 'Feature_' . $self->line_number;
Condition0%0/5
$args{'name'} || $self->name || 'Feature_' . $self->line_number
l!l
00
$args{"name"} or $self->name
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'name'} || $self->name || 'Feature_' . $self->line_number
$args{"name"} $self->name
Truth table0%0/3
A or B
A= $args{"name"}B= $self->name
ABresult
1X1
011
000
1492 0 $string .= "\t$name";
1493 }
1494 0 ▶ if ( $args{bed} >= 5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"bed"} >= 5) 0 0 0
1495 0 ▶ my $score = exists $args{score} ? $args{score} : $self->score;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'score'} ? : 0 0 0
1496 0 ▶ $score = 1 unless defined $score;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $score 0 0 0
1497 0 $string .= "\t$score";
1498 }
1499 0 ▶ if ( $args{bed} >= 6 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"bed"} >= 6) 0 0 0
1500 0 my $s;
1501 0 ▶ if ( exists $args{strand} and defined $args{strand} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'strand'} and defined $args{'strand'}) { } 0 0 0
Condition0%0/3
exists $args{"strand"} and defined $args{"strand"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args{"strand"} and defined $args{"strand"}
exists $args{"strand"} defined $args{"strand"}
Truth table0%0/3
A and B
A= exists $args{"strand"}B= defined $args{"strand"}
ABresult
0X0
100
111
1502 0 $s = $self->_strand( $args{strand} );
1503 }
1504 else {
1505 0 $s = $self->strand;
1506 }
1507 0 ▶ $string .= sprintf( "\t%s", $s == -1 ? '-' : '+' );
Branch: 1 branch
BranchTrueFalseTotal
$s == -1 ? : 0 0 0
1508 }
1509  
1510 # we could go on with other columns, but there's no guarantee that additional
1511 # information is available, and we would have to implement user provided data
1512  
1513 # done
1514 0 return $string;
1515 }
1516  
1517 0 ▶sub gff_string {
Subroutine gff_string: not called CC=34 SCAR=70.8
Pod documented
1518 0 my $self = shift;
1519 0 my %args = @_;
1520  
1521 # coordinate information
1522 0 $self->seqfeature; # retrieve the seqfeature object first
1523 0 ▶ my $chr = $args{chromo} || $args{seq_id} || $self->seq_id;
Condition0%0/6
$args{'chromo'} || $args{'seq_id'} || $self->seq_id
l!l&&r!l&&!r
000
$args{"chromo"} or $args{"seq_id"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{'chromo'} || $args{'seq_id'} || $self->seq_id
$args{"chromo"} $args{"seq_id"} $self->seq_id
Truth table0%0/4
A or B || C
A= $args{"chromo"}B= $args{"seq_id"}C= $self->seq_id
ABCresult
1XX1
01X1
0011
0000
1524 0 ▶ my $start = $args{start} || $self->start;
Condition0%0/3
$args{'start'} || $self->start
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'start'} || $self->start
$args{'start'} $self->start
Truth table0%0/3
A || B
A= $args{'start'}B= $self->start
ABresult
1X1
011
000
1525 my $stop =
1526 $args{stop}
1527 || $args{end}
1528 0 ▶ || $self->stop
Condition0%0/12
$args{'stop'} || $args{'end'} || $self->stop || $start + $self->length - 1 || $start
l!l&&r!l&&!r
000
$args{"stop"} or $args{"end"} or $self->stop or $start + $self->length - 1
l!l&&r!l&&!r
000
$args{"stop"} or $args{"end"} or $self->stop
l!l&&r!l&&!r
000
$args{"stop"} or $args{"end"}
l!l&&r!l&&!r
000
MC/DC0%0/5
$args{'stop'} || $args{'end'} || $self->stop || $start + $self->length - 1 || $start
$args{"stop"} $args{"end"} $self->stop $start + $self->length - 1 $start
Truth table0%0/6
A or B or C or D || E
A= $args{"stop"}B= $args{"end"}C= $self->stopD= $start + $self->length - 1E= $start
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1529 || $start + $self->length - 1
1530 || $start;
1531 0 ▶ if ( $chr eq '.'
Branch: 1 branch
BranchTrueFalseTotal
if ($chr eq "." or not CORE::length $chr or $start eq "." or not CORE::length $start) 0 0 0
Condition0%0/9
$chr eq "." or not CORE::length $chr or $start eq "." or not CORE::length $start
l!l&&r!l&&!r
000
$chr eq "." or not CORE::length $chr or $start eq "."
l!l&&r!l&&!r
000
$chr eq "." or not CORE::length $chr
l!l&&r!l&&!r
000
MC/DC0%0/4
$chr eq "." or not CORE::length $chr or $start eq "." or not CORE::length $start
$chr eq "." not CORE::length $chr $start eq "." not CORE::length $start
Truth table0%0/5
A or not(B) or C or not(D)
A= $chr eq "."B= not CORE::length $chrC= $start eq "."D= not CORE::length $start
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1532 or not CORE::length($chr)
1533 or $start eq '.'
1534 or not CORE::length($start) )
1535 {
1536 0 carp sprintf( "ERROR: no valid seq_id or start for data line %d",
1537 $self->line_number );
1538 0 return;
1539 }
1540 0 ▶ if ( $start > $stop ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start > $stop) 0 0 0
1541  
1542 # reversed coordinates? old school way of setting reverse strand
1543 0 my $s = $start;
1544 0 $start = $stop;
1545 0 $stop = $s;
1546 0 $args{strand} = -1; # this will override any user provided data?
1547 }
1548 0 my $strand;
1549 0 ▶ if ( exists $args{strand} and defined $args{strand} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'strand'} and defined $args{'strand'}) { } 0 0 0
Condition0%0/3
exists $args{"strand"} and defined $args{"strand"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args{"strand"} and defined $args{"strand"}
exists $args{"strand"} defined $args{"strand"}
Truth table0%0/3
A and B
A= exists $args{"strand"}B= defined $args{"strand"}
ABresult
0X0
100
111
1550 0 $strand = $self->_strand( $args{strand} );
1551 }
1552 else {
1553 0 $strand = $self->strand;
1554 }
1555 0 ▶ $strand = $strand == -1 ? '-' : $strand == 1 ? '+' : '.';
Branch: 2 branches
BranchTrueFalseTotal
$strand == -1 ? : 0 0 0
$strand == 1 ? : 0 0 0
1556  
1557 # type information
1558 0 ▶ my $type = $args{type} || $self->type || undef;
Condition0%0/5
$args{'type'} || $self->type || undef
l!l
00
$args{"type"} or $self->type
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'type'} || $self->type || undef
$args{"type"} $self->type
Truth table0%0/3
A or B
A= $args{"type"}B= $self->type
ABresult
1X1
011
000
1559 0 my ( $source, $primary_tag );
1560 0 ▶ if ( defined $type and $type =~ /:/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type and $type =~ /:/) 0 0 0
Condition0%0/3
defined $type and $type =~ /:/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $type and $type =~ /:/
defined $type $type =~ /:/
Truth table0%0/3
A and B
A= defined $typeB= $type =~ /:/
ABresult
0X0
100
111
1561 0 ( $primary_tag, $source ) = split /:/, $type;
1562 }
1563 0 ▶ unless ($source) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($source) 0 0 0
1564 0 ▶ $source = $args{source} || '.';
Condition0%0/2
$args{'source'} || '.'
l!l
00
MC/DC0%0/1
$args{'source'} || '.'
$args{'source'}
Truth table0%0/2
A
A= $args{'source'}
Aresult
11
00
1565 }
1566 0 ▶ unless ($primary_tag) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($primary_tag) 0 0 0
1567 0 ▶ $primary_tag = $args{primary_tag} || defined $type ? $type : '.';
Branch: 1 branch
BranchTrueFalseTotal
$args{'primary_tag'} || defined $type ? : 0 0 0
Condition0%0/3
$args{"primary_tag"} or defined $type
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"primary_tag"} or defined $type
$args{"primary_tag"} defined $type
Truth table0%0/3
A or B
A= $args{"primary_tag"}B= defined $type
ABresult
1X1
011
000
1568 }
1569  
1570 # score
1571 0 ▶ my $score = exists $args{score} ? $args{score} : $self->score;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'score'} ? : 0 0 0
1572 0 ▶ $score = '.' unless defined $score;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $score 0 0 0
1573 0 my $phase = '.'; # do not even bother!!!!
1574  
1575 # attributes
1576 0 ▶ my $name = $args{name} || $self->name || 'Feature_' . $self->line_number;
Condition0%0/5
$args{'name'} || $self->name || 'Feature_' . $self->line_number
l!l
00
$args{"name"} or $self->name
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'name'} || $self->name || 'Feature_' . $self->line_number
$args{"name"} $self->name
Truth table0%0/3
A or B
A= $args{"name"}B= $self->name
ABresult
1X1
011
000
1577 0 my $attributes = "Name=$name";
1578 0 ▶ my $id = $args{id} || sprintf( "%08d", $self->line_number );
Condition0%0/3
$args{'id'} || sprintf('%08d', $self->line_number)
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'id'} || sprintf('%08d', $self->line_number)
$args{'id'} sprintf('%08d', $self->line_number)
Truth table0%0/3
A || B
A= $args{'id'}B= sprintf('%08d', $self->line_number)
ABresult
1X1
011
000
1579 0 $attributes .= ";ID=$id";
1580 0 ▶ if ( exists $args{attributes} and ref( $args{attributes} ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"attributes"} and ref $args{"attributes"} eq "ARRAY") 0 0 0
Condition0%0/3
exists $args{"attributes"} and ref $args{"attributes"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args{"attributes"} and ref $args{"attributes"} eq "ARRAY"
exists $args{"attributes"} ref $args{"attributes"} eq "ARRAY"
Truth table0%0/3
A and B
A= exists $args{"attributes"}B= ref $args{"attributes"} eq "ARRAY"
ABresult
0X0
100
111
1581 0 foreach my $i ( @{ $args{attributes} } ) {
1582 0 my $k = $self->{data}->name($i);
1583 0 $k =~ s/( [\t\n\r%&\=;,\ ] ) /sprintf("%%%X",ord($1))/xge;
1584 0 my $v = $self->value($i);
1585 0 $v =~ s/( [\t\n\r%&\=;,\ ] ) /sprintf("%%%X",ord($1))/xge;
1586 0 $attributes .= ";$k=$v";
1587 }
1588 }
1589  
1590 # done
1591 0 my $string = join( "\t",
1592 $chr, $source, $primary_tag, $start, $stop,
1593 $score, $strand, $phase, $attributes );
1594 0 return $string;
1595 }
1596  
1597 4 1;
1598  
1599 __END__
« lib/Bio/ToolBox/db_helper/alignment_callbacks.pm ↑ Summary script/get_relative_data.pl »