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

filter: Statementstmt 97.4% 113 / 116 Branchbran 72.2% 65 / 90 Conditioncond 45.8% 22 / 48 MC/DCmcdc 11.1% 3 / 27 Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 2 totaltotal 73.0% 217 / 297 CC 68 SCAR 25.7
CC
68
Cov
79%
map_pxf_to_biosample
21.3
_map_phenotypic_features
17.6
_map_measurements
12.2
CRAP 13.1
« lib/Convert/Pheno/OMOP/ToBFF/Individuals.pm ↑ Summary lib/Convert/Pheno/Tabular/ToBFF.pm »
1 package Convert::Pheno::PXF::ToBFF::Biosamples;
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  
11 137 our @EXPORT_OK = qw(extract_pxf_biosamples map_pxf_to_biosample);
12  
13 137 my $DEFAULT = get_defaults();
14  
15 244 ▶sub extract_pxf_biosamples {
Subroutine extract_pxf_biosamples: called CC=4 SCAR=13.9
Pod undocumented
16 244 my ( $self, $phenopacket, $individual_id ) = @_;
17  
18 return []
19 unless exists $phenopacket->{biosamples}
20 244 ▶ && ref( $phenopacket->{biosamples} ) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless exists $phenopacket->{"biosamples"} and ref $phenopacket->{"biosamples"} eq "ARRAY" 145 99 244
Condition66%2/3
exists $phenopacket->{"biosamples"} and ref $phenopacket->{"biosamples"} eq "ARRAY"
!ll&&!rl&&r
145099
MC/DC50%1/2
exists $phenopacket->{"biosamples"} and ref $phenopacket->{"biosamples"} eq "ARRAY"
exists $phenopacket->{"biosamples"} ref $phenopacket->{"biosamples"} eq "ARRAY"
Truth table66%2/3
A and B
A= exists $phenopacket->{"biosamples"}B= ref $phenopacket->{"biosamples"} eq "ARRAY"
ABresult
0X0
100
111
21  
22 99 my @biosamples;
23 99 for my $biosample ( @{ $phenopacket->{biosamples} } ) {
24 228 push @biosamples,
25 map_pxf_to_biosample( $self, $biosample, $individual_id );
26 }
27  
28 99 return \@biosamples;
29 }
30  
31 230 ▶sub map_pxf_to_biosample {
Subroutine map_pxf_to_biosample: called CC=21 SCAR=30.6
Pod undocumented
32 230 my ( $self, $source, $individual_id ) = @_;
33  
34 230 my %biosample = %{$source};
35 230 _normalize_biosample_aliases( \%biosample );
36  
37 my $mapped = {
38 id => $biosample{id},
39 individualId => $biosample{individualId} // $individual_id,
40 biosampleStatus =>
41 $biosample{materialSample} // $DEFAULT->{ontology_term},
42 sampleOriginType =>
43 $biosample{sampleType} // $DEFAULT->{ontology_term},
44 230 ▶ };
Condition66%6/9
$biosample{"individualId"} // $individual_id
l!l&&r!l&&!r
166640
$biosample{"materialSample"} // $DEFAULT->{"ontology_term"}
l!l&&r!l&&!r
12290
$biosample{"sampleType"} // $DEFAULT->{"ontology_term"}
l!l&&r!l&&!r
12290
MC/DC0%0/2
$biosample{"individualId"} // $individual_id
$biosample{"individualId"} $individual_id
MC/DC0%0/2
$biosample{"materialSample"} // $DEFAULT->{"ontology_term"}
$biosample{"materialSample"} $DEFAULT->{"ontology_term"}
MC/DC0%0/2
$biosample{"sampleType"} // $DEFAULT->{"ontology_term"}
$biosample{"sampleType"} $DEFAULT->{"ontology_term"}
Truth table66%2/3
A // B
A= $biosample{"individualId"}B= $individual_id
ABresult
1X1
011
000
Truth table66%2/3
A // B
A= $biosample{"materialSample"}B= $DEFAULT->{"ontology_term"}
ABresult
1X1
011
000
Truth table66%2/3
A // B
A= $biosample{"sampleType"}B= $DEFAULT->{"ontology_term"}
ABresult
1X1
011
000
45  
46 230 ▶ if ( exists $biosample{timeOfCollection} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $biosample{"timeOfCollection"}) 145 85 230
47 145 my $collection_date = _map_collection_date( $biosample{timeOfCollection} );
48 my $collection_moment =
49 145 _map_collection_moment( $biosample{timeOfCollection} );
50  
51 145 ▶ $mapped->{collectionDate} = $collection_date if defined $collection_date;
Branch: 1 branch
BranchTrueFalseTotal
if defined $collection_date 1 144 145
52 145 ▶ $mapped->{collectionMoment} = $collection_moment if defined $collection_moment;
Branch: 1 branch
BranchTrueFalseTotal
if defined $collection_moment 145 0 145
53 }
54  
55 $mapped->{diagnosticMarkers} = $biosample{diagnosticMarkers}
56 230 ▶ if exists $biosample{diagnosticMarkers};
Branch: 1 branch
BranchTrueFalseTotal
if exists $biosample{"diagnosticMarkers"} 19 211 230
57 $mapped->{histologicalDiagnosis} = $biosample{histologicalDiagnosis}
58 230 ▶ if exists $biosample{histologicalDiagnosis};
Branch: 1 branch
BranchTrueFalseTotal
if exists $biosample{"histologicalDiagnosis"} 91 139 230
59 $mapped->{notes} = $biosample{description}
60 230 ▶ if exists $biosample{description};
Branch: 1 branch
BranchTrueFalseTotal
if exists $biosample{"description"} 1 229 230
61 $mapped->{pathologicalStage} = $biosample{pathologicalStage}
62 230 ▶ if exists $biosample{pathologicalStage};
Branch: 1 branch
BranchTrueFalseTotal
if exists $biosample{"pathologicalStage"} 1 229 230
63 $mapped->{pathologicalTnmFinding} = $biosample{pathologicalTnmFinding}
64 230 ▶ if exists $biosample{pathologicalTnmFinding};
Branch: 1 branch
BranchTrueFalseTotal
if exists $biosample{"pathologicalTnmFinding"} 19 211 230
65 $mapped->{phenotypicFeatures} = _map_phenotypic_features( $biosample{phenotypicFeatures} )
66 230 ▶ if exists $biosample{phenotypicFeatures};
Branch: 1 branch
BranchTrueFalseTotal
if exists $biosample{"phenotypicFeatures"} 37 193 230
67 $mapped->{sampleOriginDetail} = $biosample{sampledTissue}
68 230 ▶ if exists $biosample{sampledTissue};
Branch: 1 branch
BranchTrueFalseTotal
if exists $biosample{"sampledTissue"} 181 49 230
69 $mapped->{sampleProcessing} = $biosample{sampleProcessing}
70 230 ▶ if exists $biosample{sampleProcessing};
Branch: 1 branch
BranchTrueFalseTotal
if exists $biosample{"sampleProcessing"} 0 230 230
71 $mapped->{sampleStorage} = $biosample{sampleStorage}
72 230 ▶ if exists $biosample{sampleStorage};
Branch: 1 branch
BranchTrueFalseTotal
if exists $biosample{"sampleStorage"} 0 230 230
73 $mapped->{tumorGrade} = $biosample{tumorGrade}
74 230 ▶ if exists $biosample{tumorGrade};
Branch: 1 branch
BranchTrueFalseTotal
if exists $biosample{"tumorGrade"} 19 211 230
75 $mapped->{tumorProgression} = $biosample{tumorProgression}
76 230 ▶ if exists $biosample{tumorProgression};
Branch: 1 branch
BranchTrueFalseTotal
if exists $biosample{"tumorProgression"} 127 103 230
77 $mapped->{measurements} = _map_measurements( $biosample{measurements} )
78 230 ▶ if exists $biosample{measurements};
Branch: 1 branch
BranchTrueFalseTotal
if exists $biosample{"measurements"} 19 211 230
79 $mapped->{obtentionProcedure} = _map_procedure( $biosample{procedure} )
80 230 ▶ if exists $biosample{procedure};
Branch: 1 branch
BranchTrueFalseTotal
if exists $biosample{"procedure"} 181 49 230
81  
82 230 my $extra = _build_info_payload( \%biosample );
83 230 ▶ $mapped->{info} = { phenopacket => $extra } if %{$extra};
Branch: 1 branch
BranchTrueFalseTotal
if %{$extra;} 181 49 230
84  
85 230 return $mapped;
86 }
87  
88 230 ▶sub _normalize_biosample_aliases {
Subroutine _normalize_biosample_aliases: called CC=4 SCAR=16.4
89 230 my ($biosample) = @_;
90  
91 230 my %alias = (
92 individual_id => 'individualId',
93 derived_from_id => 'derivedFromId',
94 sampled_tissue => 'sampledTissue',
95 sample_type => 'sampleType',
96 phenotypic_features => 'phenotypicFeatures',
97 time_of_collection => 'timeOfCollection',
98 histological_diagnosis => 'histologicalDiagnosis',
99 tumor_progression => 'tumorProgression',
100 tumor_grade => 'tumorGrade',
101 pathological_stage => 'pathologicalStage',
102 pathological_tnm_finding => 'pathologicalTnmFinding',
103 diagnostic_markers => 'diagnosticMarkers',
104 material_sample => 'materialSample',
105 sample_processing => 'sampleProcessing',
106 sample_storage => 'sampleStorage',
107 );
108  
109 230 for my $source_key ( keys %alias ) {
110 3450 my $target_key = $alias{$source_key};
111 3450 ▶ next unless exists $biosample->{$source_key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $biosample->{$source_key} 3450 0 3450
112 0 ▶ next if exists $biosample->{$target_key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $biosample->{$target_key} 0 0 0
113 0 $biosample->{$target_key} = delete $biosample->{$source_key};
114 }
115  
116 230 return 1;
117 }
118  
119 145 ▶sub _map_collection_date {
Subroutine _map_collection_date: called CC=8 SCAR=24.7
120 145 my ($time) = @_;
121 145 ▶ return unless defined $time;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $time 0 145 145
122  
123 return substr( $time->{timestamp}, 0, 10 )
124 145 ▶ if ref($time) eq 'HASH' && exists $time->{timestamp};
Branch: 1 branch
BranchTrueFalseTotal
if ref $time eq "HASH" and exists $time->{"timestamp"} 1 144 145
Condition66%2/3
ref $time eq "HASH" and exists $time->{"timestamp"}
!ll&&!rl&&r
01441
MC/DC50%1/2
ref $time eq "HASH" and exists $time->{"timestamp"}
ref $time eq "HASH" exists $time->{"timestamp"}
Truth table66%2/3
A and B
A= ref $time eq "HASH"B= exists $time->{"timestamp"}
ABresult
0X0
100
111
125  
126 return substr( $time->{interval}{start}, 0, 10 )
127 if ref($time) eq 'HASH'
128 && exists $time->{interval}
129 && ref( $time->{interval} ) eq 'HASH'
130 144 ▶ && exists $time->{interval}{start};
Branch: 1 branch
BranchTrueFalseTotal
if ref $time eq "HASH" and exists $time->{"interval"} and ref $time->{"interval"} eq "HASH" and exists $time->{"interval"}{"start"} 0 144 144
Condition33%3/9
ref $time eq "HASH" and exists $time->{"interval"} and ref $time->{"interval"} eq "HASH" and exists $time->{"interval"}{"start"}
!ll&&!rl&&r
14400
ref $time eq "HASH" and exists $time->{"interval"} and ref $time->{"interval"} eq "HASH"
!ll&&!rl&&r
14400
ref $time eq "HASH" and exists $time->{"interval"}
!ll&&!rl&&r
01440
MC/DC0%0/4
ref $time eq "HASH" and exists $time->{"interval"} and ref $time->{"interval"} eq "HASH" and exists $time->{"interval"}{"start"}
ref $time eq "HASH" exists $time->{"interval"} ref $time->{"interval"} eq "HASH" exists $time->{"interval"}{"start"}
Truth table20%1/5
A and B and C and D
A= ref $time eq "HASH"B= exists $time->{"interval"}C= ref $time->{"interval"} eq "HASH"D= exists $time->{"interval"}{"start"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
131  
132 144 return;
133 }
134  
135 145 ▶sub _map_collection_moment {
Subroutine _map_collection_moment: called CC=6 SCAR=24.3
136 145 my ($time) = @_;
137 145 ▶ return unless defined $time && ref($time) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $time and ref $time eq "HASH" 0 145 145
Condition33%1/3
defined $time and ref $time eq "HASH"
!ll&&!rl&&r
00145
MC/DC0%0/2
defined $time and ref $time eq "HASH"
defined $time ref $time eq "HASH"
Truth table33%1/3
A and B
A= defined $timeB= ref $time eq "HASH"
ABresult
0X0
100
111
138  
139 return $time->{age}{iso8601duration}
140 if exists $time->{age}
141 && ref( $time->{age} ) eq 'HASH'
142 145 ▶ && exists $time->{age}{iso8601duration};
Branch: 1 branch
BranchTrueFalseTotal
if exists $time->{"age"} and ref $time->{"age"} eq "HASH" and exists $time->{"age"}{"iso8601duration"} 145 0 145
Condition33%2/6
exists $time->{"age"} and ref $time->{"age"} eq "HASH" and exists $time->{"age"}{"iso8601duration"}
!ll&&!rl&&r
00145
exists $time->{"age"} and ref $time->{"age"} eq "HASH"
!ll&&!rl&&r
00145
MC/DC0%0/3
exists $time->{"age"} and ref $time->{"age"} eq "HASH" and exists $time->{"age"}{"iso8601duration"}
exists $time->{"age"} ref $time->{"age"} eq "HASH" exists $time->{"age"}{"iso8601duration"}
Truth table25%1/4
A and B and C
A= exists $time->{"age"}B= ref $time->{"age"} eq "HASH"C= exists $time->{"age"}{"iso8601duration"}
ABCresult
0XX0
10X0
1100
1111
143  
144 0 return;
145 }
146  
147 37 ▶sub _map_phenotypic_features {
Subroutine _map_phenotypic_features: called CC=13 SCAR=28.7
148 37 my ($features) = @_;
149 37 ▶ return unless ref($features) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $features eq "ARRAY" 0 37 37
150  
151 37 my @mapped;
152 37 for my $feature ( @{$features} ) {
153 55 ▶ next unless ref($feature) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $feature eq "HASH" 0 55 55
154  
155 55 my %mapped = %{$feature};
156 55 ▶ $mapped{featureType} = delete $mapped{type} if exists $mapped{type};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mapped{"type"} 55 0 55
157  
158 55 ▶ if ( exists $mapped{evidence} && ref( $mapped{evidence} ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $mapped{"evidence"} and ref $mapped{"evidence"} eq "ARRAY") 1 54 55
Condition66%2/3
exists $mapped{"evidence"} and ref $mapped{"evidence"} eq "ARRAY"
!ll&&!rl&&r
5401
MC/DC50%1/2
exists $mapped{"evidence"} and ref $mapped{"evidence"} eq "ARRAY"
exists $mapped{"evidence"} ref $mapped{"evidence"} eq "ARRAY"
Truth table66%2/3
A and B
A= exists $mapped{"evidence"}B= ref $mapped{"evidence"} eq "ARRAY"
ABresult
0X0
100
111
159 1 for my $evidence ( @{ $mapped{evidence} } ) {
160 1 ▶ next unless ref($evidence) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $evidence eq "HASH" 0 1 1
161 $evidence->{reference}{notes} = delete $evidence->{reference}{description}
162 if exists $evidence->{reference}
163 && ref( $evidence->{reference} ) eq 'HASH'
164 && exists $evidence->{reference}{description}
165 1 ▶ && !exists $evidence->{reference}{notes};
Branch: 1 branch
BranchTrueFalseTotal
if exists $evidence->{"reference"} and ref $evidence->{"reference"} eq "HASH" and exists $evidence->{"reference"}{"description"} and not exists $evidence->{"reference"}{"notes"} 1 0 1
Condition33%3/9
exists $evidence->{"reference"} and ref $evidence->{"reference"} eq "HASH" and exists $evidence->{"reference"}{"description"} and not exists $evidence->{"reference"}{"notes"}
!ll&&!rl&&r
001
exists $evidence->{"reference"} and ref $evidence->{"reference"} eq "HASH" and exists $evidence->{"reference"}{"description"}
!ll&&!rl&&r
001
exists $evidence->{"reference"} and ref $evidence->{"reference"} eq "HASH"
!ll&&!rl&&r
001
MC/DC0%0/4
exists $evidence->{"reference"} and ref $evidence->{"reference"} eq "HASH" and exists $evidence->{"reference"}{"description"} and not exists $evidence->{"reference"}{"notes"}
exists $evidence->{"reference"} ref $evidence->{"reference"} eq "HASH" exists $evidence->{"reference"}{"description"} not exists $evidence->{"reference"}{"notes"}
Truth table20%1/5
A and B and C and not(D)
A= exists $evidence->{"reference"}B= ref $evidence->{"reference"} eq "HASH"C= exists $evidence->{"reference"}{"description"}D= not exists $evidence->{"reference"}{"notes"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
166 }
167 }
168  
169 55 push @mapped, \%mapped;
170 }
171  
172 37 return \@mapped;
173 }
174  
175 19 ▶sub _map_measurements {
Subroutine _map_measurements: called CC=10 SCAR=25.0
176 19 my ($measurements) = @_;
177 19 ▶ return unless ref($measurements) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $measurements eq "ARRAY" 0 19 19
178  
179 19 my @mapped;
180 19 for my $measurement ( @{$measurements} ) {
181 19 ▶ next unless ref($measurement) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $measurement eq "HASH" 0 19 19
182  
183 19 my %mapped = %{$measurement};
184 19 ▶ $mapped{assayCode} = delete $mapped{assay} if exists $mapped{assay};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mapped{"assay"} 19 0 19
185 19 ▶ $mapped{measurementValue} = delete $mapped{value} if exists $mapped{value};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mapped{"value"} 19 0 19
186 $mapped{measurementValue} = delete $mapped{complexValue}
187 19 ▶ if !exists $mapped{measurementValue} && exists $mapped{complexValue};
Branch: 1 branch
BranchTrueFalseTotal
if not exists $mapped{"measurementValue"} and exists $mapped{"complexValue"} 0 19 19
Condition33%1/3
not exists $mapped{"measurementValue"} and exists $mapped{"complexValue"}
!ll&&!rl&&r
1900
MC/DC0%0/2
not exists $mapped{"measurementValue"} and exists $mapped{"complexValue"}
not exists $mapped{"measurementValue"} exists $mapped{"complexValue"}
Truth table33%1/3
not(A) and B
A= not exists $mapped{"measurementValue"}B= exists $mapped{"complexValue"}
ABresult
0X0
100
111
188 $mapped{observationMoment} = delete $mapped{timeObserved}
189 19 ▶ if exists $mapped{timeObserved};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mapped{"timeObserved"} 19 0 19
190 $mapped{procedure} = _map_procedure( $mapped{procedure} )
191 19 ▶ if exists $mapped{procedure};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mapped{"procedure"} 0 19 19
192  
193 19 push @mapped, \%mapped;
194 }
195  
196 19 return \@mapped;
197 }
198  
199 181 ▶sub _map_procedure {
Subroutine _map_procedure: called CC=7 SCAR=19.6
200 181 my ($procedure) = @_;
201 181 ▶ return unless ref($procedure) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $procedure eq "HASH" 0 181 181
202  
203 181 my %mapped = %{$procedure};
204 181 ▶ $mapped{procedureCode} = delete $mapped{code} if exists $mapped{code};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mapped{"code"} 181 0 181
205  
206 181 ▶ if ( exists $mapped{performed} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $mapped{"performed"}) 37 144 181
207 37 my $performed = delete $mapped{performed};
208  
209 37 ▶ if ( ref($performed) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $performed eq "HASH") 37 0 37
210 $mapped{ageAtProcedure} = $performed->{age}
211 37 ▶ if exists $performed->{age};
Branch: 1 branch
BranchTrueFalseTotal
if exists $performed->{"age"} 36 1 37
212 $mapped{dateOfProcedure} = substr( $performed->{timestamp}, 0, 10 )
213 37 ▶ if exists $performed->{timestamp};
Branch: 1 branch
BranchTrueFalseTotal
if exists $performed->{"timestamp"} 1 36 37
214 }
215 }
216  
217 181 return \%mapped;
218 }
219  
220 230 ▶sub _build_info_payload {
Subroutine _build_info_payload: called CC=3 SCAR=11.0
221 230 my ($biosample) = @_;
222  
223 230 my %info;
224 230 for my $key (
225 qw(
226 derivedFromId
227 files
228 taxonomy
229 timeOfCollection
230 procedure
231 measurements
232 description
233 sampledTissue
234 sampleType
235 materialSample
236 phenotypicFeatures
237 pathologicalStage
238 pathologicalTnmFinding
239 diagnosticMarkers
240 histologicalDiagnosis
241 tumorProgression
242 tumorGrade
243 sampleProcessing
244 sampleStorage
245 )
246 )
247 {
248 4370 ▶ $info{$key} = $biosample->{$key} if exists $biosample->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $biosample->{$key} 898 3472 4370
249 }
250  
251 230 return \%info;
252 }
253  
254 137 1;
« lib/Convert/Pheno/OMOP/ToBFF/Individuals.pm ↑ Summary lib/Convert/Pheno/Tabular/ToBFF.pm »