lib/Pheno/Ranker/Compare/Prune.pm

filter: Statementstmt 100% 42 / 42 Branchbran 90.0% 18 / 20 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 3 totaltotal 93.5% 73 / 78 CC 16 SCAR 17.4
CC
16
Cov
97%
prune_excluded_included
9.0
set_excluded_phenotypicFeatures
6.0
prune_keys_with_weight_zero
3.0
CRAP 5.7
« lib/Pheno/Ranker/Compare/Remap.pm ↑ Summary lib/Pheno/Ranker/Compare/Encoding.pm »
1 package Pheno::Ranker::Compare::Prune;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 our @EXPORT_OK =
10 qw(prune_excluded_included set_excluded_phenotypicFeatures prune_keys_with_weight_zero);
11  
12 552 ▶sub prune_excluded_included {
Subroutine prune_excluded_included: called CC=9 SCAR=22.0
Pod undocumented
13 552 my ( $hash, $self ) = @_;
14 552 my @included = @{ $self->{include_terms} };
15 552 my @excluded = @{ $self->{exclude_terms} };
16  
17 # Die if we have both options at the same time
18 552 ▶ die "Sorry, <--include> and <--exclude> are mutually exclusive\n"
Branch: 1 branch
BranchTrueFalseTotal
if @included and @excluded 1 551 552
Condition100%3/3
@included and @excluded
!ll&&!rl&&r
517341
MC/DC100%2/2
@included and @excluded
@included @excluded
Truth table100%3/3
A and B
A= @includedB= @excluded
ABresult
0X0
100
111
19 if ( @included && @excluded );
20  
21 # *** IMPORTANT ***
22 # Original $hash is modified
23  
24 # INCLUDED
25 551 ▶ if (@included) {
Branch: 1 branch
BranchTrueFalseTotal
if (@included) 34 517 551
26 34 for my $key ( keys %$hash ) {
27 150 ▶ delete $hash->{$key} unless any { $_ eq $key } @included;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless &any(sub { $_ eq $key; } , @included) 92 58 150
28 }
29 }
30  
31 # EXCLUDED
32 551 ▶ if (@excluded) {
Branch: 1 branch
BranchTrueFalseTotal
if (@excluded) 1 550 551
33 1 for my $key (@excluded) {
34 1 ▶ delete $hash->{$key} if exists $hash->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $hash->{$key} 1 0 1
35 }
36 }
37  
38 # We will do nothing if @included = @excluded = [] (DEFAULT)
39 551 return 1;
40 }
41  
42 548 ▶sub set_excluded_phenotypicFeatures {
Subroutine set_excluded_phenotypicFeatures: called CC=6 SCAR=17.9
Pod undocumented
43 548 my ( $hash, $switch, $format ) = @_;
44  
45 # Ensure phenotypicFeatures exist before processing
46 548 ▶ return 1 unless exists $hash->{phenotypicFeatures};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{"phenotypicFeatures"} 147 401 548
47  
48 401 foreach my $feature ( @{ $hash->{phenotypicFeatures} } ) {
49  
50 # Skip if 'excluded' is not set or false
51 963 ▶ next unless $feature->{excluded};
Branch: 1 branch
BranchTrueFalseTotal
unless $feature->{"excluded"} 423 540 963
52  
53 # NB: remaining phenotypicFeatures:1.excluded
54 # will be discarded by $exclude_variables_regex_qr later
55 540 ▶ if ($switch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($switch) { } 2 538 540
56  
57 # Determine the correct ID field based on the format
58 2 ▶ my $id_field = $format eq 'BFF' ? 'featureType' : 'type';
Branch: 1 branch
BranchTrueFalseTotal
$format eq 'BFF' ? : 0 2 2
59  
60 # Append '_excluded' to the appropriate ID
61 2 $feature->{$id_field}{id} .= '_excluded';
62 }
63 else {
64 # Remove the feature by setting it to undef
65 538 $feature = undef;
66  
67 # Due to properties being set to undef, it's possible for the coverage file to
68 # report phenotypicFeatures as 100% by all "excluded" = true
69 }
70 }
71  
72 401 return 1;
73 }
74  
75 97 ▶sub prune_keys_with_weight_zero {
Subroutine prune_keys_with_weight_zero: called CC=3 SCAR=11.0
Pod undocumented
76 97 my $hash_ref = shift;
77  
78 # Iterate over the keys of the hash
79 97 foreach my $key ( keys %{$hash_ref} ) {
80  
81 # Delete the key if its value is 0
82 5077 ▶ delete $hash_ref->{$key} if $hash_ref->{$key} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $hash_ref->{$key} == 0 20 5057 5077
83 }
84 }
85  
86 8 1;
« lib/Pheno/Ranker/Compare/Remap.pm ↑ Summary lib/Pheno/Ranker/Compare/Encoding.pm »