lib/Convert/Pheno/CBioPortal/ToBFF.pm

filter: Statementstmt 93.7% 180 / 192 Branchbran 57.8% 59 / 102 Conditioncond 41.1% 37 / 90 MC/DCmcdc 9.2% 5 / 54 Subroutinesub 100% 25 / 25 Podpod 0.0% 0 / 1 totaltotal 65.9% 306 / 464 CC 93 SCAR 25.4
CC
93
Cov
72%
_map_sex
26.1
_map_biosample
19.6
_map_individual
19.4
CRAP 12.6
« lib/Convert/Pheno/Tabular/ToBFF.pm ↑ Summary lib/Convert/Pheno/Source/TablePackage.pm »
1 package Convert::Pheno::CBioPortal::ToBFF;
2  
3 136 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 136 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 136 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 136 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 136 ▶use Convert::Pheno::BFF::Biosample qw(biosample_to_phenopacket);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 136 ▶use Convert::Pheno::Context;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 136 ▶use Convert::Pheno::Model::Bundle;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 136 ▶use Convert::Pheno::Tabular::ToBFF qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
13 map_tabular_biosamples
14 map_tabular_individual
15 136 );
16 136 ▶use Convert::Pheno::Utils::Default qw(get_defaults);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 136 our @EXPORT_OK = qw(run_cbioportal_to_bundle);
19  
20 136 my $DEFAULT = get_defaults();
21  
22 100 ▶sub run_cbioportal_to_bundle {
Subroutine run_cbioportal_to_bundle: called CC=15 SCAR=28.6
Pod undocumented
23 100 my ( $self, $record, $context ) = @_;
24  
25 $context ||= Convert::Pheno::Context->from_self(
26 $self,
27 {
28 source_format => 'cbioportal',
29 target_format => 'beacon',
30 100 ▶ entities => $self->{entities} || ['individuals'],
Condition20%1/5
$context ||= "Convert::Pheno::Context"->from_self($self, {"source_format", "cbioportal", "target_format", "beacon", "entities", $self->{"entities"} || ["individuals"]})
l!l&&r!l&&!r
10000
$self->{'entities'} || ['individuals']
l!l
00
MC/DC0%0/2
$context ||= "Convert::Pheno::Context"->from_self($self, {"source_format", "cbioportal", "target_format", "beacon", "entities", $self->{"entities"} || ["individuals"]})
$context "Convert::Pheno::Context"->from_self($self, {"source_format", "cbioportal", "target_format", "beacon", "entities", $self->{"entities"} || ["individuals"]})
MC/DC0%0/1
$self->{'entities'} || ['individuals']
$self->{'entities'}
Truth table33%1/3
A ||= B
A= $contextB= "Convert::Pheno::Context"->from_self($self, {"source_format", "cbioportal", "target_format", "beacon", "entities", $self->{"entities"} || ["individuals"]})
ABresult
1X1
011
000
Truth table0%0/2
A
A= $self->{'entities'}
Aresult
11
00
31 }
32 );
33  
34 die "Normalized cBioPortal input must contain a patient-scoped object\n"
35 unless ref($record) eq 'HASH'
36 && ref( $record->{patient} ) eq 'HASH'
37 100 ▶ && ref( $record->{study} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $record eq "HASH" and ref $record->{"patient"} eq "HASH" and ref $record->{"study"} eq "HASH" 0 100 100
Condition33%2/6
ref $record eq "HASH" and ref $record->{"patient"} eq "HASH" and ref $record->{"study"} eq "HASH"
!ll&&!rl&&r
00100
ref $record eq "HASH" and ref $record->{"patient"} eq "HASH"
!ll&&!rl&&r
00100
MC/DC0%0/3
ref $record eq "HASH" and ref $record->{"patient"} eq "HASH" and ref $record->{"study"} eq "HASH"
ref $record eq "HASH" ref $record->{"patient"} eq "HASH" ref $record->{"study"} eq "HASH"
Truth table25%1/4
A and B and C
A= ref $record eq "HASH"B= ref $record->{"patient"} eq "HASH"C= ref $record->{"study"} eq "HASH"
ABCresult
0XX0
10X0
1100
1111
38  
39 100 my $bundle = Convert::Pheno::Model::Bundle->new(
40 {
41 context => $context,
42 entities => $context->entities,
43 }
44 );
45  
46 100 my $individual = _map_individual($self, $record);
47 my @biosamples = map {
48 _map_biosample( $self, $_, $individual->{id} )
49 100 ▶ } @{ $record->{samples} || [] };
Condition50%1/2
$record->{'samples'} || []
l!l
1000
MC/DC0%0/1
$record->{'samples'} || []
$record->{'samples'}
Truth table50%1/2
A
A= $record->{'samples'}
Aresult
11
00
50  
51 # PXF pipelines carry only the primary individual between stages. Keep a
52 # Phenopackets representation here so linked samples are not discarded.
53 100 ▶ if (@biosamples) {
Branch: 1 branch
BranchTrueFalseTotal
if (@biosamples) 100 0 100
54 $individual->{info}{phenopacket}{biosamples} = [
55 100 map { biosample_to_phenopacket($_) } @biosamples
56 ];
57 }
58  
59 100 $bundle->add_entity( individuals => $individual );
60 100 ▶ if ( _context_requests_entity( $context, 'biosamples' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_context_requests_entity($context, "biosamples")) 40 60 100
61 40 $bundle->add_entity( biosamples => $_ ) for @biosamples;
62 }
63  
64 100 ▶ if ( $record->{isFirst}
Branch: 1 branch
BranchTrueFalseTotal
if ($record->{"isFirst"} and _context_requests_entity($context, "datasets")) 2 98 100
Condition100%3/3
$record->{"isFirst"} and _context_requests_entity($context, "datasets")
!ll&&!rl&&r
9082
MC/DC100%2/2
$record->{"isFirst"} and _context_requests_entity($context, "datasets")
$record->{"isFirst"} _context_requests_entity($context, "datasets")
Truth table100%3/3
A and B
A= $record->{"isFirst"}B= _context_requests_entity($context, "datasets")
ABresult
0X0
100
111
65 && _context_requests_entity( $context, 'datasets' ) )
66 {
67 $bundle->add_entity(
68 datasets => _map_dataset( $self, $record->{study} )
69 2 );
70 }
71  
72 100 ▶ if ( $record->{isFirst}
Branch: 1 branch
BranchTrueFalseTotal
if ($record->{"isFirst"} and _context_requests_entity($context, "cohorts")) 3 97 100
Condition100%3/3
$record->{"isFirst"} and _context_requests_entity($context, "cohorts")
!ll&&!rl&&r
9073
MC/DC100%2/2
$record->{"isFirst"} and _context_requests_entity($context, "cohorts")
$record->{"isFirst"} _context_requests_entity($context, "cohorts")
Truth table100%3/3
A and B
A= $record->{"isFirst"}B= _context_requests_entity($context, "cohorts")
ABresult
0X0
100
111
73 && _context_requests_entity( $context, 'cohorts' ) )
74 {
75 $bundle->add_entity( cohorts => $_ )
76 3 for @{ _map_cohorts( $self, $record->{study} ) };
77 }
78  
79 100 return $bundle;
80 }
81  
82 100 ▶sub _map_individual {
Subroutine _map_individual: called CC=15 SCAR=29.6
83 100 my ( $self, $record ) = @_;
84 100 my $patient = $record->{patient};
85 100 my $id = _required_scalar( $patient->{PATIENT_ID}, 'PATIENT_ID' );
86  
87 100 my $individual = {
88 id => $id,
89 sex => _map_sex($patient),
90 };
91  
92 100 my $vital_status = _map_vital_status($patient);
93 100 ▶ $individual->{info}{phenopacket}{vitalStatus} = $vital_status
Branch: 1 branch
BranchTrueFalseTotal
if $vital_status 0 100 100
94 if $vital_status;
95  
96 100 my ( %seen_disease, @diseases );
97 100 ▶ for my $sample ( @{ $record->{samples} || [] } ) {
Condition50%1/2
$record->{'samples'} || []
l!l
1000
MC/DC0%0/1
$record->{'samples'} || []
$record->{'samples'}
Truth table50%1/2
A
A= $record->{'samples'}
Aresult
11
00
98 100 my $term = _oncotree_term($sample);
99 100 ▶ next unless $term && !$seen_disease{ $term->{id} }++;
Branch: 1 branch
BranchTrueFalseTotal
unless $term and not $seen_disease{$term->{"id"}}++ 0 100 100
Condition33%1/3
$term and not $seen_disease{$term->{"id"}}++
!ll&&!rl&&r
00100
MC/DC0%0/2
$term and not $seen_disease{$term->{"id"}}++
$term not $seen_disease{$term->{"id"}}++
Truth table33%1/3
A and not(B)
A= $termB= not $seen_disease{$term->{"id"}}++
ABresult
0X0
100
111
100 100 push @diseases, { diseaseCode => $term };
101 }
102 100 ▶ $individual->{diseases} = \@diseases if @diseases;
Branch: 1 branch
BranchTrueFalseTotal
if @diseases 100 0 100
103  
104 100 ▶ if ( $self->{source_info} // 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"source_info"} // 1) 90 10 100
Condition50%1/2
$self->{"source_info"} // 1
l!l
1000
MC/DC0%0/1
$self->{"source_info"} // 1
$self->{"source_info"}
Truth table50%1/2
A
A= $self->{"source_info"}
Aresult
11
00
105 90 $individual->{info}{cbioportal}{patient} = dclone($patient);
106 }
107  
108 100 ▶ if ( ref( $self->{data_mapping_file} ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"data_mapping_file"} eq "HASH") 10 90 100
109 10 my $mapped = map_tabular_individual( $self, $patient );
110 10 ▶ die "The cBioPortal mapping did not produce individual <$id>; ensure its sex source is populated\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $mapped eq "HASH" 0 10 10
111 unless ref($mapped) eq 'HASH';
112 die "A cBioPortal mapping cannot rewrite PATIENT_ID <$id> as <$mapped->{id}>\n"
113 10 ▶ unless defined $mapped->{id} && "$mapped->{id}" eq $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mapped->{"id"} and qq[$mapped->{"id"}] eq $id 0 10 10
Condition33%1/3
defined $mapped->{"id"} and qq[$mapped->{"id"}] eq $id
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $mapped->{"id"} and qq[$mapped->{"id"}] eq $id
defined $mapped->{"id"} qq[$mapped->{"id"}] eq $id
Truth table33%1/3
A and B
A= defined $mapped->{"id"}B= qq[$mapped->{"id"}] eq $id
ABresult
0X0
100
111
114  
115 # cBioPortal identifiers are structural: sample links and case lists
116 # refer to them. Mapping rules augment semantics but cannot change the
117 # identity graph without breaking those source relationships.
118 10 _merge_hash_into( $individual, $mapped );
119 10 $individual->{id} = $id;
120 }
121  
122 $individual->{info}{convertPheno} = $self->{convertPheno}
123 100 ▶ if !$self->{test} && defined $self->{convertPheno};
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"test"} and defined $self->{"convertPheno"} 0 100 100
Condition33%1/3
not $self->{"test"} and defined $self->{"convertPheno"}
!ll&&!rl&&r
10000
MC/DC0%0/2
not $self->{"test"} and defined $self->{"convertPheno"}
not $self->{"test"} defined $self->{"convertPheno"}
Truth table33%1/3
not(A) and B
A= not $self->{"test"}B= defined $self->{"convertPheno"}
ABresult
0X0
100
111
124  
125 100 return $individual;
126 }
127  
128 100 ▶sub _map_biosample {
Subroutine _map_biosample: called CC=15 SCAR=29.7
129 100 my ( $self, $sample, $individual_id ) = @_;
130 100 my $id = _required_scalar( $sample->{SAMPLE_ID}, 'SAMPLE_ID' );
131 my $source_patient_id = _required_scalar(
132 $sample->{PATIENT_ID},
133 100 'PATIENT_ID',
134 );
135 100 ▶ die "cBioPortal sample <$id> cannot be linked to rewritten individual <$individual_id>\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $source_patient_id eq $individual_id 0 100 100
136 unless $source_patient_id eq $individual_id;
137  
138 my $biosample = {
139 id => $id,
140 individualId => $individual_id,
141 biosampleStatus => dclone( $DEFAULT->{ontology_term} ),
142 # cBioPortal SAMPLE_TYPE is a source category, not necessarily an
143 # ontology concept. Preserve it in info and avoid inventing a CURIE.
144 100 sampleOriginType => dclone( $DEFAULT->{ontology_term} ),
145 };
146 100 my $diagnosis = _oncotree_term($sample);
147 100 ▶ $biosample->{histologicalDiagnosis} = $diagnosis if $diagnosis;
Branch: 1 branch
BranchTrueFalseTotal
if $diagnosis 100 0 100
148  
149 100 ▶ if ( $self->{source_info} // 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"source_info"} // 1) 90 10 100
Condition50%1/2
$self->{"source_info"} // 1
l!l
1000
MC/DC0%0/1
$self->{"source_info"} // 1
$self->{"source_info"}
Truth table50%1/2
A
A= $self->{"source_info"}
Aresult
11
00
150 90 $biosample->{info}{cbioportal}{sample} = dclone($sample);
151 }
152  
153 100 ▶ if ( ref( $self->{data_mapping_file} ) eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"data_mapping_file"} eq "HASH" and ref $self->{"data_mapping_file"}{"beacon"}{"biosamples"} eq "HASH") 10 90 100
Condition66%2/3
ref $self->{"data_mapping_file"} eq "HASH" and ref $self->{"data_mapping_file"}{"beacon"}{"biosamples"} eq "HASH"
!ll&&!rl&&r
90010
MC/DC50%1/2
ref $self->{"data_mapping_file"} eq "HASH" and ref $self->{"data_mapping_file"}{"beacon"}{"biosamples"} eq "HASH"
ref $self->{"data_mapping_file"} eq "HASH" ref $self->{"data_mapping_file"}{"beacon"}{"biosamples"} eq "HASH"
Truth table66%2/3
A and B
A= ref $self->{"data_mapping_file"} eq "HASH"B= ref $self->{"data_mapping_file"}{"beacon"}{"biosamples"} eq "HASH"
ABresult
0X0
100
111
154 && ref( $self->{data_mapping_file}{beacon}{biosamples} ) eq 'HASH' )
155 {
156 10 my $mapped = map_tabular_biosamples( $self, $sample, $individual_id );
157 die "The cBioPortal mapping produced multiple biosamples for SAMPLE_ID <$id>; define one matching biosample rule per sample row\n"
158 10 ▶ if @{$mapped} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @{$mapped;} > 1 0 10 10
159 10 ▶ if ( @{$mapped} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$mapped;}) 10 0 10
160 10 my $mapped_sample = $mapped->[0];
161 die "A cBioPortal mapping cannot rewrite SAMPLE_ID <$id> as <$mapped_sample->{id}>\n"
162 unless defined $mapped_sample->{id}
163 10 ▶ && "$mapped_sample->{id}" eq $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mapped_sample->{"id"} and qq[$mapped_sample->{"id"}] eq $id 0 10 10
Condition33%1/3
defined $mapped_sample->{"id"} and qq[$mapped_sample->{"id"}] eq $id
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $mapped_sample->{"id"} and qq[$mapped_sample->{"id"}] eq $id
defined $mapped_sample->{"id"} qq[$mapped_sample->{"id"}] eq $id
Truth table33%1/3
A and B
A= defined $mapped_sample->{"id"}B= qq[$mapped_sample->{"id"}] eq $id
ABresult
0X0
100
111
164 die "A cBioPortal mapping cannot relink SAMPLE_ID <$id> to another individual\n"
165 if defined $mapped_sample->{individualId}
166 10 ▶ && "$mapped_sample->{individualId}" ne $individual_id;
Branch: 1 branch
BranchTrueFalseTotal
if defined $mapped_sample->{"individualId"} and qq[$mapped_sample->{"individualId"}] ne $individual_id 0 10 10
Condition33%1/3
defined $mapped_sample->{"individualId"} and qq[$mapped_sample->{"individualId"}] ne $individual_id
!ll&&!rl&&r
0100
MC/DC0%0/2
defined $mapped_sample->{"individualId"} and qq[$mapped_sample->{"individualId"}] ne $individual_id
defined $mapped_sample->{"individualId"} qq[$mapped_sample->{"individualId"}] ne $individual_id
Truth table33%1/3
A and B
A= defined $mapped_sample->{"individualId"}B= qq[$mapped_sample->{"individualId"}] ne $individual_id
ABresult
0X0
100
111
167 10 _merge_hash_into( $biosample, $mapped_sample );
168 10 $biosample->{id} = $id;
169 10 $biosample->{individualId} = $individual_id;
170 }
171 }
172  
173 $biosample->{info}{convertPheno} = $self->{convertPheno}
174 100 ▶ if !$self->{test} && defined $self->{convertPheno};
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"test"} and defined $self->{"convertPheno"} 0 100 100
Condition33%1/3
not $self->{"test"} and defined $self->{"convertPheno"}
!ll&&!rl&&r
10000
MC/DC0%0/2
not $self->{"test"} and defined $self->{"convertPheno"}
not $self->{"test"} defined $self->{"convertPheno"}
Truth table33%1/3
not(A) and B
A= not $self->{"test"}B= defined $self->{"convertPheno"}
ABresult
0X0
100
111
175  
176 100 return $biosample;
177 }
178  
179 2 ▶sub _map_dataset {
Subroutine _map_dataset: called CC=6 SCAR=19.6
180 2 my ( $self, $study ) = @_;
181 2 my $meta = $study->{metadata};
182 my $dataset = {
183 id => $study->{id},
184 name => $meta->{name},
185 description => $meta->{description} // "cBioPortal study $study->{id}.",
186 info => {
187 sourceEntity => 'cBioPortal clinical study',
188 individualCount => 0 + $study->{patientCount},
189 biosampleCount => 0 + $study->{sampleCount},
190 },
191 2 ▶ };
Condition50%1/2
$meta->{"description"} // qq[cBioPortal study $study->{"id"}.]
l!l
20
MC/DC0%0/1
$meta->{"description"} // qq[cBioPortal study $study->{"id"}.]
$meta->{"description"}
Truth table50%1/2
A
A= $meta->{"description"}
Aresult
11
00
192  
193 2 ▶ if ( $self->{source_info} // 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"source_info"} // 1) 2 0 2
Condition50%1/2
$self->{"source_info"} // 1
l!l
20
MC/DC0%0/1
$self->{"source_info"} // 1
$self->{"source_info"}
Truth table50%1/2
A
A= $self->{"source_info"}
Aresult
11
00
194 $dataset->{info}{cbioportal} = {
195 source => $study->{source},
196 study => dclone($meta),
197 patientAttributeDefinitions => dclone(
198 $study->{patientAttributeDefinitions}
199 ),
200 sampleAttributeDefinitions => dclone(
201 $study->{sampleAttributeDefinitions}
202 2 ),
203 };
204 }
205  
206 2 _apply_dataset_overrides( $self, $dataset );
207 $dataset->{info}{convertPheno} = $self->{convertPheno}
208 2 ▶ if !$self->{test} && defined $self->{convertPheno};
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"test"} and defined $self->{"convertPheno"} 0 2 2
Condition33%1/3
not $self->{"test"} and defined $self->{"convertPheno"}
!ll&&!rl&&r
200
MC/DC0%0/2
not $self->{"test"} and defined $self->{"convertPheno"}
not $self->{"test"} defined $self->{"convertPheno"}
Truth table33%1/3
not(A) and B
A= not $self->{"test"}B= defined $self->{"convertPheno"}
ABresult
0X0
100
111
209 2 return $dataset;
210 }
211  
212 3 ▶sub _map_cohorts {
Subroutine _map_cohorts: called CC=5 SCAR=16.2
213 3 my ( $self, $study ) = @_;
214 3 my @cohorts;
215  
216 3 ▶ for my $case ( @{ $study->{caseLists} || [] } ) {
Condition50%1/2
$study->{'caseLists'} || []
l!l
30
MC/DC0%0/1
$study->{'caseLists'} || []
$study->{'caseLists'}
Truth table50%1/2
A
A= $study->{'caseLists'}
Aresult
11
00
217 3 my $meta = $case->{metadata};
218 my $cohort = {
219 id => $meta->{stable_id},
220 name => $meta->{case_list_name},
221 cohortType => 'study-defined',
222 3 cohortSize => scalar @{ $case->{individualIds} },
223 info => {
224 cbioportal => {
225 membership => {
226 sampleIds => dclone( $case->{sampleIds} ),
227 3 individualIds => dclone( $case->{individualIds} ),
228 },
229 },
230 },
231 };
232  
233 3 ▶ if ( $self->{source_info} // 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"source_info"} // 1) 2 1 3
Condition50%1/2
$self->{"source_info"} // 1
l!l
30
MC/DC0%0/1
$self->{"source_info"} // 1
$self->{"source_info"}
Truth table50%1/2
A
A= $self->{"source_info"}
Aresult
11
00
234 2 $cohort->{info}{cbioportal}{caseList} = dclone($meta);
235 2 $cohort->{info}{cbioportal}{source} = $case->{source};
236 }
237  
238 3 _apply_cohort_overrides( $self, $cohort );
239 3 push @cohorts, $cohort;
240 }
241  
242 3 return \@cohorts;
243 }
244  
245 100 ▶sub _map_sex {
Subroutine _map_sex: called CC=11 SCAR=32.6
246 100 my ($patient) = @_;
247 100 my $value;
248 100 for my $field (qw(SEX GENDER)) {
249 200 ▶ next unless defined $patient->{$field} && !ref( $patient->{$field} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $patient->{$field} and not ref $patient->{$field} 200 0 200
Condition33%1/3
defined $patient->{$field} and not ref $patient->{$field}
!ll&&!rl&&r
20000
MC/DC0%0/2
defined $patient->{$field} and not ref $patient->{$field}
defined $patient->{$field} not ref $patient->{$field}
Truth table33%1/3
A and not(B)
A= defined $patient->{$field}B= not ref $patient->{$field}
ABresult
0X0
100
111
250 0 $value = lc _trim( $patient->{$field} );
251 0 ▶ last if length $value;
Branch: 1 branch
BranchTrueFalseTotal
if length $value 0 0 0
252 }
253  
254 return dclone( $DEFAULT->{sex}{male} )
255 100 ▶ if defined $value && $value =~ /\A(?:m|male)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and $value =~ /\A(?:m|male)\z/ 0 100 100
Condition33%1/3
defined $value and $value =~ /\A(?:m|male)\z/
!ll&&!rl&&r
10000
MC/DC0%0/2
defined $value and $value =~ /\A(?:m|male)\z/
defined $value $value =~ /\A(?:m|male)\z/
Truth table33%1/3
A and B
A= defined $valueB= $value =~ /\A(?:m|male)\z/
ABresult
0X0
100
111
256 return dclone( $DEFAULT->{sex}{female} )
257 100 ▶ if defined $value && $value =~ /\A(?:f|female)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and $value =~ /\A(?:f|female)\z/ 0 100 100
Condition33%1/3
defined $value and $value =~ /\A(?:f|female)\z/
!ll&&!rl&&r
10000
MC/DC0%0/2
defined $value and $value =~ /\A(?:f|female)\z/
defined $value $value =~ /\A(?:f|female)\z/
Truth table33%1/3
A and B
A= defined $valueB= $value =~ /\A(?:f|female)\z/
ABresult
0X0
100
111
258 return dclone( $DEFAULT->{sex}{other} )
259 100 ▶ if defined $value && $value eq 'other';
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and $value eq "other" 0 100 100
Condition33%1/3
defined $value and $value eq "other"
!ll&&!rl&&r
10000
MC/DC0%0/2
defined $value and $value eq "other"
defined $value $value eq "other"
Truth table33%1/3
A and B
A= defined $valueB= $value eq "other"
ABresult
0X0
100
111
260 100 return dclone( $DEFAULT->{sex}{unknown} );
261 }
262  
263 100 ▶sub _map_vital_status {
Subroutine _map_vital_status: called CC=5 SCAR=25.2
264 100 my ($patient) = @_;
265 100 my $status = $patient->{OS_STATUS};
266 100 ▶ return unless defined $status && !ref($status);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status and not ref $status 100 0 100
Condition33%1/3
defined $status and not ref $status
!ll&&!rl&&r
10000
MC/DC0%0/2
defined $status and not ref $status
defined $status not ref $status
Truth table33%1/3
A and not(B)
A= defined $statusB= not ref $status
ABresult
0X0
100
111
267  
268 0 ▶ return { status => 'DECEASED' } if $status =~ /DECEASED/i;
Branch: 1 branch
BranchTrueFalseTotal
if $status =~ /DECEASED/i 0 0 0
269 0 ▶ return { status => 'ALIVE' } if $status =~ /(?:LIVING|ALIVE)/i;
Branch: 1 branch
BranchTrueFalseTotal
if $status =~ /(?:LIVING|ALIVE)/i 0 0 0
270 0 return;
271 }
272  
273 200 ▶sub _oncotree_term {
Subroutine _oncotree_term: called CC=4 SCAR=14.2
274 200 my ($sample) = @_;
275 200 my $code = _trim( $sample->{ONCOTREE_CODE} );
276 200 ▶ return unless _has_source_value($code);
Branch: 1 branch
BranchTrueFalseTotal
unless _has_source_value($code) 0 200 200
277 200 $code =~ s/\s+/_/g;
278  
279 200 my $label = _trim( $sample->{CANCER_TYPE_DETAILED} );
280 200 ▶ $label = _trim( $sample->{CANCER_TYPE} ) unless _has_source_value($label);
Branch: 1 branch
BranchTrueFalseTotal
unless _has_source_value($label) 0 200 200
281 200 ▶ $label = $code unless _has_source_value($label);
Branch: 1 branch
BranchTrueFalseTotal
unless _has_source_value($label) 0 200 200
282 200 return { id => "OncoTree:$code", label => $label };
283 }
284  
285 2 ▶sub _apply_dataset_overrides {
Subroutine _apply_dataset_overrides: called CC=4 SCAR=16.1
286 2 my ( $self, $dataset ) = @_;
287 2 for my $source (
288 $self->{mapping_file_derived_entity_overrides},
289 $self->{derived_entity_overrides},
290 )
291 {
292 next unless ref($source) eq 'HASH'
293 4 ▶ && ref( $source->{datasets} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source eq "HASH" and ref $source->{"datasets"} eq "HASH" 4 0 4
Condition33%1/3
ref $source eq "HASH" and ref $source->{"datasets"} eq "HASH"
!ll&&!rl&&r
040
MC/DC0%0/2
ref $source eq "HASH" and ref $source->{"datasets"} eq "HASH"
ref $source eq "HASH" ref $source->{"datasets"} eq "HASH"
Truth table33%1/3
A and B
A= ref $source eq "HASH"B= ref $source->{"datasets"} eq "HASH"
ABresult
0X0
100
111
294 0 _merge_hash_into( $dataset, dclone( $source->{datasets} ) );
295 }
296 2 return 1;
297 }
298  
299 3 ▶sub _apply_cohort_overrides {
Subroutine _apply_cohort_overrides: called CC=4 SCAR=18.7
300 3 my ( $self, $cohort ) = @_;
301 3 for my $source (
302 $self->{mapping_file_derived_entity_overrides},
303 $self->{derived_entity_overrides},
304 )
305 {
306 next unless ref($source) eq 'HASH'
307 6 ▶ && ref( $source->{cohorts} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source eq "HASH" and ref $source->{"cohorts"} eq "HASH" 6 0 6
Condition33%1/3
ref $source eq "HASH" and ref $source->{"cohorts"} eq "HASH"
!ll&&!rl&&r
060
MC/DC0%0/2
ref $source eq "HASH" and ref $source->{"cohorts"} eq "HASH"
ref $source eq "HASH" ref $source->{"cohorts"} eq "HASH"
Truth table33%1/3
A and B
A= ref $source eq "HASH"B= ref $source->{"cohorts"} eq "HASH"
ABresult
0X0
100
111
308 0 my $overrides = dclone( $source->{cohorts} );
309 0 delete @{$overrides}{qw(id name cohortSize)};
310 0 _merge_hash_into( $cohort, $overrides );
311 }
312 3 return 1;
313 }
314  
315 80 ▶sub _merge_hash_into {
Subroutine _merge_hash_into: called CC=8 SCAR=21.1
316 80 my ( $target, $source ) = @_;
317 80 ▶ return $target unless ref($source) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source eq "HASH" 0 80 80
318  
319 80 for my $key ( keys %{$source} ) {
320 230 my $value = $source->{$key};
321 230 ▶ next unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 230 230
322  
323 230 ▶ if ( ref($value) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "HASH") 60 170 230
324 my $merged = ref( $target->{$key} ) eq 'HASH'
325 60 ▶ ? _clone_data( $target->{$key} )
Branch: 1 branch
BranchTrueFalseTotal
ref $target->{$key} eq 'HASH' ? : 50 10 60
326 : {};
327 60 _merge_hash_into( $merged, $value );
328 60 $target->{$key} = $merged;
329 60 next;
330 }
331 170 ▶ $target->{$key} = _clone_data($value) if ref($value);
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 170 170
332 170 ▶ $target->{$key} = $value unless ref($value);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value 170 0 170
333 }
334 80 return $target;
335 }
336  
337 290 ▶sub _clone_data {
Subroutine _clone_data: called CC=3 SCAR=11.4
338 290 my ($value) = @_;
339 290 ▶ return { map { $_ => _clone_data( $value->{$_} ) } keys %{$value} }
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "HASH" 90 200 290
340 if ref($value) eq 'HASH';
341 0 ▶ return [ map { _clone_data($_) } @{$value} ]
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "ARRAY" 0 200 200
342 if ref($value) eq 'ARRAY';
343 200 return $value;
344 }
345  
346 300 ▶sub _required_scalar {
Subroutine _required_scalar: called CC=4 SCAR=17.1
347 300 my ( $value, $field ) = @_;
348 300 ▶ die "Normalized cBioPortal input is missing <$field>\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value and length _trim($value) 0 300 300
Condition33%2/6
defined $value and not ref $value and length _trim($value)
!ll&&!rl&&r
00300
defined $value and not ref $value
!ll&&!rl&&r
00300
MC/DC0%0/3
defined $value and not ref $value and length _trim($value)
defined $value not ref $value length _trim($value)
Truth table25%1/4
A and not(B) and C
A= defined $valueB= not ref $valueC= length _trim($value)
ABCresult
0XX0
10X0
1100
1111
349 unless defined $value && !ref($value) && length _trim($value);
350 300 return _trim($value);
351 }
352  
353 600 ▶sub _has_source_value {
Subroutine _has_source_value: called CC=5 SCAR=19.4
354 600 my ($value) = @_;
355 600 ▶ return 0 unless defined $value && !ref($value) && length $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value and length $value 0 600 600
Condition33%2/6
defined $value and not ref $value and length $value
!ll&&!rl&&r
00600
defined $value and not ref $value
!ll&&!rl&&r
00600
MC/DC0%0/3
defined $value and not ref $value and length $value
defined $value not ref $value length $value
Truth table25%1/4
A and not(B) and C
A= defined $valueB= not ref $valueC= length $value
ABCresult
0XX0
10X0
1100
1111
356 600 ▶ return 0 if $value =~ /\A(?:NA|N\/A|\[Not Available\]|Not Available)\z/i;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ m(\A(?:NA|N/A|\[Not Available\]|Not Available)\z)i 0 600 600
357 600 return 1;
358 }
359  
360 1000 ▶sub _trim {
Subroutine _trim: called CC=3 SCAR=11.3
361 1000 my ($value) = @_;
362 1000 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 1000 1000
363 1000 ▶ return $value if ref($value);
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 1000 1000
364 1000 $value =~ s/^\s+|\s+$//g;
365 1000 return $value;
366 }
367  
368 120 ▶sub _context_requests_entity {
Subroutine _context_requests_entity: called CC=1 SCAR=0.0
369 120 my ( $context, $entity ) = @_;
370 120 return scalar grep { $_ eq $entity } @{ $context->entities };
371 }
372  
373 136 1;
« lib/Convert/Pheno/Tabular/ToBFF.pm ↑ Summary lib/Convert/Pheno/Source/TablePackage.pm »