| 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
Condition100%3/3
@included and @excluded
MC/DC100%2/2
@included and @excluded
@included
@excluded
Truth table100%3/3
A and B
A= @includedB= @excluded
| |||||||||||||||||||||||||||||
| 19 | if ( @included && @excluded ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # *** IMPORTANT *** | ||||||||||||||||||||||||||||
| 22 | # Original $hash is modified | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # INCLUDED | ||||||||||||||||||||||||||||
| 25 | 551 | ▶ | if (@included) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # EXCLUDED | ||||||||||||||||||||||||||||
| 32 | 551 | ▶ | if (@excluded) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 1 | for my $key (@excluded) { | |||||||||||||||||||||||||||
| 34 | 1 | ▶ | delete $hash->{$key} if exists $hash->{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # NB: remaining phenotypicFeatures:1.excluded | ||||||||||||||||||||||||||||
| 54 | # will be discarded by $exclude_variables_regex_qr later | ||||||||||||||||||||||||||||
| 55 | 540 | ▶ | if ($switch) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # Determine the correct ID field based on the format | ||||||||||||||||||||||||||||
| 58 | 2 | ▶ | my $id_field = $format eq 'BFF' ? 'featureType' : 'type'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 8 | 1; | |||||||||||||||||||||||||||