| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 195 | ▶ | confess "no attributes can be set with this method" if ( $p->{args} ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 40 | return | ||||||||||||||||||||||||||||||||
| 41 | 195 | ▶ | unless ( exists( $self->attributes->{ $p->{name} } ) && @{ $self->attributes->{ $p->{name} } } > 0 ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $self->attributes->{$p->{"name"}} and @{$self->attributes->{$p->{"name"}};} > 0
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
| |||||||||||||||||||||||||||||||||
| 42 | carp "multiple ID entries, taking the first" | ||||||||||||||||||||||||||||||||
| 43 | 173 | ▶ | if ( @{ $self->attributes->{ $p->{name} } } > 1 && !$p->{quiet} ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$self->attributes->{$p->{"name"}};} > 1 and not $p->{"quiet"}
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"}
| |||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $self->attributes->{$attr} and @{$self->attributes->{$attr};} > 0
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
| |||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 88 | ▶ | return wantarray ? @{ $self->attributes->{$attr} } : $self->attributes->{$attr} | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
@values and @values > 0
MC/DC50%1/2
@values and @values > 0
@values
@values > 0
Truth table66%2/3
A and B
A= @valuesB= @values > 0
| |||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
@values == 1 and ref $values[0] eq "ARRAY"
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"
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
exists $$v{builtin::refaddr($self)} and $$v{builtin::refaddr($self)} != $depth
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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 148 | 440 | ▶ | $self->attributes->{$name} = [] unless defined $self->attributes->{$name}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 149 | 440 | ▶ | push @{ $self->attributes->{$name} }, ( ref $value eq 'ARRAY' ? @$value : $value ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | 4 | 1; | |||||||||||||||||||||||||||||||