| 1 | package Convert::Pheno::PXF::ToBFF; | ||||||||||||||||||||||||||||||
| 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::Context; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 10 | 137 | ▶ | use Convert::Pheno::Model::Bundle; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 11 | 137 | ▶ | use Convert::Pheno::Mapping::Shared; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | 137 | ▶ | use Convert::Pheno::PXF::ToBFF::Individuals qw(map_pxf_to_individual); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 13 | 137 | ▶ | use Convert::Pheno::PXF::ToBFF::Biosamples qw(extract_pxf_biosamples map_pxf_to_biosample); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||
| 15 | 137 | our @EXPORT_OK = qw(do_pxf2bff run_pxf_to_bundle map_pxf_to_individual map_pxf_to_biosample); | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | sub do_pxf2bff { | ||||||||||||||||||||||||||||
|
Subroutine
do_pxf2bff: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 18 | 1 | my ( $self, $data ) = @_; | |||||||||||||||||||||||||||||
| 19 | 1 | my $bundle = run_pxf_to_bundle( $self, $data, $self->{conversion_context} ); | |||||||||||||||||||||||||||||
| 20 | 1 | return $bundle->primary_entity('individuals'); | |||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||
| 23 | 344 | ▶ | sub run_pxf_to_bundle { | ||||||||||||||||||||||||||||
|
Subroutine
run_pxf_to_bundle: called CC=8 SCAR=21.4
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 24 | 344 | my ( $self, $data, $context ) = @_; | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||
| 26 | $context ||= Convert::Pheno::Context->from_self( | ||||||||||||||||||||||||||||||
| 27 | $self, | ||||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||||
| 29 | source_format => 'pxf', | ||||||||||||||||||||||||||||||
| 30 | target_format => 'beacon', | ||||||||||||||||||||||||||||||
| 31 | 344 | ▶ | entities => $self->{entities} || ['individuals'], | ||||||||||||||||||||||||||||
|
Condition20%1/5
$context ||= "Convert::Pheno::Context"->from_self($self, {"source_format", "pxf", "target_format", "beacon", "entities", $self->{"entities"} || ["individuals"]})
$self->{'entities'} || ['individuals']
MC/DC0%0/2
$context ||= "Convert::Pheno::Context"->from_self($self, {"source_format", "pxf", "target_format", "beacon", "entities", $self->{"entities"} || ["individuals"]})
$context
"Convert::Pheno::Context"->from_self($self, {"source_format", "pxf", "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", "pxf", "target_format", "beacon", "entities", $self->{"entities"} || ["individuals"]})
Truth table0%0/2
A
A= $self->{'entities'}
| |||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||
| 35 | 344 | my $bundle = Convert::Pheno::Model::Bundle->new( | |||||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||||
| 37 | context => $context, | ||||||||||||||||||||||||||||||
| 38 | entities => $context->entities, | ||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||
| 42 | 344 | my ( $phenopacket, $cohort, $family ) = _extract_pxf_payload($data); | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||
| 44 | 344 | ▶ | die "Are you sure that your input is not already a bff?\n" | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 45 | unless validate_format( $phenopacket, 'pxf' ); | ||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||
| 47 | 344 | ▶ | if ( exists $phenopacket->{medical_actions} || exists $phenopacket->{meta_data} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $phenopacket->{"medical_actions"} or exists $phenopacket->{"meta_data"}
MC/DC50%1/2
exists $phenopacket->{"medical_actions"} or exists $phenopacket->{"meta_data"}
exists $phenopacket->{"medical_actions"}
exists $phenopacket->{"meta_data"}
Truth table66%2/3
A or B
A= exists $phenopacket->{"medical_actions"}B= exists $phenopacket->{"meta_data"}
| |||||||||||||||||||||||||||||||
| 48 | 2 | $phenopacket = { %{$phenopacket} }; | |||||||||||||||||||||||||||||
| 49 | 2 | _normalize_phenopacket_aliases($phenopacket); | |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||
| 52 | 344 | my $individual = map_pxf_to_individual( $self, $phenopacket, $cohort, $family ); | |||||||||||||||||||||||||||||
| 53 | 344 | $bundle->add_entity( individuals => $individual ); | |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||
| 55 | 344 | ▶ | if ( _context_requests_entity( $context, 'biosamples' ) ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 56 | 244 | for my $biosample ( @{ extract_pxf_biosamples( $self, $phenopacket, $individual->{id} ) } ) { | |||||||||||||||||||||||||||||
| 57 | 228 | $bundle->add_entity( biosamples => $biosample ); | |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||
| 61 | 344 | return $bundle; | |||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||
| 64 | 344 | ▶ | sub _extract_pxf_payload { | ||||||||||||||||||||||||||||
|
Subroutine
_extract_pxf_payload: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||
| 65 | 344 | my ($data) = @_; | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||
| 67 | my $phenopacket = | ||||||||||||||||||||||||||||||
| 68 | 344 | ▶ | exists $data->{phenopacket} ? $data->{phenopacket} : $data; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||
| 70 | 344 | ▶ | my $cohort = exists $data->{cohort} ? $data->{cohort} : undef; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 71 | 344 | ▶ | my $family = exists $data->{family} ? $data->{family} : undef; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||
| 73 | 344 | return ( $phenopacket, $cohort, $family ); | |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||
| 76 | 2 | ▶ | sub _normalize_phenopacket_aliases { | ||||||||||||||||||||||||||||
|
Subroutine
_normalize_phenopacket_aliases: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||
| 77 | 2 | my ($phenopacket) = @_; | |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||
| 79 | 2 | ▶ | if ( exists $phenopacket->{medical_actions} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 80 | 2 | $phenopacket->{medicalActions} = delete $phenopacket->{medical_actions}; | |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||
| 83 | 2 | ▶ | if ( exists $phenopacket->{meta_data} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 84 | 2 | $phenopacket->{metaData} = delete $phenopacket->{meta_data}; | |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||
| 87 | 2 | return 1; | |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||
| 90 | 344 | ▶ | sub _context_requests_entity { | ||||||||||||||||||||||||||||
|
Subroutine
_context_requests_entity: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 91 | 344 | my ( $context, $entity ) = @_; | |||||||||||||||||||||||||||||
| 92 | 344 | return scalar grep { $_ eq $entity } @{ $context->entities }; | |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||
| 95 | 137 | 1; | |||||||||||||||||||||||||||||