Skip to content

Commit

Permalink
Fix boolean in excluded
Browse files Browse the repository at this point in the history
  • Loading branch information
mrueda committed Dec 18, 2024
1 parent 3308e06 commit 444ef05
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 44 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Revision history for Perl distribution Convert-Pheno

0.26 2024-XX-XXT00:00:00Z (Manuel Rueda <[email protected]>)

- Fixed issue with excluded/negated boolean values in <pxf2bff>

0.25 2024-11-09T00:00:00Z (Manuel Rueda <[email protected]>)

- Changed the default 'ontology_term' from {id => 'NCIT:NA0000', label => 'NA'} to {id => 'NCIT:C126101', label => 'Not Available'}
Expand Down
27 changes: 13 additions & 14 deletions lib/Convert/Pheno/BFF.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ sub do_bff2pxf {
# START MAPPING TO PHENOPACKET V2 TERMS #
#########################################

# We need to shuffle a bit some Beacon v2 properties to be Phenopacket compliant
# Order of terms (not alphabetical) taken from:
# - https://phenopacket-schema.readthedocs.io/en/latest/phenopacket.html
# We need to shuffle a bit some Beacon v2 properties to be Phenopacket compliant
# Order of terms (not alphabetical) taken from:
# - https://phenopacket-schema.readthedocs.io/en/latest/phenopacket.html

# Initiate PXF structure
my $pxf;
Expand All @@ -55,9 +55,8 @@ sub do_bff2pxf {
#alternateIds => [],
#_age => $bff->{info}{age}
#timeAtLastEncounter => {},
vitalStatus => { status => 'ALIVE' }
, #["UNKNOWN_STATUS", "ALIVE", "DECEASED"]
sex => uc( $bff->{sex}{label} ),
vitalStatus => { status => 'ALIVE' }, #["UNKNOWN_STATUS", "ALIVE", "DECEASED"]
sex => uc( $bff->{sex}{label} ),

#taxonomy => {} ;
#_age => $bff->{info}{age}
Expand All @@ -76,13 +75,13 @@ sub do_bff2pxf {
# phenotypicFeatures
# ===================

# Assign transformed 'phenotypicFeatures' to $pxf, only if it's defined in $bff
$pxf->{phenotypicFeatures} = [
map {
{
type => delete $_->{featureType},
excluded => delete $_->{excluded}

#_notes => $_->{notes}
type => delete $_->{featureType}, # Rename 'featureType' to 'type'
excluded => (exists $_->{excluded} ? delete $_->{excluded} : JSON::PP::false),
# _notes => $_->{notes}
}
} @{ $bff->{phenotypicFeatures} }
]
Expand Down Expand Up @@ -153,7 +152,7 @@ sub do_bff2pxf {
routeOfAdministration => $_->{routeOfAdministration},
doseIntervals => $_->{doseIntervals}

#performed => { timestamp => exists $_->{dateOfProcedure} ? $_->{dateOfProcedure} : undef}
#performed => { timestamp => exists $_->{dateOfProcedure} ? $_->{dateOfProcedure} : undef}
}
}
} @{ $bff->{treatments} };
Expand All @@ -180,9 +179,9 @@ sub do_bff2pxf {
# exposures
# =========

# Can't be mapped as Sept-2023 from pxf-tools
# Message type "org.phenopackets.schema.v2.Phenopacket" has no field named "exposures" at "Phenopacket".
# Available Fields(except extensions): "['id', 'subject', 'phenotypicFeatures', 'measurements', 'biosamples', 'interpretations', 'diseases', 'medicalActions', 'files', 'metaData']" at line 22
# Can't be mapped as Sept-2023 from pxf-tools
# Message type "org.phenopackets.schema.v2.Phenopacket" has no field named "exposures" at "Phenopacket".
# Available Fields(except extensions): "['id', 'subject', 'phenotypicFeatures', 'measurements', 'biosamples', 'interpretations', 'diseases', 'medicalActions', 'files', 'metaData']" at line 22

# $pxf->{exposures} =
#
Expand Down
72 changes: 42 additions & 30 deletions lib/Convert/Pheno/PXF.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package Convert::Pheno::PXF;
use strict;
use warnings;
use autodie;
use feature qw(say);
use feature qw(say);
use Data::Dumper;
use Convert::Pheno::Default qw(get_defaults);
use Convert::Pheno::Mapping;
use Exporter 'import';
Expand All @@ -22,21 +23,21 @@ sub do_pxf2bff {
my ( $self, $data ) = @_;
my $sth = $self->{sth};

# *** IMPORTANT ****
# PXF three top-level elements are usually split in files:
# - phenopacket.json ( usually - 1 individual per file)
# - cohort.json (info on mutliple individuals)
# - family.json (info related to one or multiple individuals).
# These 3 files dont't contain their respective objects at the root level (/).
#
# However, top-elements might be combined into a single file (e.g., pxf.json),
# as a result, certain files may contain objects for top-level elements:
# - /phenopacket
# - /cohort
# - /family
#
# In this context, we only accept top-level phenopackets,
# while the other two types will be categorized as "info".
# *** IMPORTANT ****
# PXF three top-level elements are usually split in files:
# - phenopacket.json ( usually - 1 individual per file)
# - cohort.json (info on mutliple individuals)
# - family.json (info related to one or multiple individuals).
# These 3 files dont't contain their respective objects at the root level (/).
#
# However, top-elements might be combined into a single file (e.g., pxf.json),
# as a result, certain files may contain objects for top-level elements:
# - /phenopacket
# - /cohort
# - /family
#
# In this context, we only accept top-level phenopackets,
# while the other two types will be categorized as "info".

# We create cursors for top-level elements
# 1 - phenopacket (mandatory)
Expand All @@ -55,15 +56,15 @@ sub do_pxf2bff {
# Normalize the hash for medical_actions + medicalActions = medicalActions
if ( exists $phenopacket->{medical_actions} ) {

# NB: The delete function returns the value of the deleted key-value pair
# NB: The delete function returns the value of the deleted key-value pair
$phenopacket->{medicalActions} = delete $phenopacket->{medical_actions};
}

# CNAG files have 'meta_data' nomenclature, but PXF documentation uses 'metaData'
# We search for both 'meta_data' and 'metaData' and simply display the
# CNAG files have 'meta_data' nomenclature, but PXF documentation uses 'metaData'
# We search for both 'meta_data' and 'metaData' and simply display the
if ( exists $phenopacket->{meta_data} ) {

# NB: The delete function returns the value of the deleted key-value pair
# NB: The delete function returns the value of the deleted key-value pair
$phenopacket->{metaData} = delete $phenopacket->{meta_data};
}

Expand Down Expand Up @@ -92,10 +93,11 @@ sub do_pxf2bff {
$disease->{diseaseCode} = $disease->{term};
$disease->{ageOfOnset} = $disease->{onset}
if exists $disease->{onset};
$disease->{excluded} =
( exists $disease->{negated} || exists $disease->{excluded} )
? JSON::XS::true
: JSON::XS::false;

# Check and normalize keys if they exist
for (qw/excluded negated/) {
$disease->{$_} = $disease->{$_} if exists $disease->{$_};
}

# Clean analog terms if exist
for (qw/term onset/) {
Expand Down Expand Up @@ -253,12 +255,13 @@ sub do_pxf2bff {
# *** IMPORTANT ****
# In v2.0.0 BFF 'evidence' is object but in PXF is array of objects

$phenotypicFeature->{excluded} =
( exists $phenotypicFeature->{negated}
|| exists $phenotypicFeature->{excluded} )
? JSON::XS::true
: JSON::XS::false,
$phenotypicFeature->{featureType} = $phenotypicFeature->{type}
# Check and normalize keys if they exist
for (qw/excluded negated/) {
$phenotypicFeature->{excluded} = $phenotypicFeature->{$_}
if exists $phenotypicFeature->{$_};
}

$phenotypicFeature->{featureType} = $phenotypicFeature->{type}
if exists $phenotypicFeature->{type};

# Clean analog terms if exist
Expand Down Expand Up @@ -365,4 +368,13 @@ sub map_complexValue {
return 1;
}

# Function to normalize a value to a Boolean
sub to_boolean {

my $value = shift;
print Dumper $value;
return JSON::XS::true if $value && $value ne 'false'; # Non-empty string and not 'false'
return JSON::XS::false; # Empty, 'false', or undef
}

1;

0 comments on commit 444ef05

Please sign in to comment.