lib/Bio/MUST/Core/Roles/Filterable.pm

filter: Statementstmt 93.2% 55 / 59 Branchbran 43.7% 7 / 16 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 11 / 11 Podpod 50.0% 1 / 2 totaltotal 84.9% 79 / 93 CC 12 SCAR 17.0
CC
12
Cov
83%
BUILD
10.7
score
6.0
BEGIN
1.0
CRAP 5.5
« lib/Bio/MUST/Core/SeqId.pm ↑ Summary lib/Bio/MUST/Core/PostPred/Composition.pm »
1 package Bio::MUST::Core::Roles::Filterable;
2 # ABSTRACT: Filterable Moose role for objects that behave as filters
3 18 $Bio::MUST::Core::Roles::Filterable::VERSION = '0.252040';
4 18 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 18 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 18 ▶use feature qw(say);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 18 ▶use Smart::Comments '###';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 18 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 18 ▶use Const::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 18 ▶use Bio::MUST::Core::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 18 ▶use Bio::MUST::Core::Constants qw(:seqids);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 18 requires 'is_allowed';
18  
19  
20 18 has '_specs' => (
21 is => 'ro',
22 isa => 'Bio::MUST::Core::IdList',
23 required => 1,
24 coerce => 1,
25 handles => {
26 all_specs => 'all_ids',
27 },
28 );
29  
30  
31 has '_is_' . $_ => (
32 traits => ['Hash'],
33 is => 'ro',
34 isa => 'HashRef',
35 init_arg => undef,
36 writer => '_set_is_' . $_,
37 handles => {
38 'all_' . $_ => 'keys',
39 'is_' . $_ => 'defined',
40 },
41 18 ) for qw(wanted unwanted);
42  
43  
44 # TODO: allow specifying taxa as partial lineages to solve ambiguities
45 # TODO: allow specifying taxa as taxid and/or mustids (for strains)
46  
47 # regexes for deriving filter from specifications
48 18 const my $WANTED => qr{\A \+ \s* (.*) }xms;
49 18 const my $UNWANTED => qr{\A \- \s* (.*) }xms;
50  
51 2 ▶sub BUILD {
Subroutine BUILD: called CC=7 SCAR=23.7
Pod undocumented
52 2 my $self = shift;
53  
54 # parse filter specifications
55 2 ▶ my @wanted = map { $_ =~ $WANTED ? $1 : () } $self->all_specs;
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /$WANTED/ ? : 2 0 2
56 2 ▶ my @unwanted = map { $_ =~ $UNWANTED ? $1 : () } $self->all_specs;
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /$UNWANTED/ ? : 0 2 2
57  
58 # only for tax_filters
59 2 ▶ if ( $self->can('tax') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("tax")) 0 2 2
60 #### TAXONOMIC FILTER
61  
62 # warn in case of ambiguous taxa
63 0 for my $taxon (@wanted, @unwanted) {
64 0 ▶ carp "[BMC] Warning: $taxon is taxonomically ambiguous in filter!"
Branch: 1 branch
BranchTrueFalseTotal
if $self->tax->is_dupe($taxon) 0 0 0
65 if $self->tax->is_dupe($taxon);
66 }
67  
68 # build filtering hashes from wanted and unwanted arrays
69 # Note: we want no virus by default but exclude nothing
70 0 ▶ push @wanted, 'cellular organisms' unless @wanted;
Branch: 1 branch
BranchTrueFalseTotal
unless @wanted 0 0 0
71 }
72  
73 2 my %is_wanted = map { $_ => 1 } @wanted;
74 0 my %is_unwanted = map { $_ => 1 } @unwanted;
75  
76 # store HashRefs for filter
77 2 $self->_set_is_wanted( \%is_wanted );
78 2 $self->_set_is_unwanted(\%is_unwanted);
79  
80 2 return;
81 }
82  
83  
84 2200 ▶sub score { ## no critic (RequireArgUnpacking)
Subroutine score: called CC=6 SCAR=18.0
Pod documented
85 2200 my $self = shift;
86 2200 my @seq_ids = @_;
87  
88 2200 my $seen;
89 2200 my $score = 0;
90  
91 2200 for my $seq_id (@seq_ids) {
92 #### s: $seq_id->full_id
93 303600 my $res = $self->is_allowed($seq_id);
94 #### $res
95  
96 # track if at least one id passed filter
97 303600 ▶ $seen ||= $res;
Condition100%3/3
$seen ||= $res
l!l&&r!l&&!r
283373164918578
MC/DC100%2/2
$seen ||= $res
$seen $res
Truth table100%3/3
A ||= B
A= $seenB= $res
ABresult
1X1
011
000
98  
99 # increment score: undef => 0 ; otherwise +1 / -1
100 303600 ▶ $score += !defined $res ? 0 : $res ? +1 : -1;
Branch: 2 branches
BranchTrueFalseTotal
!defined($res) ? : 0 303600 303600
$res ? : 151800 151800 303600
101 #### $score
102 }
103  
104 # further return seen flag in list context
105 2200 ▶ return wantarray ? ($score, $seen) : $score;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2200 0 2200
106 }
107  
108 18 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
109 18 1;
110  
111 __END__
« lib/Bio/MUST/Core/SeqId.pm ↑ Summary lib/Bio/MUST/Core/PostPred/Composition.pm »