Skip to content

Commit

Permalink
Merge pull request #311 from dbkeator/master
Browse files Browse the repository at this point in the history
fixed bug in bidsmri2nidm.py where phenotype files with identical var…
  • Loading branch information
dbkeator authored Feb 16, 2022
2 parents f896e7e + 98ebd0c commit 0483cf9
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 207 deletions.
2 changes: 1 addition & 1 deletion nidm/experiment/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def get_metadata_dict(self,NIDM_TYPE):

return metadata

def serializeTurtle(self):
def serializeTurtle(self):
"""
Serializes graph to Turtle format
:return: text of serialized graph in Turtle format
Expand Down
173 changes: 92 additions & 81 deletions nidm/experiment/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,102 +1177,35 @@ def map_variables_to_terms(df,directory, assessment_name, output_file=None,json_
column_to_terms[current_tuple]['allowableValues'] = json_map[json_key[0]]['allowableValues']
print("allowableValues: %s" % column_to_terms[current_tuple]['allowableValues'])

if "isAbout" in json_map[json_key[0]]:
#check if we have a single isAbout or multiple...
if isinstance(json_map[json_key[0]]['isAbout'],list):
# isAbout is an empty list, do concept association if user asked for it else skip
if not json_map[json_key[0]]['isAbout']:
if associate_concepts:
# provide user with opportunity to associate a concept with this annotation
find_concept_interactive(column, current_tuple, column_to_terms, ilx_obj,
nidm_owl_graph=nidm_owl_graph)
# write annotations to json file so user can start up again if not doing whole file
write_json_mapping_file(column_to_terms, output_file, bids)
else:
pass
else:
# else create a new list
column_to_terms[current_tuple]['isAbout'] = []
# for each isAbout entry
for subdict in json_map[json_key[0]]['isAbout']:
# some entries may not have 'label' so check
if 'label' in subdict.keys():
column_to_terms[current_tuple]['isAbout'].append({'@id':subdict['@id'],'label':subdict['label']})
print("isAbout: %s = %s, %s = %s" %('@id',subdict['@id'],
'label',subdict['label']))
else:
column_to_terms[current_tuple]['isAbout'].append(
{'@id': subdict['@id']})
print("isAbout: %s = %s" % ('@id', subdict['@id']))
#for isabout_key,isabout_value in subdict.items():
# column_to_terms[current_tuple]['isAbout'].append({isabout_key:isabout_value})
# print("isAbout: %s = %s" %(isabout_key, isabout_value))
# if isAbout is a dictionary then we only have 1 isAbout...we'll upgrade it to a list
# to be consistent moving forward
else:
column_to_terms[current_tuple]['isAbout'] = []
if 'url' in json_map[json_key[0]]['isAbout'].keys():
if 'label' in json_map[json_key[0]]['isAbout'].keys():
column_to_terms[current_tuple]['isAbout'].append({'@id':
json_map[json_key[0]]['isAbout']['url'],'label':
json_map[json_key[0]]['isAbout']['label']})
else:
column_to_terms[current_tuple]['isAbout'].append({'@id':
json_map[json_key[0]]['isAbout']['url']})
else:
if 'label' in json_map[json_key[0]]['isAbout'].keys():
column_to_terms[current_tuple]['isAbout'].append({'@id':
json_map[json_key[0]]['isAbout']['@id'],'label':
json_map[json_key[0]]['isAbout']['label']})
else:
column_to_terms[current_tuple]['isAbout'].append({'@id':
json_map[json_key[0]]['isAbout']['@id']})


print("isAbout: %s = %s, %s = %s" %('@id',column_to_terms[current_tuple]['isAbout']['@id'],
'label',column_to_terms[current_tuple]['isAbout']['label']))
else:

# if user ran in mode where they want to associate concepts and this isn't the participant
# id field then associate concepts.
if match_participant_id_field(json_map[json_key[0]]['sourceVariable']):
column_to_terms[current_tuple]['isAbout'] =[]
column_to_terms[current_tuple]['isAbout'].append({'@id':Constants.NIDM_SUBJECTID.uri,
'label':Constants.NIDM_SUBJECTID.localpart})
write_json_mapping_file(column_to_terms, output_file, bids)
elif associate_concepts:
# provide user with opportunity to associate a concept with this annotation
find_concept_interactive(column,current_tuple,column_to_terms,ilx_obj,nidm_owl_graph=nidm_owl_graph)
# write annotations to json file so user can start up again if not doing whole file
write_json_mapping_file(column_to_terms,output_file,bids)


# added to support ReproSchema json format
if 'responseOptions' in json_map[json_key[0]]:
for subkey,subvalye in json_map[json_key[0]]['responseOptions'].items():
for subkey, subvalye in json_map[json_key[0]]['responseOptions'].items():
if 'valueType' in subkey:
if 'responseOptions' not in column_to_terms[current_tuple].keys():
column_to_terms[current_tuple]['responseOptions'] = {}

column_to_terms[current_tuple]['responseOptions']['valueType'] = \
json_map[json_key[0]]['responseOptions']['valueType']
print("valueType: %s" % column_to_terms[current_tuple]['responseOptions']['valueType'])
print("valueType: %s" % column_to_terms[current_tuple]['responseOptions'][
'valueType'])

elif 'minValue' in subkey:
if 'responseOptions' not in column_to_terms[current_tuple].keys():
column_to_terms[current_tuple]['responseOptions'] = {}

column_to_terms[current_tuple]['responseOptions']['minValue'] = \
json_map[json_key[0]]['responseOptions']['minValue']
print("minValue: %s" % column_to_terms[current_tuple]['responseOptions']['minValue'])
print(
"minValue: %s" % column_to_terms[current_tuple]['responseOptions']['minValue'])

elif 'maxValue' in subkey:
if 'responseOptions' not in column_to_terms[current_tuple].keys():
column_to_terms[current_tuple]['responseOptions'] = {}

column_to_terms[current_tuple]['responseOptions']['maxValue'] = \
json_map[json_key[0]]['responseOptions']['maxValue']
print("maxValue: %s" % column_to_terms[current_tuple]['responseOptions']['maxValue'])
print(
"maxValue: %s" % column_to_terms[current_tuple]['responseOptions']['maxValue'])
elif 'choices' in subkey:
if 'responseOptions' not in column_to_terms[current_tuple].keys():
column_to_terms[current_tuple]['responseOptions'] = {}
Expand All @@ -1299,14 +1232,16 @@ def map_variables_to_terms(df,directory, assessment_name, output_file=None,json_
# upgrade 'levels' to 'responseOptions'->'choices'
if 'responseOptions' not in column_to_terms[current_tuple].keys():
column_to_terms[current_tuple]['responseOptions'] = {}
column_to_terms[current_tuple]['responseOptions']['choices'] = json_map[json_key[0]]['levels']
print("choices: %s" %column_to_terms[current_tuple]['responseOptions']['choices'])
column_to_terms[current_tuple]['responseOptions']['choices'] = json_map[json_key[0]][
'levels']
print("choices: %s" % column_to_terms[current_tuple]['responseOptions']['choices'])
elif 'Levels' in json_map[json_key[0]]:
# upgrade 'levels' to 'responseOptions'->'choices'
if 'responseOptions' not in column_to_terms[current_tuple].keys():
column_to_terms[current_tuple]['responseOptions'] ={}
column_to_terms[current_tuple]['responseOptions']['choices'] = json_map[json_key[0]]['Levels']
print("levels: %s" %column_to_terms[current_tuple]['responseOptions']['choices'])
column_to_terms[current_tuple]['responseOptions'] = {}
column_to_terms[current_tuple]['responseOptions']['choices'] = json_map[json_key[0]][
'Levels']
print("levels: %s" % column_to_terms[current_tuple]['responseOptions']['choices'])

if 'valueType' in json_map[json_key[0]]:
# upgrade 'valueType' to 'responseOptions'->'valueType
Expand Down Expand Up @@ -1352,9 +1287,85 @@ def map_variables_to_terms(df,directory, assessment_name, output_file=None,json_
column_to_terms[current_tuple]['responseOptions']['unitCode'] = \
json_map[json_key[0]]['hasUnit']
print("unitCode: %s" % column_to_terms[current_tuple]['responseOptions']['unitCode'])
elif 'Units' in json_map[json_key[0]]:
# upgrade 'Units' to 'responseOptions'->'unitCode
if 'responseOptions' not in column_to_terms[current_tuple].keys():
column_to_terms[current_tuple]['responseOptions'] = {}
column_to_terms[current_tuple]['responseOptions']['unitCode'] = \
json_map[json_key[0]]['Units']
print("unitCode: %s" % column_to_terms[current_tuple]['responseOptions']['unitCode'])

if "isAbout" in json_map[json_key[0]]:
#check if we have a single isAbout or multiple...
if isinstance(json_map[json_key[0]]['isAbout'],list):
# isAbout is an empty list, do concept association if user asked for it else skip
if not json_map[json_key[0]]['isAbout']:
if associate_concepts:
# provide user with opportunity to associate a concept with this annotation
find_concept_interactive(column, current_tuple, column_to_terms, ilx_obj,
nidm_owl_graph=nidm_owl_graph)
# write annotations to json file so user can start up again if not doing whole file
write_json_mapping_file(column_to_terms, output_file, bids)
else:
pass
else:
# else create a new list
column_to_terms[current_tuple]['isAbout'] = []
# for each isAbout entry
for subdict in json_map[json_key[0]]['isAbout']:
# some entries may not have 'label' so check
if 'label' in subdict.keys():
column_to_terms[current_tuple]['isAbout'].append({'@id':subdict['@id'],'label':subdict['label']})
print("isAbout: %s = %s, %s = %s" %('@id',subdict['@id'],
'label',subdict['label']))
else:
column_to_terms[current_tuple]['isAbout'].append(
{'@id': subdict['@id']})
print("isAbout: %s = %s" % ('@id', subdict['@id']))
#for isabout_key,isabout_value in subdict.items():
# column_to_terms[current_tuple]['isAbout'].append({isabout_key:isabout_value})
# print("isAbout: %s = %s" %(isabout_key, isabout_value))
# if isAbout is a dictionary then we only have 1 isAbout...we'll upgrade it to a list
# to be consistent moving forward
else:
column_to_terms[current_tuple]['isAbout'] = []
if 'url' in json_map[json_key[0]]['isAbout'].keys():
if 'label' in json_map[json_key[0]]['isAbout'].keys():
column_to_terms[current_tuple]['isAbout'].append({'@id':
json_map[json_key[0]]['isAbout']['url'],'label':
json_map[json_key[0]]['isAbout']['label']})
else:
column_to_terms[current_tuple]['isAbout'].append({'@id':
json_map[json_key[0]]['isAbout']['url']})
else:
if 'label' in json_map[json_key[0]]['isAbout'].keys():
column_to_terms[current_tuple]['isAbout'].append({'@id':
json_map[json_key[0]]['isAbout']['@id'],'label':
json_map[json_key[0]]['isAbout']['label']})
else:
column_to_terms[current_tuple]['isAbout'].append({'@id':
json_map[json_key[0]]['isAbout']['@id']})


print("***************************************************************************************")
print("---------------------------------------------------------------------------------------")
print("isAbout: %s = %s, %s = %s" %('@id',column_to_terms[current_tuple]['isAbout']['@id'],
'label',column_to_terms[current_tuple]['isAbout']['label']))
else:

# if user ran in mode where they want to associate concepts and this isn't the participant
# id field then associate concepts.
if match_participant_id_field(json_map[json_key[0]]['sourceVariable']):
column_to_terms[current_tuple]['isAbout'] =[]
column_to_terms[current_tuple]['isAbout'].append({'@id':Constants.NIDM_SUBJECTID.uri,
'label':Constants.NIDM_SUBJECTID.localpart})
write_json_mapping_file(column_to_terms, output_file, bids)
elif associate_concepts:
# provide user with opportunity to associate a concept with this annotation
find_concept_interactive(column,current_tuple,column_to_terms,ilx_obj,nidm_owl_graph=nidm_owl_graph)
# write annotations to json file so user can start up again if not doing whole file
write_json_mapping_file(column_to_terms,output_file,bids)

print("***************************************************************************************")
print("---------------------------------------------------------------------------------------")

if (json_map is not None) and (len(json_key)>0):
continue
Expand Down
Loading

0 comments on commit 0483cf9

Please sign in to comment.