| 1 | package Pheno::Ranker::Compare::Remap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 Digest::SHA qw(sha1_hex); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Hash::Fold fold => { array_delimiter => ':' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use List::Util qw(first); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use Pheno::Ranker::Compare::Ontology qw(add_hpo_ascendants); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | use Pheno::Ranker::Compare::Prune | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | qw(prune_excluded_included set_excluded_phenotypicFeatures); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 8 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | our @EXPORT_OK = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | qw(remap_hash add_id2key guess_label normalize_nested_array_indexes remap_leaf_is_usable); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 549 | ▶ | sub remap_hash { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remap_hash: called CC=14 SCAR=26.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 549 | my $arg = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 549 | my $hash = $arg->{hash}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 549 | my $weight = $arg->{weight}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 549 | my $self = $arg->{self}; # $self from $arg | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 549 | ▶ | my $nomenclature = $arg->{nomenclature} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg->{'nomenclature'} || {}
MC/DC0%0/1
$arg->{'nomenclature'} || {}
$arg->{'nomenclature'}
Truth table50%1/2
A
A= $arg->{'nomenclature'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 549 | my $nodes = $self->{nodes}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 549 | my $edges = $self->{edges}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 549 | my $format = $self->{format}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 549 | my $switch = $self->{retain_excluded_phenotypicFeatures}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 549 | my %out_hash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # Do some pruning excluded / included | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 549 | prune_excluded_included( $hash, $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # *** IMPORTANT *** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # The user may include a term that: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # 1 - may not exist in any individual | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # 2 - does not exist in some individuals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # If the term does not exist in a individual | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # - a) -include-terms contains ANOTHER TERM THAT EXISTS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # %$hash will contain keys => OK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # - b) -include-terms only includes the term/terms not present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # %$hash = 0 , then we return {}, to avoid trouble w/ Fold.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 549 | ▶ | return {} unless %$hash; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # Remapping pipeline: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # 1. Apply include/exclude pruning before identities are generated. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # 2. Normalize nested arrays before folding. Deeper arrays are converted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # to hashes keyed by deterministic content signatures, so order-only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # nested index differences disappear. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # 3. Fold with Hash::Fold. NB: Hash::Fold keeps white spaces on keys. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # 4. Replace first-level array indexes after folding. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # First-level arrays intentionally use the fold-then-remap path. This keeps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # the documented CURIE-style replacement separate from the content-derived | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # signatures used for deeper nested arrays. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 548 | set_excluded_phenotypicFeatures( $hash, $switch, $format ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 548 | normalize_nested_array_indexes( $hash, $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 548 | $hash = fold($hash); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # Now we proceed for each key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 548 | for my $key ( keys %{$hash} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # Load values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 106221 | my $val = $hash->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 106221 | ▶ | next unless remap_leaf_is_usable( $key, $val, $self ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # Add IDs to key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 28661 | my $id_key = add_id2key( $key, $hash, $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # Finally add value to id_key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 28661 | my $tmp_key_at_variable_level = $id_key . '.' . $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # Add HPO ascendants | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 28661 | ▶ | if ( defined $edges && $val =~ /^HP:/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $edges and $val =~ /^HP:/
MC/DC100%2/2
defined $edges and $val =~ /^HP:/
defined $edges
$val =~ /^HP:/
Truth table100%3/3
A and B
A= defined $edgesB= $val =~ /^HP:/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | my $ascendants = add_hpo_ascendants( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | $tmp_key_at_variable_level, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | $nodes, $edges, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | $nomenclature | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | $out_hash{$_} = 1 for @$ascendants; # weight 1 for now | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | ################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # Assign weights # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | ################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # NB: mrueda (04-12-23) - it's ok if $weight == undef => NO AUTOVIVIFICATION! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # NB: We don't warn if user selection does not exist, just assign 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 28661 | my $tmp_key_at_term_level = $tmp_key_at_variable_level; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # If variable has . then capture $1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 28661 | ▶ | if ( $tmp_key_at_term_level =~ m/\./ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # NB: For long str regex is faster than (split /\./, $foo)[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 28661 | $tmp_key_at_term_level =~ m/^(\w+)\./; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 28661 | $tmp_key_at_term_level = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 28661 | ▶ | if ( defined $weight ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # *** IMPORTANT *** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # ORDER MATTERS !!!! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # We allow for assigning weights by TERM (e.g., 1D) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # but VARIABLE level takes precedence to TERM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | $out_hash{$tmp_key_at_variable_level} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # VARIABLE LEVEL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # NB: exists stringifies the weights | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | exists $weight->{$tmp_key_at_variable_level} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ? $weight->{$tmp_key_at_variable_level} + 0 # coercing to number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # TERM LEVEL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | : exists $weight->{$tmp_key_at_term_level} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 5295 | ▶ | ? $weight->{$tmp_key_at_term_level} + 0 # coercing to number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # NO WEIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # Assign a weight of 1 if no users weights | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 23366 | $out_hash{$tmp_key_at_variable_level} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | ############## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # label Hash # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | ############## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # Finally we load the Nomenclature hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 28661 | my $label = $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 28661 | $label =~ s/id/label/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | $nomenclature->{$tmp_key_at_variable_level} = $hash->{$label} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 28661 | ▶ | if defined $hash->{$label}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # *** IMPORTANT *** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # We have to return an object {} when undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 548 | ▶ | return \%out_hash // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
\%out_hash // {}
MC/DC0%0/1
\%out_hash // {}
\%out_hash
Truth table50%1/2
A
A= \%out_hash
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 551 | ▶ | sub normalize_nested_array_indexes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_nested_array_indexes: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 551 | my ( $data, $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 551 | _normalize_nested_arrays( $data, $self, '', 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 551 | return $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 175423 | ▶ | sub _normalize_nested_arrays { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_nested_arrays: called CC=9 SCAR=22.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 175423 | my ( $data, $self, $path, $array_depth ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 175423 | ▶ | if ( ref $data eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 70304 | for my $key ( keys %{$data} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 168011 | ▶ | my $child_path = length $path ? "$path.$key" : $key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 168011 | my $value = $data->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 168011 | ▶ | if ( ref $value eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 2477 | ▶ | if ($array_depth) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 735 | $data->{$key} = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | _normalize_nested_array( $value, $self, $child_path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | $array_depth ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1742 | for my $i ( 0 .. $#{$value} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 9325 | _normalize_nested_arrays( $value->[$i], $self, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | "$child_path:$i", $array_depth + 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 165534 | _normalize_nested_arrays( $value, $self, $child_path, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | $array_depth ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | elsif ( ref $data eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | for my $i ( 0 .. $#{$data} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | _normalize_nested_arrays( $data->[$i], $self, "$path:$i", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | $array_depth + 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 175423 | return $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 735 | ▶ | sub _normalize_nested_array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_nested_array: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 735 | my ( $array, $self, $path, $array_depth ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 735 | my %normalized; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | my @unidentified; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 735 | for my $i ( 0 .. $#{$array} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 13 | my $item = $array->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 13 | _normalize_nested_arrays( $item, $self, "$path:$i", $array_depth + 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 13 | my $signature = _nested_item_signature( "$path:$i", $item, $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 13 | ▶ | if ( defined $signature ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 13 | $normalized{$signature} = $item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | push @unidentified, $item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # If any item lacks usable content, preserve the original array. Keeping | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # numeric indexes is safer than inventing identities from ignored fields. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 735 | ▶ | return $array if @unidentified; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 735 | return \%normalized; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 13 | ▶ | sub _nested_item_signature { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_nested_item_signature: called CC=8 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 13 | my ( $prefix, $item, $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 13 | ▶ | my $folded = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | ref $item eq 'HASH' ? fold($item) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | : ref $item ? {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | : { '__value__' => $item }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 13 | my @items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 13 | for my $relative ( sort keys %{$folded} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 31 | my $value = $folded->{$relative}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 31 | ▶ | next if ref $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 31 | ▶ | my $key = $relative eq '__value__' ? $prefix : "$prefix.$relative"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 31 | ▶ | next unless remap_leaf_is_usable( $key, $value, $self ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 22 | push @items, "$relative=$value"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 13 | ▶ | return unless @items; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 13 | return 'idx_' . substr( sha1_hex( join "\x1e", @items ), 0, 12 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 8 | ▶ | sub _nested_array_signature { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_nested_array_signature: called CC=8 SCAR=21.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 8 | my ( $prefix, $hash, $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 8 | my @items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # Used for generic JSON first-level array default identity inference from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # already-folded hashes. Pre-fold nested array normalization uses | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # _nested_item_signature(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 8 | for my $key ( sort keys %{$hash} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 40 | ▶ | next unless $key eq $prefix || index( $key, "$prefix." ) == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq $prefix or index($key, "$prefix.") == 0
MC/DC50%1/2
$key eq $prefix or index($key, "$prefix.") == 0
$key eq $prefix
index($key, "$prefix.") == 0
Truth table66%2/3
A or B
A= $key eq $prefixB= index($key, "$prefix.") == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 16 | my $value = $hash->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 16 | ▶ | next if ref $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 16 | ▶ | next unless remap_leaf_is_usable( $key, $value, $self ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 16 | ▶ | my $relative = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | $key eq $prefix ? '__value__' : substr( $key, length($prefix) + 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 16 | push @items, "$relative=$value"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 8 | ▶ | return unless @items; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 8 | return 'idx_' . substr( sha1_hex( join "\x1e", @items ), 0, 12 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 106270 | ▶ | sub remap_leaf_is_usable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remap_leaf_is_usable: called CC=16 SCAR=28.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 106270 | my ( $key, $val, $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 106270 | ▶ | return 0 unless defined $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 102876 | my $exclude_variables_regex_qr = $self->{exclude_variables_regex_qr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # Discard low-quality keys. Some can be rescued by adding ontology data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # but labels/info/metaData should not affect either variables or signatures. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 102876 | ▶ | return 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $exclude_variables_regex_qr and $key =~ /$exclude_variables_regex_qr/
MC/DC100%2/2
defined $exclude_variables_regex_qr and $key =~ /$exclude_variables_regex_qr/
defined $exclude_variables_regex_qr
$key =~ /$exclude_variables_regex_qr/
Truth table100%3/3
A and B
A= defined $exclude_variables_regex_qrB= $key =~ /$exclude_variables_regex_qr/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | if defined $exclude_variables_regex_qr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | && $key =~ $exclude_variables_regex_qr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 41010 | ▶ | my $format = $self->{format} || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'format'} || ''
MC/DC0%0/1
$self->{'format'} || ''
$self->{'format'}
Truth table50%1/2
A
A= $self->{'format'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | return 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | if ( ( $format eq 'PXF' || $format eq 'BFF' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | && $key =~ m/\.age(?!nt)|onset/i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 41010 | ▶ | && !$self->{age} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$format eq "PXF" || $format eq "BFF" and $key =~ /\.age(?!nt)|onset/i and not $self->{"age"}
$format eq "PXF" || $format eq "BFF" and $key =~ /\.age(?!nt)|onset/i
$format eq "PXF" or $format eq "BFF"
MC/DC50%2/4
$format eq "PXF" || $format eq "BFF" and $key =~ /\.age(?!nt)|onset/i and not $self->{"age"}
$format eq "PXF"
$format eq "BFF"
$key =~ /\.age(?!nt)|onset/i
not $self->{"age"}
Truth table57%4/7
A or B and C and not(D)
A= $format eq "PXF"B= $format eq "BFF"C= $key =~ /\.age(?!nt)|onset/iD= not $self->{"age"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 39175 | ▶ | return 0 if ref($val) eq 'HASH' && !keys %{$val}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $val eq "HASH" and not keys %{$val;}
MC/DC50%1/2
ref $val eq "HASH" and not keys %{$val;}
ref $val eq "HASH"
not keys %{$val;}
Truth table66%2/3
A and not(B)
A= ref $val eq "HASH"B= not keys %{$val;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | return 0 if ref($val) eq 'ARRAY' && !@{$val}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $val eq "ARRAY" and not @{$val;}
MC/DC0%0/2
ref $val eq "ARRAY" and not @{$val;}
ref $val eq "ARRAY"
not @{$val;}
Truth table33%1/3
A and not(B)
A= ref $val eq "ARRAY"B= not @{$val;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 38446 | ▶ | return 1 if ref $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | my %exclude_values = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 38446 | map { $_ => 1 } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | ( 'NA', 'NaN', 'Fake', 'None:No matching concept', 'Not Available' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 38446 | ▶ | return 0 if exists $exclude_values{$val}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 38446 | my $misc_regex_qr = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | qr/1900-01-01|NA0000|NCIT:C126101|P999Y|P9999Y|phenopacket_id/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 38446 | ▶ | return 0 if $val =~ $misc_regex_qr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 28701 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 28662 | ▶ | sub add_id2key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_id2key: called CC=13 SCAR=25.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 28662 | my ( $key, $hash, $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | my $id_correspondence = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | defined $self->{id_correspondence} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | && defined $self->{format} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | && exists $self->{id_correspondence}{ $self->{format} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | ? $self->{id_correspondence}{ $self->{format} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 28662 | ▶ | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $self->{"id_correspondence"} and defined $self->{"format"} and exists $self->{"id_correspondence"}{$self->{"format"}}
defined $self->{"id_correspondence"} and defined $self->{"format"}
MC/DC33%1/3
defined $self->{"id_correspondence"} and defined $self->{"format"} and exists $self->{"id_correspondence"}{$self->{"format"}}
defined $self->{"id_correspondence"}
defined $self->{"format"}
exists $self->{"id_correspondence"}{$self->{"format"}}
Truth table50%2/4
A and B and C
A= defined $self->{"id_correspondence"}B= defined $self->{"format"}C= exists $self->{"id_correspondence"}{$self->{"format"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 28662 | my $array_regex_qr = $self->{array_regex_qr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 28662 | my $array_terms_regex_qr = $self->{array_terms_regex_qr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | ############# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # OBJECTIVE # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | ############# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | # This subroutine is important as it replaces the index (numeric) for a given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # array element by a selected ontology. It's done for all subkeys on that element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | #"interventionsOrProcedures" : [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # "bodySite" : { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # "id" : "NCIT:C12736", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # "label" : "intestine" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # "procedureCode" : { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | # "id" : "NCIT:C157823", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # "label" : "Colon Resection" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | # "bodySite" : { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # "id" : "NCIT:C12736", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # "label" : "intestine" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | # "procedureCode" : { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | # "id" : "NCIT:C86074", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # "label" : "Hemicolectomy" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | # }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | #] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # Will become: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | #"interventionsOrProcedures.NCIT:C157823.bodySite.id.NCIT:C12736" : 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | #"interventionsOrProcedures.NCIT:C157823.procedureCode.id.NCIT:C157823" : 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | #"interventionsOrProcedures.NCIT:C86074.bodySite.id.NCIT:C12736" : 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | #"interventionsOrProcedures.NCIT:C86074.procedureCode.id.NCIT:C86074" : 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | # To make the replacement we use $id_correspondence, then we perform a regex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # to fetch the key parts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # Only proceed if $key is one of the array_terms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 28662 | ▶ | if ( $key =~ $array_terms_regex_qr ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | # Now we use $array_regex_qr to capture $1, $2 and $3 for object arrays. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # For scalar arrays we will have only $1 and $2. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 27283 | $key =~ $array_regex_qr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | #say "$array_regex_qr -- [$key] <$1> <$2> <$3>"; # $3 can be undefined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 27283 | my ( $tmp_key, $val ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | # Object arrays. Explicit identity_paths take precedence. Generic JSON | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | # can fall back to direct id-like fields or content signatures. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 27283 | ▶ | if ( defined $3 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 27151 | my $correspondence; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 27151 | ▶ | if ( defined $id_correspondence && ref $id_correspondence->{$1} eq ref [] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
defined $id_correspondence and ref $id_correspondence->{$1} eq ref []
MC/DC100%2/2
defined $id_correspondence and ref $id_correspondence->{$1} eq ref []
defined $id_correspondence
ref $id_correspondence->{$1} eq ref []
Truth table100%3/3
A and B
A= defined $id_correspondenceB= ref $id_correspondence->{$1} eq ref []
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | # $1 $2 $3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # <medicalActions> <0> <treatment.routeOfAdministration.id> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 11 | my $subkey = ( split /\./, $3 )[0]; # treatment | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | $correspondence = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 11 | ▶ | first { $_ =~ m/^$subkey/ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 11 | @{ $id_correspondence->{$1} }; # treatment.agent.id | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | ▶ | elsif ( defined $id_correspondence && exists $id_correspondence->{$1} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $id_correspondence and exists $id_correspondence->{$1}
MC/DC50%1/2
defined $id_correspondence and exists $id_correspondence->{$1}
defined $id_correspondence
exists $id_correspondence->{$1}
Truth table66%2/3
A and B
A= defined $id_correspondenceB= exists $id_correspondence->{$1}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 27130 | $correspondence = $id_correspondence->{$1}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 27151 | ▶ | if ( defined $correspondence ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | # Now that we know which is the term we use to find key-val in $hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 27141 | $tmp_key = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | $1 . ':' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | . $2 . '.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | . $correspondence; # medicalActions.0.treatment.agent.id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 27141 | $val = $hash->{$tmp_key}; # DrugCentral:257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | elsif ( _uses_json_default_identity($self) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 10 | $val = _default_json_array_identity( $1, $2, $hash, $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | die | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | "<$1> contains object array elements but has no identity path in <$self->{config_file}>. Please add it under <identity_paths>.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 27151 | $key = join '.', $1, $val, $3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | ; # medicalActions.DrugCentral:257.treatment.routeOfAdministration.id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | # Generic JSON scalar arrays. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 132 | $tmp_key = $1 . ':' . $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 132 | $val = $hash->{$tmp_key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 132 | $key = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | # $key = 'Bar:1' means that we have array but the user either: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | # a) Made a mistake in the config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | # b) Is not using the right config file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 1379 | ▶ | die | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | "<$1> contains array elements but is not defined as an array in <$self->{config_file}>. Please check your syntax and configuration file.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | if $key =~ m/^(\w+):/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 28662 | return $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 10 | ▶ | sub _uses_json_default_identity { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_uses_json_default_identity: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 10 | ▶ | return defined $self->{format} && $self->{format} eq 'JSON'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $self->{'format'} && $self->{'format'} eq 'JSON'
MC/DC0%0/2
defined $self->{'format'} && $self->{'format'} eq 'JSON'
defined $self->{'format'}
$self->{'format'} eq 'JSON'
Truth table33%1/3
A && B
A= defined $self->{'format'}B= $self->{'format'} eq 'JSON'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 10 | ▶ | sub _default_json_array_identity { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_json_array_identity: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 10 | my ( $term, $index, $hash, $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 10 | my $prefix = "$term:$index"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 10 | for my $path (qw(id identifier code name title value)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 50 | my $key = "$prefix.$path"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | return $hash->{$key} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | if exists $hash->{$key} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 50 | ▶ | && remap_leaf_is_usable( $key, $hash->{$key}, $self ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $hash->{$key} and remap_leaf_is_usable($key, $hash->{$key}, $self)
MC/DC50%1/2
exists $hash->{$key} and remap_leaf_is_usable($key, $hash->{$key}, $self)
exists $hash->{$key}
remap_leaf_is_usable($key, $hash->{$key}, $self)
Truth table66%2/3
A and B
A= exists $hash->{$key}B= remap_leaf_is_usable($key, $hash->{$key}, $self)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 8 | my $signature = _nested_array_signature( $prefix, $hash, $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 8 | ▶ | die | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | "<$term> contains object array elements but no usable default identity could be inferred. Please add <identity_paths> in <$self->{config_file}>.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | unless defined $signature; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 8 | return $signature; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 116 | ▶ | sub guess_label { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
guess_label: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 116 | my $input_string = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 116 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | $input_string =~ /\. # Match a literal dot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | ([^\.]+) # Match and capture everything except a dot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | $ # Anchor to the end of the string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | /x | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 115 | return $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | # If no dot is found, return the original string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 1 | return $input_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||