lib/Convert/Pheno/PXF/ToBFF/Individuals.pm

filter: Statementstmt 96.6% 227 / 235 Branchbran 78.9% 120 / 152 Conditioncond 45.4% 15 / 33 MC/DCmcdc 15.7% 3 / 19 Subroutinesub 100% 26 / 26 Podpod 0.0% 0 / 2 totaltotal 83.7% 391 / 467 CC 107 SCAR 21.2
CC
107
Cov
86%
_normalize_evidence
12.3
_map_procedure_performed
11.9
_map_exposures
11.4
CRAP 8.4
« lib/Convert/Pheno/DB/Similarity.pm ↑ Summary lib/Convert/Pheno/IO/CSVHandler.pm »
1 package Convert::Pheno::PXF::ToBFF::Individuals;
2  
3 137 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 137 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 137 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 137 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 137 ▶use Convert::Pheno::Utils::Default qw(get_defaults);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 137 ▶use Convert::Pheno::Mapping::Shared;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 137 our @EXPORT_OK = qw(map_pxf_to_individual);
13  
14 137 my $DEFAULT = get_defaults();
15  
16 341 ▶sub map_pxf_to_individual {
Subroutine map_pxf_to_individual: called CC=1 SCAR=0.0
Pod undocumented
17 341 my ( $self, $phenopacket, $cohort, $family ) = @_;
18  
19 341 my $individual = {};
20  
21 341 _map_diseases( $phenopacket, $individual );
22 341 _map_exposures( $phenopacket, $individual );
23 341 _map_id( $phenopacket, $individual );
24 341 _map_info( $self, $phenopacket, $cohort, $family, $individual );
25 341 _map_interventions_or_procedures( $phenopacket, $individual );
26 341 _map_karyotypicSex( $phenopacket, $individual );
27 341 _map_measures( $phenopacket, $individual );
28 341 _map_phenotypic_features( $phenopacket, $individual );
29 341 _map_sex( $self, $phenopacket, $individual );
30 341 _map_treatments( $phenopacket, $individual );
31  
32 341 return $individual;
33 }
34  
35 341 ▶sub _map_diseases {
Subroutine _map_diseases: called CC=8 SCAR=20.8
36 341 my ( $phenopacket, $individual ) = @_;
37  
38 341 ▶ if ( exists $phenopacket->{diseases} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $phenopacket->{"diseases"}) 230 111 341
39 230 for my $pxf_disease ( @{ $phenopacket->{diseases} } ) {
40 310 my %disease = %{$pxf_disease};
41 310 $disease{diseaseCode} = $disease{term};
42 $disease{ageOfOnset} = _map_time_element_value( $disease{onset} )
43 310 ▶ if exists $disease{onset};
Branch: 1 branch
BranchTrueFalseTotal
if exists $disease{"onset"} 185 125 310
44  
45 310 for (qw/excluded negated/) {
46 620 ▶ $disease{$_} = $disease{$_} if exists $disease{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $disease{$_} 302 318 620
47 }
48  
49 310 for (qw/term onset/) {
50 620 ▶ delete $disease{$_} if exists $disease{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $disease{$_} 495 125 620
51 }
52  
53 310 push @{ $individual->{diseases} }, \%disease;
54 }
55 }
56 }
57  
58 341 ▶sub _map_exposures {
Subroutine _map_exposures: called CC=11 SCAR=24.3
59 341 my ( $phenopacket, $individual ) = @_;
60  
61 341 ▶ if ( exists $phenopacket->{exposures} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $phenopacket->{"exposures"}) 2 339 341
62 2 for my $pxf_exposure ( @{ $phenopacket->{exposures} } ) {
63 4 my %exposure = %{$pxf_exposure};
64 4 $exposure{exposureCode} = $exposure{type};
65  
66 4 ▶ if ( exists $exposure{occurrence} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $exposure{"occurrence"}) 4 0 4
67 4 my $occurrence = delete $exposure{occurrence};
68 4 my ( $date, $age_at_exposure, $unmapped_occurrence ) =
69 _map_exposure_occurrence($occurrence);
70  
71 4 ▶ $exposure{date} = $date if defined $date;
Branch: 1 branch
BranchTrueFalseTotal
if defined $date 2 2 4
72 4 ▶ $exposure{ageAtExposure} = $age_at_exposure
Branch: 1 branch
BranchTrueFalseTotal
if defined $age_at_exposure 2 2 4
73 if defined $age_at_exposure;
74  
75 4 ▶ if ( defined $unmapped_occurrence ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $unmapped_occurrence) 0 4 4
76 0 $exposure{info}{phenopacket}{occurrence} = $unmapped_occurrence;
77 }
78 }
79  
80 4 ▶ unless ( exists $exposure{ageAtExposure} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $exposure{"ageAtExposure"}) 2 2 4
81 2 $exposure{ageAtExposure} = $DEFAULT->{iso8601duration};
82 }
83  
84 $exposure{duration} = $DEFAULT->{duration}
85 4 ▶ unless exists $exposure{duration};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $exposure{"duration"} 4 0 4
86  
87 4 ▶ unless ( exists $exposure{unit} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $exposure{"unit"}) 4 0 4
88 4 $exposure{unit} = $DEFAULT->{ontology_term};
89 }
90  
91 4 ▶ delete $exposure{type} if exists $exposure{type};
Branch: 1 branch
BranchTrueFalseTotal
if exists $exposure{"type"} 4 0 4
92  
93 4 push @{ $individual->{exposures} }, \%exposure;
94 }
95 }
96 }
97  
98 1705 ▶sub _subject_value {
Subroutine _subject_value: called CC=5 SCAR=16.8
99 1705 my ( $phenopacket, @keys ) = @_;
100  
101 return unless exists $phenopacket->{subject}
102 1705 ▶ && ref( $phenopacket->{subject} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless exists $phenopacket->{"subject"} and ref $phenopacket->{"subject"} eq "HASH" 0 1705 1705
Condition33%1/3
exists $phenopacket->{"subject"} and ref $phenopacket->{"subject"} eq "HASH"
!ll&&!rl&&r
001705
MC/DC0%0/2
exists $phenopacket->{"subject"} and ref $phenopacket->{"subject"} eq "HASH"
exists $phenopacket->{"subject"} ref $phenopacket->{"subject"} eq "HASH"
Truth table33%1/3
A and B
A= exists $phenopacket->{"subject"}B= ref $phenopacket->{"subject"} eq "HASH"
ABresult
0X0
100
111
103  
104 1705 for my $key (@keys) {
105 return $phenopacket->{subject}{$key}
106 2315 ▶ if exists $phenopacket->{subject}{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $phenopacket->{"subject"}{$key} 1095 1220 2315
107 }
108  
109 610 return;
110 }
111  
112 310 ▶sub _top_level_value {
Subroutine _top_level_value: called CC=3 SCAR=11.1
113 310 my ( $phenopacket, @keys ) = @_;
114  
115 310 for my $key (@keys) {
116 620 ▶ return $phenopacket->{$key} if exists $phenopacket->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $phenopacket->{$key} 0 620 620
117 }
118  
119 310 return;
120 }
121  
122 2315 ▶sub _map_time_element_value {
Subroutine _map_time_element_value: called CC=6 SCAR=19.0
123 2315 my ($time) = @_;
124 2315 ▶ return unless defined $time;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $time 0 2315 2315
125  
126 2315 ▶ return $time unless ref($time);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $time 0 2315 2315
127  
128 2315 ▶ return $time unless ref($time) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $time eq "HASH" 0 2315 2315
129  
130 2315 for my $key (
131 qw(
132 age
133 ageRange
134 age_range
135 gestationalAge
136 gestational_age
137 interval
138 timeInterval
139 time_interval
140 ontologyClass
141 ontology_class
142 timestamp
143 )
144 )
145 {
146 8840 ▶ return $time->{$key} if exists $time->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $time->{$key} 2315 6525 8840
147 }
148  
149 0 return $time;
150 }
151  
152 4 ▶sub _map_exposure_occurrence {
Subroutine _map_exposure_occurrence: called CC=9 SCAR=22.6
153 4 my ($occurrence) = @_;
154 4 ▶ return unless defined $occurrence;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $occurrence 0 4 4
155  
156 4 ▶ return ( substr( $occurrence, 0, 10 ), undef, undef )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $occurrence 0 4 4
157 unless ref($occurrence);
158  
159 4 ▶ return ( undef, undef, $occurrence ) unless ref($occurrence) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $occurrence eq "HASH" 0 4 4
160  
161 4 my $date;
162 my $age_at_exposure;
163 4 my $handled = 0;
164  
165 4 ▶ if ( exists $occurrence->{timestamp} && defined $occurrence->{timestamp} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $occurrence->{"timestamp"} and defined $occurrence->{"timestamp"}) 2 2 4
Condition66%2/3
exists $occurrence->{"timestamp"} and defined $occurrence->{"timestamp"}
!ll&&!rl&&r
202
MC/DC50%1/2
exists $occurrence->{"timestamp"} and defined $occurrence->{"timestamp"}
exists $occurrence->{"timestamp"} defined $occurrence->{"timestamp"}
Truth table66%2/3
A and B
A= exists $occurrence->{"timestamp"}B= defined $occurrence->{"timestamp"}
ABresult
0X0
100
111
166 2 $date = substr( $occurrence->{timestamp}, 0, 10 );
167 2 $handled = 1;
168 }
169  
170 4 for my $key (qw/age/) {
171 4 ▶ next unless exists $occurrence->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $occurrence->{$key} 2 2 4
172 2 $age_at_exposure = $occurrence->{$key};
173 2 $handled = 1;
174 2 last;
175 }
176  
177 4 ▶ return ( $date, $age_at_exposure, undef ) if $handled;
Branch: 1 branch
BranchTrueFalseTotal
if $handled 4 0 4
178  
179 0 return ( undef, undef, $occurrence );
180 }
181  
182 162 ▶sub _map_procedure_performed {
Subroutine _map_procedure_performed: called CC=10 SCAR=24.7
183 162 my ($performed) = @_;
184 162 ▶ return unless defined $performed;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $performed 0 162 162
185  
186 162 my %mapped;
187  
188 162 ▶ if ( !ref($performed) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $performed) 0 162 162
189 0 $mapped{dateOfProcedure} = substr( $performed, 0, 10 );
190 0 return \%mapped;
191 }
192  
193 162 ▶ return { info => { phenopacket => { performed => $performed } } }
Branch: 1 branch
BranchTrueFalseTotal
unless ref $performed eq "HASH" 0 162 162
194 unless ref($performed) eq 'HASH';
195  
196 162 ▶ if ( exists $performed->{timestamp} && defined $performed->{timestamp} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $performed->{"timestamp"} and defined $performed->{"timestamp"}) 52 110 162
Condition66%2/3
exists $performed->{"timestamp"} and defined $performed->{"timestamp"}
!ll&&!rl&&r
110052
MC/DC50%1/2
exists $performed->{"timestamp"} and defined $performed->{"timestamp"}
exists $performed->{"timestamp"} defined $performed->{"timestamp"}
Truth table66%2/3
A and B
A= exists $performed->{"timestamp"}B= defined $performed->{"timestamp"}
ABresult
0X0
100
111
197 52 $mapped{dateOfProcedure} = substr( $performed->{timestamp}, 0, 10 );
198 }
199  
200 162 for my $key (
201 qw(
202 age
203 ageRange
204 age_range
205 gestationalAge
206 gestational_age
207 interval
208 timeInterval
209 time_interval
210 ontologyClass
211 ontology_class
212 )
213 )
214 {
215 630 ▶ next unless exists $performed->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $performed->{$key} 520 110 630
216 110 $mapped{ageAtProcedure} = $performed->{$key};
217 110 last;
218 }
219  
220 162 ▶ unless ( exists $mapped{ageAtProcedure} || exists $mapped{dateOfProcedure} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $mapped{"ageAtProcedure"} or exists $mapped{"dateOfProcedure"}) 0 162 162
Condition66%2/3
exists $mapped{"ageAtProcedure"} or exists $mapped{"dateOfProcedure"}
l!l&&r!l&&!r
110520
MC/DC0%0/2
exists $mapped{"ageAtProcedure"} or exists $mapped{"dateOfProcedure"}
exists $mapped{"ageAtProcedure"} exists $mapped{"dateOfProcedure"}
Truth table66%2/3
A or B
A= exists $mapped{"ageAtProcedure"}B= exists $mapped{"dateOfProcedure"}
ABresult
1X1
011
000
221 0 $mapped{info}{phenopacket}{performed} = $performed;
222 }
223  
224 162 return \%mapped;
225 }
226  
227 452 ▶sub _map_evidence {
Subroutine _map_evidence: called CC=5 SCAR=17.0
228 452 my ($evidence) = @_;
229 452 ▶ return unless defined $evidence;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $evidence 0 452 452
230  
231 452 ▶ my $mapped = _normalize_evidence(
Branch: 1 branch
BranchTrueFalseTotal
ref $evidence eq 'ARRAY' ? : 452 0 452
232 ref($evidence) eq 'ARRAY' ? $evidence->[0] : $evidence
233 );
234  
235 452 ▶ return unless defined $mapped;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mapped 0 452 452
236  
237 452 ▶ if ( ref($evidence) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $evidence eq "ARRAY") 452 0 452
238 # Beacon v2 individuals still models evidence as a single object.
239 452 $mapped->{info}{phenopacket}{evidence} = $evidence;
240 }
241  
242 452 return $mapped;
243 }
244  
245 452 ▶sub _normalize_evidence {
Subroutine _normalize_evidence: called CC=8 SCAR=25.1
246 452 my ($evidence) = @_;
247 452 ▶ return unless ref($evidence) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $evidence eq "HASH" 0 452 452
248  
249 452 my %mapped = %{$evidence};
250 452 $mapped{reference} = { %{ $mapped{reference} } }
251 if exists $mapped{reference}
252 452 ▶ && ref( $mapped{reference} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if exists $mapped{"reference"} and ref $mapped{"reference"} eq "HASH" 452 0 452
Condition33%1/3
exists $mapped{"reference"} and ref $mapped{"reference"} eq "HASH"
!ll&&!rl&&r
00452
MC/DC0%0/2
exists $mapped{"reference"} and ref $mapped{"reference"} eq "HASH"
exists $mapped{"reference"} ref $mapped{"reference"} eq "HASH"
Truth table33%1/3
A and B
A= exists $mapped{"reference"}B= ref $mapped{"reference"} eq "HASH"
ABresult
0X0
100
111
253  
254 452 ▶ if ( exists $mapped{reference}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $mapped{"reference"} and ref $mapped{"reference"} eq "HASH" and exists $mapped{"reference"}{"description"} and not exists $mapped{"reference"}{"notes"}) 452 0 452
Condition33%3/9
exists $mapped{"reference"} and ref $mapped{"reference"} eq "HASH" and exists $mapped{"reference"}{"description"} and not exists $mapped{"reference"}{"notes"}
!ll&&!rl&&r
00452
exists $mapped{"reference"} and ref $mapped{"reference"} eq "HASH" and exists $mapped{"reference"}{"description"}
!ll&&!rl&&r
00452
exists $mapped{"reference"} and ref $mapped{"reference"} eq "HASH"
!ll&&!rl&&r
00452
MC/DC0%0/4
exists $mapped{"reference"} and ref $mapped{"reference"} eq "HASH" and exists $mapped{"reference"}{"description"} and not exists $mapped{"reference"}{"notes"}
exists $mapped{"reference"} ref $mapped{"reference"} eq "HASH" exists $mapped{"reference"}{"description"} not exists $mapped{"reference"}{"notes"}
Truth table20%1/5
A and B and C and not(D)
A= exists $mapped{"reference"}B= ref $mapped{"reference"} eq "HASH"C= exists $mapped{"reference"}{"description"}D= not exists $mapped{"reference"}{"notes"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
255 && ref( $mapped{reference} ) eq 'HASH'
256 && exists $mapped{reference}{description}
257 && !exists $mapped{reference}{notes} )
258 {
259 452 $mapped{reference}{notes} = delete $mapped{reference}{description};
260 }
261  
262 452 return \%mapped;
263 }
264  
265 162 ▶sub _merge_info_hash {
Subroutine _merge_info_hash: called CC=6 SCAR=22.1
266 162 my ( $target, $source ) = @_;
267 162 ▶ return unless ref($source) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source eq "HASH" 0 162 162
268  
269 162 for my $key ( keys %{$source} ) {
270 162 ▶ if ( exists $target->{$key}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $target->{$key} and ref $target->{$key} eq "HASH" and ref $source->{$key} eq "HASH") 0 162 162
Condition33%2/6
exists $target->{$key} and ref $target->{$key} eq "HASH" and ref $source->{$key} eq "HASH"
!ll&&!rl&&r
16200
exists $target->{$key} and ref $target->{$key} eq "HASH"
!ll&&!rl&&r
16200
MC/DC0%0/3
exists $target->{$key} and ref $target->{$key} eq "HASH" and ref $source->{$key} eq "HASH"
exists $target->{$key} ref $target->{$key} eq "HASH" ref $source->{$key} eq "HASH"
Truth table25%1/4
A and B and C
A= exists $target->{$key}B= ref $target->{$key} eq "HASH"C= ref $source->{$key} eq "HASH"
ABCresult
0XX0
10X0
1100
1111
271 && ref( $target->{$key} ) eq 'HASH'
272 && ref( $source->{$key} ) eq 'HASH' )
273 {
274 0 _merge_info_hash( $target->{$key}, $source->{$key} );
275 0 next;
276 }
277  
278 162 $target->{$key} = $source->{$key};
279 }
280 }
281  
282 341 ▶sub _map_id {
Subroutine _map_id: called CC=2 SCAR=7.1
283 341 my ( $phenopacket, $individual ) = @_;
284  
285 341 my $id = _subject_value( $phenopacket, qw/id/ );
286 341 ▶ $individual->{id} = $id if defined $id;
Branch: 1 branch
BranchTrueFalseTotal
if defined $id 341 0 341
287 }
288  
289 341 ▶sub _map_info {
Subroutine _map_info: called CC=9 SCAR=22.0
290 341 my ( $self, $phenopacket, $cohort, $family, $individual ) = @_;
291  
292 341 my $date_of_birth = _subject_value( $phenopacket, qw/dateOfBirth date_of_birth/ );
293 341 ▶ $date_of_birth = _top_level_value( $phenopacket, qw/dateOfBirth date_of_birth/ )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date_of_birth 310 31 341
294 unless defined $date_of_birth;
295 341 ▶ $individual->{info}{phenopacket}{dateOfBirth} = $date_of_birth
Branch: 1 branch
BranchTrueFalseTotal
if defined $date_of_birth 31 310 341
296 if defined $date_of_birth;
297  
298 341 my $vitalStatus = _subject_value( $phenopacket, qw/vitalStatus vital_status/ );
299 341 ▶ $individual->{info}{phenopacket}{vitalStatus} = $vitalStatus
Branch: 1 branch
BranchTrueFalseTotal
if defined $vitalStatus 55 286 341
300 if defined $vitalStatus;
301  
302 341 for my $term (
303 qw(genes interpretations metaData variants files biosamples pedigree)
304 )
305 {
306 $individual->{info}{phenopacket}{$term} = $phenopacket->{$term}
307 2387 ▶ if exists $phenopacket->{$term};
Branch: 1 branch
BranchTrueFalseTotal
if exists $phenopacket->{$term} 672 1715 2387
308 }
309  
310 341 ▶ $individual->{info}{cohort} = $cohort if defined $cohort;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cohort 2 339 341
311 341 ▶ $individual->{info}{family} = $family if defined $family;
Branch: 1 branch
BranchTrueFalseTotal
if defined $family 2 339 341
312  
313 341 ▶ unless ( $self->{test} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"test"}) 6 335 341
314 6 $individual->{info}{convertPheno} = $self->{convertPheno};
315 }
316 }
317  
318 341 ▶sub _map_interventions_or_procedures {
Subroutine _map_interventions_or_procedures: called CC=8 SCAR=20.8
319 341 my ( $phenopacket, $individual ) = @_;
320  
321 341 ▶ if ( exists $phenopacket->{medicalActions} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $phenopacket->{"medicalActions"}) 154 187 341
322 154 for my $action ( @{ $phenopacket->{medicalActions} } ) {
323 514 ▶ if ( exists $action->{procedure} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $action->{"procedure"}) 162 352 514
324 162 my %procedure = %{ $action->{procedure} };
325 $procedure{procedureCode} =
326 exists $action->{procedure}{code}
327 ? $action->{procedure}{code}
328 162 ▶ : $DEFAULT->{ontology_term};
Branch: 1 branch
BranchTrueFalseTotal
exists $action->{'procedure'}{'code'} ? : 160 2 162
329  
330 162 ▶ if ( exists $procedure{performed} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $procedure{"performed"}) 162 0 162
331 my $mapped_performed =
332 162 _map_procedure_performed( delete $procedure{performed} );
333 162 ▶ _merge_info_hash( \%procedure, $mapped_performed )
Branch: 1 branch
BranchTrueFalseTotal
if defined $mapped_performed 162 0 162
334 if defined $mapped_performed;
335 }
336  
337 162 ▶ delete $procedure{code} if exists $procedure{code};
Branch: 1 branch
BranchTrueFalseTotal
if exists $procedure{"code"} 160 2 162
338  
339 162 push @{ $individual->{interventionsOrProcedures} }, \%procedure;
340 }
341 }
342 }
343 }
344  
345 341 ▶sub _map_karyotypicSex {
Subroutine _map_karyotypicSex: called CC=2 SCAR=6.9
346 341 my ( $phenopacket, $individual ) = @_;
347  
348 341 my $karyotypic_sex =
349 _subject_value( $phenopacket, qw/karyotypicSex karyotypic_sex/ );
350 341 ▶ $individual->{karyotypicSex} = $karyotypic_sex
Branch: 1 branch
BranchTrueFalseTotal
if defined $karyotypic_sex 327 14 341
351 if defined $karyotypic_sex;
352 }
353  
354 341 ▶sub _map_measures {
Subroutine _map_measures: called CC=9 SCAR=22.0
355 341 my ( $phenopacket, $individual ) = @_;
356  
357 341 ▶ if ( exists $phenopacket->{measurements} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $phenopacket->{"measurements"}) 127 214 341
358 127 for my $measurement ( @{ $phenopacket->{measurements} } ) {
359 477 my %measure = %{$measurement};
360  
361 477 $measure{assayCode} = $measure{assay};
362  
363 $measure{complexValue} = map_complexValue( $measure{complexValue} )
364 477 ▶ if exists $measure{complexValue};
Branch: 1 branch
BranchTrueFalseTotal
if exists $measure{"complexValue"} 77 400 477
365  
366 $measure{measurementValue} =
367 exists $measure{value} ? $measure{value}
368 : exists $measure{complexValue} ? $measure{complexValue}
369 477 ▶ : $DEFAULT->{value};
Branch: 2 branches
BranchTrueFalseTotal
exists $measure{'value'} ? : 400 77 477
exists $measure{'complexValue'} ? : 77 0 77
370 $measure{observationMoment} = _map_time_element_value( $measure{timeObserved} )
371 477 ▶ if exists $measure{timeObserved};
Branch: 1 branch
BranchTrueFalseTotal
if exists $measure{"timeObserved"} 402 75 477
372  
373 477 for (qw/assay value complexValue/) {
374 1431 ▶ delete $measure{$_} if exists $measure{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $measure{$_} 954 477 1431
375 }
376  
377 477 push @{ $individual->{measures} }, \%measure;
378 }
379 }
380 }
381  
382 341 ▶sub _map_phenotypic_features {
Subroutine _map_phenotypic_features: called CC=10 SCAR=23.0
383 341 my ( $phenopacket, $individual ) = @_;
384  
385 341 ▶ if ( exists $phenopacket->{phenotypicFeatures} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $phenopacket->{"phenotypicFeatures"}) 303 38 341
386 303 for my $feature ( @{ $phenopacket->{phenotypicFeatures} } ) {
387 1953 my %phenotypicFeature = %{$feature};
388  
389 1953 for (qw/excluded negated/) {
390 $phenotypicFeature{excluded} = $phenotypicFeature{$_}
391 3906 ▶ if exists $phenotypicFeature{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $phenotypicFeature{$_} 1953 1953 3906
392 }
393  
394 $phenotypicFeature{featureType} = $phenotypicFeature{type}
395 1953 ▶ if exists $phenotypicFeature{type};
Branch: 1 branch
BranchTrueFalseTotal
if exists $phenotypicFeature{"type"} 1953 0 1953
396 $phenotypicFeature{onset} = _map_time_element_value( $phenotypicFeature{onset} )
397 1953 ▶ if exists $phenotypicFeature{onset};
Branch: 1 branch
BranchTrueFalseTotal
if exists $phenotypicFeature{"onset"} 1728 225 1953
398 $phenotypicFeature{evidence} = _map_evidence( $phenotypicFeature{evidence} )
399 1953 ▶ if exists $phenotypicFeature{evidence};
Branch: 1 branch
BranchTrueFalseTotal
if exists $phenotypicFeature{"evidence"} 452 1501 1953
400  
401 1953 for (qw/negated type/) {
402 delete $phenotypicFeature{$_}
403 3906 ▶ if exists $phenotypicFeature{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $phenotypicFeature{$_} 1955 1951 3906
404 }
405  
406 1953 push @{ $individual->{phenotypicFeatures} }, \%phenotypicFeature;
407 }
408 }
409 }
410  
411 341 ▶sub _map_sex {
Subroutine _map_sex: called CC=3 SCAR=11.0
412 341 my ( $self, $phenopacket, $individual ) = @_;
413  
414 341 my $sex = _subject_value( $phenopacket, qw/sex/ );
415  
416 341 ▶ if ( defined $sex && $sex ne '' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sex and $sex ne "") 339 2 341
Condition66%2/3
defined $sex and $sex ne ""
!ll&&!rl&&r
02339
MC/DC50%1/2
defined $sex and $sex ne ""
defined $sex $sex ne ""
Truth table66%2/3
A and B
A= defined $sexB= $sex ne ""
ABresult
0X0
100
111
417 {
418 339 $individual->{sex} = map_ontology_term(
419 {
420 query => $sex,
421 column => 'label',
422 ontology => 'ncit',
423 self => $self
424 }
425 );
426 }
427 }
428  
429 341 ▶sub _map_treatments {
Subroutine _map_treatments: called CC=10 SCAR=23.0
430 341 my ( $phenopacket, $individual ) = @_;
431  
432 341 ▶ if ( exists $phenopacket->{medicalActions} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $phenopacket->{"medicalActions"}) 154 187 341
433 154 for my $action ( @{ $phenopacket->{medicalActions} } ) {
434 514 ▶ if ( exists $action->{treatment} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $action->{"treatment"}) 327 187 514
435 327 my %treatment = %{ $action->{treatment} };
436 $treatment{treatmentCode} =
437 exists $action->{treatment}{agent}
438 ? $action->{treatment}{agent}
439 327 ▶ : $DEFAULT->{ontology_term};
Branch: 1 branch
BranchTrueFalseTotal
exists $action->{'treatment'}{'agent'} ? : 325 2 327
440  
441 327 ▶ delete $treatment{agent} if exists $treatment{agent};
Branch: 1 branch
BranchTrueFalseTotal
if exists $treatment{"agent"} 325 2 327
442  
443 327 ▶ if ( exists $treatment{doseIntervals} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $treatment{"doseIntervals"}) 302 25 327
444 302 for ( @{ $treatment{doseIntervals} } ) {
445 329 ▶ unless ( exists $_->{quantity} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $_->{"quantity"}) 1 328 329
446 1 $_->{quantity} = $DEFAULT->{quantity};
447 }
448  
449 329 ▶ unless ( exists $_->{scheduleFrequency} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $_->{"scheduleFrequency"}) 2 327 329
450 2 $_->{scheduleFrequency} = $DEFAULT->{ontology_term};
451 }
452 }
453 }
454  
455 327 push @{ $individual->{treatments} }, \%treatment;
456 }
457 }
458 }
459 }
460  
461 77 ▶sub map_complexValue {
Subroutine map_complexValue: called CC=1 SCAR=0.0
Pod undocumented
462 77 my $complexValue = shift;
463 77 my %mapped = %{$complexValue};
464  
465 $mapped{typedQuantities} = [
466 map {
467 102 my %quantity = %{$_};
468 102 $quantity{quantityType} = delete $quantity{type};
469 102 \%quantity;
470 77 } @{ $complexValue->{typedQuantities} }
471 ];
472  
473 77 return \%mapped;
474 }
475  
476 137 1;
« lib/Convert/Pheno/DB/Similarity.pm ↑ Summary lib/Convert/Pheno/IO/CSVHandler.pm »