Skip to content

Commit

Permalink
added saftety asserts into pddfutils, until we have proper implementa…
Browse files Browse the repository at this point in the history
…tion for getting lists of attributes from Molgenis
  • Loading branch information
holubp committed Sep 29, 2023
1 parent 13408fe commit 31181dd
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pddfutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ def linearizeStructures (df : pd.DataFrame, rules : list):
def tidyCollectionDf (df : pd.DataFrame):
linearizeStructures(df, [('country','id'),('biobank','name'),('network','name'),('parent_collection','id')])
for col in ('order_of_magnitude','order_of_magnitude_donors'):
assert col in df, f"{col} expected in df"
if col in df:
df[col] = df[col].map(lambda x: "%d (%s)"%(x['id'],x['size']) if type(x) is dict else x)
for col in ('type','also_known','data_categories','quality','sex','age_unit','body_part_examined','imaging_modality','image_dataset_type','materials','storage_temperatures','sub_collections','data_use'):
assert col in df, f"{col} expected in df"
df[col] = df[col].map(lambda x: ",".join([e['id'] for e in x]) )
df['diagnosis_available'] = df['diagnosis_available'].map(lambda x: ",".join([re.sub('^urn:miriam:icd:','',e['id']) for e in x]) )
if col in df:
df[col] = df[col].map(lambda x: ",".join([e['id'] for e in x]) )
if 'diagnosis_available' in df:
df['diagnosis_available'] = df['diagnosis_available'].map(lambda x: ",".join([re.sub('^urn:miriam:icd:','',e['id']) for e in x]) )
extractContactDetails(df)
for c in ['contact']:
del df[c]
Expand All @@ -39,7 +39,6 @@ def tidyBiobankDf (df : pd.DataFrame):
linearizeStructures(df, [('country','id'), ('network','name'), ('covid19biobank','id'), ('capabilities','id'), ('quality','id')])
extractContactDetails(df)
for col in ['it_support_available', 'it_staff_size', 'is_available', 'his_available', 'partner_charter_signed', 'collections','contact']:
assert col in df, f"{col} expected in df"
try:
del df[col]
except KeyError:
Expand Down

0 comments on commit 31181dd

Please sign in to comment.