Skip to content

Commit

Permalink
✨ Convert family relations to P1+P2+rel
Browse files Browse the repository at this point in the history
  • Loading branch information
fiendish committed Dec 14, 2020
1 parent d201dfa commit 860f61e
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions kf_lib_data_ingest/target_api_plugins/kids_first_dataservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
requirements for format and content.
"""
from d3b_utils.requests_retry import Session
from pandas import DataFrame
from kf_lib_data_ingest.common import constants
from kf_lib_data_ingest.common.concept_schema import CONCEPT
from kf_lib_data_ingest.common.misc import (
Expand Down Expand Up @@ -549,6 +550,44 @@ class FamilyRelationship:
target_id_concept = CONCEPT.FAMILY_RELATIONSHIP.TARGET_SERVICE_ID
service_id_fields = {"kf_id", "participant1_id", "participant2_id"}

@classmethod
def transform_records_list(cls, records_list):
"""Convert PID+REL_TO_PROBAND into P1+REL_1_TO_2+P2"""
rdf = DataFrame(records_list)
if (
(CONCEPT.FAMILY_RELATIONSHIP.PERSON1.ID not in rdf)
and (CONCEPT.FAMILY_RELATIONSHIP.PERSON2.ID not in rdf)
and (CONCEPT.FAMILY_RELATIONSHIP.RELATION_FROM_1_TO_2 not in rdf)
and (CONCEPT.PARTICIPANT.RELATIONSHIP_TO_PROBAND in rdf)
):
relations = rdf.get(
[
CONCEPT.FAMILY.ID,
CONCEPT.PARTICIPANT.ID,
CONCEPT.PARTICIPANT.RELATIONSHIP_TO_PROBAND,
CONCEPT.FAMILY_RELATIONSHIP.VISIBLE,
]
).drop_duplicates()

side1 = relations[
relations[CONCEPT.PARTICIPANT.RELATIONSHIP_TO_PROBAND]
!= constants.RELATIONSHIP.PROBAND
].rename(
columns={
CONCEPT.PARTICIPANT.ID: CONCEPT.FAMILY_RELATIONSHIP.PERSON1.ID,
CONCEPT.PARTICIPANT.RELATIONSHIP_TO_PROBAND: CONCEPT.FAMILY_RELATIONSHIP.RELATION_FROM_1_TO_2,
}
)
side2 = relations[
relations[CONCEPT.PARTICIPANT.RELATIONSHIP_TO_PROBAND]
== "Proband"
][[CONCEPT.FAMILY.ID, CONCEPT.PARTICIPANT.ID]].rename(
columns={
CONCEPT.PARTICIPANT.ID: CONCEPT.FAMILY_RELATIONSHIP.PERSON2.ID,
}
)
return side1.merge(side2).to_dict("records")

@classmethod
def get_key_components(cls, record, get_target_id_from_record):
return {
Expand All @@ -557,7 +596,7 @@ def get_key_components(cls, record, get_target_id_from_record):
Participant,
{
CONCEPT.PARTICIPANT.ID: record[
CONCEPT.FAMILY_RELATIONSHIP.PERSON1
CONCEPT.FAMILY_RELATIONSHIP.PERSON1.ID
],
},
)
Expand All @@ -567,7 +606,7 @@ def get_key_components(cls, record, get_target_id_from_record):
Participant,
{
CONCEPT.PARTICIPANT.ID: record[
CONCEPT.FAMILY_RELATIONSHIP.PERSON2
CONCEPT.FAMILY_RELATIONSHIP.PERSON2.ID
],
},
)
Expand Down

0 comments on commit 860f61e

Please sign in to comment.