lib/Convert/Pheno/JSONLD.pm

filter: Statementstmt 97.3% 36 / 37 Branchbran 66.6% 8 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 2 totaltotal 88.3% 53 / 60 CC 7 SCAR 8.0
CC
7
Cov
90%
_context_for
3.1
_compact_document
3.1
_load_jsonld
3.0
CRAP 2.2
« lib/Convert/Pheno/OMOP/ToBFF.pm ↑ Summary lib/Convert/Pheno/Source/Tabular.pm »
1 package Convert::Pheno::JSONLD;
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 136 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 136 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 136 our @EXPORT_OK = qw(do_bff2jsonld do_pxf2jsonld);
9  
10 136 my $JSONLD_AVAILABLE;
11  
12 18 ▶sub _load_jsonld {
Subroutine _load_jsonld: called CC=3 SCAR=11.0
13 18 ▶ return 1 if $JSONLD_AVAILABLE;
Branch: 1 branch
BranchTrueFalseTotal
if $JSONLD_AVAILABLE 16 2 18
14  
15 2 eval {
16 2 require JSONLD;
17 2 1;
18 };
19 2 ▶ croak "JSONLD Perl module is required but could not be loaded: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
20  
21 2 return $JSONLD_AVAILABLE = 1;
22 }
23  
24 18 ▶sub _context_for {
Subroutine _context_for: called CC=3 SCAR=11.3
25 18 my ($format) = @_;
26  
27 18 my %common = (
28 '@vocab' => 'https://ncithesaurus.nci.nih.gov/ncitbrowser/',
29 'HP' => 'http://purl.obolibrary.org/obo/HP_',
30 'OMIM' => 'http://purl.obolibrary.org/obo/OMIM_',
31 'id' => 'id',
32 'type' => 'type',
33 );
34  
35 return {
36 18 ▶ %common,
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "bff" 4 14 18
37 'bff' =>
38 'https://github.com/ga4gh-beacon/beacon-v2/tree/main/models/src/beacon-v2-default-model/individuals',
39 'subject' => 'bff:subject',
40 'phenotypicFeatures' => 'bff:phenotypicFeatures',
41 'description' => 'bff:description',
42 'severity' => 'bff:severity',
43 'diagnosis' => 'bff:diagnosis',
44 'disease' => 'bff:disease',
45 'ageAtCollection' => 'bff:ageAtCollection',
46 'sex' => 'bff:sex',
47 'MALE' => 'bff:MALE',
48 } if $format eq 'bff';
49  
50 return {
51 14 ▶ %common,
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "pxf" 14 0 14
52 'pxf' =>
53 'https://phenopacket-schema.readthedocs.io/en/latest/schema.html#version-2-0/',
54 'subject' => 'pxf:subject',
55 'phenotypicFeatures' => 'pxf:phenotypicFeatures',
56 'description' => 'pxf:description',
57 'severity' => 'pxf:severity',
58 'diagnosis' => 'pxf:diagnosis',
59 'disease' => 'pxf:disease',
60 'ageAtCollection' => 'pxf:ageAtCollection',
61 'sex' => 'pxf:sex',
62 'MALE' => 'pxf:MALE',
63 } if $format eq 'pxf';
64  
65 0 croak "Unsupported JSON-LD context format <$format>";
66 }
67  
68 18 ▶sub _compact_document {
Subroutine _compact_document: called CC=3 SCAR=11.2
69 18 my ( $document, $context ) = @_;
70  
71 18 ▶ return unless defined $document;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $document 0 18 18
72  
73 18 ▶ croak 'JSON-LD conversion expects a hashref document'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $document eq "HASH" 0 18 18
74 unless ref($document) eq 'HASH';
75  
76 18 _load_jsonld();
77  
78 18 my $jld = JSONLD->new();
79 18 $document->{'@context'} = $context;
80  
81 18 return $jld->compact($document);
82 }
83  
84 ###############
85 ###############
86 # BFF2JSONLD #
87 ###############
88 ###############
89  
90 4 ▶sub do_bff2jsonld {
Subroutine do_bff2jsonld: called CC=1 SCAR=0.0
Pod undocumented
91 4 my ( $self, $bff ) = @_;
92 4 return _compact_document( $bff, _context_for('bff') );
93 }
94  
95 ###############
96 ###############
97 # PXF2JSONLD #
98 ###############
99 ###############
100  
101 14 ▶sub do_pxf2jsonld {
Subroutine do_pxf2jsonld: called CC=1 SCAR=0.0
Pod undocumented
102 14 my ( $self, $pxf ) = @_;
103 14 return _compact_document( $pxf, _context_for('pxf') );
104 }
105  
106 136 1;
« lib/Convert/Pheno/OMOP/ToBFF.pm ↑ Summary lib/Convert/Pheno/Source/Tabular.pm »