blib/lib/Bio/Gonzales/MiniFeat.pm

filter: Statementstmt 84.2% 91 / 108 Branchbran 75.0% 27 / 36 Conditioncond 72.2% 13 / 18 MC/DCmcdc 58.3% 7 / 12 Subroutinesub 75.7% 25 / 33 Podpod 0.0% 0 / 19 totaltotal 72.1% 163 / 226 CC 27 SCAR 15.0
CC
27
Cov
81%
del_attr
12.0
_attr_list
9.6
_attr_single
7.1
CRAP 4.5
« blib/lib/Bio/Gonzales/Util/Graphics/Color/Generator.pm ↑ Summary blib/script/blast2gff3.pl »
1 package Bio::Gonzales::MiniFeat;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use List::MoreUtils qw/zip/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Scalar::Util qw/refaddr/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 our $QUIET_MODE;
13  
14 4 our $VERSION = '0.062'; # VERSION
15  
16 4 has [qw/source type/] => ( is => 'rw', required => 1 );
17  
18 2 ▶has attributes => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
19  
20 450 ▶has [qw/subfeats parentfeats/] => ( is => 'rw', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
21  
22  
23  
24 77 ▶sub attr { return shift->attributes(@_); }
Subroutine attr: called CC=1 SCAR=0.0
Pod undocumented
25  
26 sub clone {
27 0 ▶ my ($self) = @_;
Subroutine clone: not called CC=2 SCAR=17.9
Pod undocumented
28  
29 0 my %data = %$self;
30 0 ▶ $data{attributes} = dclone( $data{attributes} ) if ( exists( $data{attributes} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $data{"attributes"} 0 0 0
31  
32 0 return __PACKAGE__->new( \%data );
33 }
34  
35 sub _attr_single {
36 195 ▶ my ( $self, $p ) = @_;
Subroutine _attr_single: called CC=7 SCAR=19.6
37 195 ▶ $p = { name => $p } unless ( ref $p );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $p 0 195 195
38  
39 195 ▶ confess "no attributes can be set with this method" if ( $p->{args} );
Branch: 1 branch
BranchTrueFalseTotal
if $p->{"args"} 0 195 195
40 return
41 195 ▶ unless ( exists( $self->attributes->{ $p->{name} } ) && @{ $self->attributes->{ $p->{name} } } > 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->attributes->{$p->{"name"}} and @{$self->attributes->{$p->{"name"}};} > 0 22 173 195
Condition66%2/3
exists $self->attributes->{$p->{"name"}} and @{$self->attributes->{$p->{"name"}};} > 0
!ll&&!rl&&r
220173
MC/DC50%1/2
exists $self->attributes->{$p->{"name"}} and @{$self->attributes->{$p->{"name"}};} > 0
exists $self->attributes->{$p->{"name"}} @{$self->attributes->{$p->{"name"}};} > 0
Truth table66%2/3
A and B
A= exists $self->attributes->{$p->{"name"}}B= @{$self->attributes->{$p->{"name"}};} > 0
ABresult
0X0
100
111
42 carp "multiple ID entries, taking the first"
43 173 ▶ if ( @{ $self->attributes->{ $p->{name} } } > 1 && !$p->{quiet} );
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->attributes->{$p->{"name"}};} > 1 and not $p->{"quiet"} 1 172 173
Condition100%3/3
@{$self->attributes->{$p->{"name"}};} > 1 and not $p->{"quiet"}
!ll&&!rl&&r
17021
MC/DC100%2/2
@{$self->attributes->{$p->{"name"}};} > 1 and not $p->{"quiet"}
@{$self->attributes->{$p->{"name"}};} > 1 not $p->{"quiet"}
Truth table100%3/3
A and not(B)
A= @{$self->attributes->{$p->{"name"}};} > 1B= not $p->{"quiet"}
ABresult
0X0
100
111
44 173 return $self->attributes->{ $p->{name} }[0];
45 }
46  
47 sub _attr_list {
48 143 ▶ my ( $self, $attr, @values ) = @_;
Subroutine _attr_list: called CC=9 SCAR=22.6
49  
50 return
51 143 ▶ unless ( exists( $self->attributes->{$attr} ) && @{ $self->attributes->{$attr} } > 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->attributes->{$attr} and @{$self->attributes->{$attr};} > 0 55 88 143
Condition66%2/3
exists $self->attributes->{$attr} and @{$self->attributes->{$attr};} > 0
!ll&&!rl&&r
55088
MC/DC50%1/2
exists $self->attributes->{$attr} and @{$self->attributes->{$attr};} > 0
exists $self->attributes->{$attr} @{$self->attributes->{$attr};} > 0
Truth table66%2/3
A and B
A= exists $self->attributes->{$attr}B= @{$self->attributes->{$attr};} > 0
ABresult
0X0
100
111
52  
53 88 ▶ return wantarray ? @{ $self->attributes->{$attr} } : $self->attributes->{$attr}
Branch: 2 branches
BranchTrueFalseTotal
unless @values and @values > 0 85 3 88
wantarray ? : 58 27 85
Condition66%2/3
@values and @values > 0
!ll&&!rl&&r
8503
MC/DC50%1/2
@values and @values > 0
@values @values > 0
Truth table66%2/3
A and B
A= @valuesB= @values > 0
ABresult
0X0
100
111
54 unless ( @values && @values > 0 );
55  
56 3 my $current_v = $self->attributes->{$attr};
57 3 my $new_v;
58 3 ▶ if ( @values == 1 && ref $values[0] eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@values == 1 and ref $values[0] eq 'ARRAY') { } 3 0 3
Condition33%1/3
@values == 1 and ref $values[0] eq "ARRAY"
!ll&&!rl&&r
003
MC/DC0%0/2
@values == 1 and ref $values[0] eq "ARRAY"
@values == 1 ref $values[0] eq "ARRAY"
Truth table33%1/3
A and B
A= @values == 1B= ref $values[0] eq "ARRAY"
ABresult
0X0
100
111
59 3 $self->attributes->{$attr} = $values[0];
60 } else {
61 0 $self->attributes->{$attr} = \@values;
62  
63 }
64 3 ▶ return wantarray ? @{$current_v} : $current_v;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 2 3
65 }
66  
67 sub first_attr {
68 26 ▶ my ( $self, $name ) = @_;
Subroutine first_attr: called CC=1 SCAR=0.0
Pod undocumented
69 26 return $self->_attr_single( { name => $name, quiet => 1 } );
70 }
71  
72 26 ▶sub attr_first { return shift->first_attr(@_); }
Subroutine attr_first: called CC=1 SCAR=0.0
Pod undocumented
73  
74 131 ▶sub id { return shift->_attr_single( { name => 'ID' } ); }
Subroutine id: called CC=1 SCAR=0.0
Pod undocumented
75  
76 86 ▶sub ids { return shift->_attr_list('ID', @_); }
Subroutine ids: called CC=1 SCAR=0.0
Pod undocumented
77  
78 0 ▶sub attr_list { return shift->_attr_list(shift); }
Subroutine attr_list: not called CC=1 SCAR=6.9
Pod undocumented
79  
80 38 ▶sub name { return shift->_attr_single( { name => 'Name' } ); }
Subroutine name: called CC=1 SCAR=0.0
Pod undocumented
81  
82 56 ▶sub parent_ids { return shift->_attr_list('Parent', @_); }
Subroutine parent_ids: called CC=1 SCAR=0.0
Pod undocumented
83  
84 0 ▶sub parent_id { return shift->_attr_single( { name => 'Parent' } ); }
Subroutine parent_id: not called CC=1 SCAR=6.9
Pod undocumented
85  
86 0 ▶sub attr_replace { return shift->replace_attr(@_) }
Subroutine attr_replace: not called CC=1 SCAR=6.9
Pod undocumented
87  
88 sub replace_attr {
89 1 ▶ my ( $self, $name, @values ) = @_;
Subroutine replace_attr: called CC=2 SCAR=7.1
Pod undocumented
90  
91 1 ▶ confess "name cannot be a reference" if(ref $name);
Branch: 1 branch
BranchTrueFalseTotal
if ref $name 0 1 1
92 1 return $self->_attr_list($name, \@values);
93 }
94  
95 sub parents {
96 0 ▶ confess 'use parent_ids';
Subroutine parents: not called CC=1 SCAR=6.9
Pod undocumented
97 }
98  
99 sub parent {
100 0 ▶ confess 'use parent_id';
Subroutine parent: not called CC=1 SCAR=6.9
Pod undocumented
101 }
102  
103 sub recurse_subfeats {
104 26 ▶ my ( $self, $sub ) = @_;
Subroutine recurse_subfeats: called CC=2 SCAR=7.0
Pod undocumented
105  
106 36 ▶ $sub = sub { return $_[0] }
Subroutine __ANON__: called CC=1 SCAR=0.0
107 26 ▶ unless defined $sub;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sub 26 0 26
108  
109 26 my %visited;
110 26 return $self->_recurse_subfeats( \%visited, $sub, 1 );
111  
112 }
113  
114 sub _recurse_subfeats {
115 62 ▶ my ( $self, $v, $sub, $depth ) = @_;
Subroutine _recurse_subfeats: called CC=5 SCAR=16.1
116  
117 62 ▶ if ( exists( $v->{ refaddr($self) } ) && $v->{ refaddr($self) } != $depth ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$v{builtin::refaddr($self)} and $$v{builtin::refaddr($self)} != $depth) 1 61 62
Condition100%3/3
exists $$v{builtin::refaddr($self)} and $$v{builtin::refaddr($self)} != $depth
!ll&&!rl&&r
5831
MC/DC100%2/2
exists $$v{builtin::refaddr($self)} and $$v{builtin::refaddr($self)} != $depth
exists $$v{builtin::refaddr($self)} $$v{builtin::refaddr($self)} != $depth
Truth table100%3/3
A and B
A= exists $$v{builtin::refaddr($self)}B= $$v{builtin::refaddr($self)} != $depth
ABresult
0X0
100
111
118 confess "Recursion in subfeature retrieval in level $depth/"
119 1 . $v->{ refaddr($self) } . "\n"
120 . Dumper $self;
121 }
122  
123 61 $v->{ refaddr($self) } = $depth;
124  
125 61 my @result;
126 61 ▶ if ( @{ $self->subfeats } > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->subfeats;} > 0) 11 50 61
127 11 $depth++;
128 11 for my $sf ( @{ $self->subfeats } ) {
129 36 push @result, $sub->( $sf, $depth );
130 36 push @result, $sf->_recurse_subfeats( $v, $sub, $depth );
131 }
132 }
133  
134 59 return @result;
135 }
136  
137 sub uniq {
138 56 ▶ my ($self) = @_;
Subroutine uniq: called CC=1 SCAR=0.0
Pod undocumented
139  
140 56 $self->subfeats( [ List::MoreUtils::uniq @{ $self->subfeats } ] );
141 56 $self->parentfeats( [ List::MoreUtils::uniq @{ $self->parentfeats } ] );
142 }
143  
144 sub add_attr {
145 440 ▶ my ( $self, %attrs ) = @_;
Subroutine add_attr: called CC=4 SCAR=13.9
Pod undocumented
146  
147 440 ▶ while ( my ( $name, $value ) = each %attrs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %attrs) 440 440 880
148 440 ▶ $self->attributes->{$name} = [] unless defined $self->attributes->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->attributes->{$name} 204 236 440
149 440 ▶ push @{ $self->attributes->{$name} }, ( ref $value eq 'ARRAY' ? @$value : $value );
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 49 391 440
150 }
151  
152 440 return;
153 }
154  
155 sub has_attr {
156 0 ▶ my ( $self, $name ) = @_;
Subroutine has_attr: not called CC=1 SCAR=6.9
Pod undocumented
157 0 return exists( $self->attributes->{$name} );
158 }
159  
160 sub del_attr {
161 0 ▶ my ( $self, @names ) = @_;
Subroutine del_attr: not called CC=3 SCAR=24.8
Pod undocumented
162  
163 0 my @deleted;
164 0 for my $name (@names) {
165 0 push @deleted, delete $self->attributes->{$name};
166 }
167 0 ▶ return @names == 1 ? $deleted[0] : \@deleted;
Branch: 1 branch
BranchTrueFalseTotal
@names == 1 ? : 0 0 0
168 }
169  
170 4 1;
« blib/lib/Bio/Gonzales/Util/Graphics/Color/Generator.pm ↑ Summary blib/script/blast2gff3.pl »