Skip to content

Commit

Permalink
Merge pull request #396 from dbkeator/master
Browse files Browse the repository at this point in the history
changed subject key finding to support NIDM JSON map
  • Loading branch information
dbkeator authored Feb 9, 2024
2 parents 46a044e + 12ce060 commit eb0fa56
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ install_requires =
numpy >= 1.16.5
ontquery ~= 0.2.3
pandas
pyarrow
patsy
prov
pybids >= 0.12.4
Expand All @@ -44,7 +45,7 @@ install_requires =
pyld >= 1.0.5, <3.0
python-dateutil ~= 2.0
rapidfuzz
rdflib
rdflib ~= 6.3.2
requests
scikit-learn
scipy
Expand Down
27 changes: 17 additions & 10 deletions src/nidm/experiment/tools/csv2nidm.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,23 @@ def main():
id_field = None
for key, value in column_to_terms.items():
if "isAbout" in value:
for isabout_key, isabout_value in value["isAbout"].items():
if isabout_key in ("url", "@id"):
if isabout_value == Constants.NIDM_SUBJECTID._uri:
key_tuple = eval(key)
# id_field=key
id_field = key_tuple.variable
# make sure id_field is a string for zero-padded subject ids
# re-read data file with constraint that key field is read as string
df = pd.read_csv(args.csv_file, dtype={id_field: str})
break
for concept in value["isAbout"]:
for isabout_key, isabout_value in concept.items():
if isabout_key in ("url", "@id"):
if isabout_value == Constants.NIDM_SUBJECTID._uri:
# get variable name from NIDM JSON file format:
# DD(source=assessment_name, variable=column)
id_field = (
key.split("variable")[1]
.split("=")[1]
.split(")")[0]
.lstrip("'")
.rstrip("'")
)
# make sure id_field is a string for zero-padded subject ids
# re-read data file with constraint that key field is read as string
df = pd.read_csv(args.csv_file, dtype={id_field: str})
break

# if we couldn't find a subject ID field in column_to_terms, ask user
if id_field is None:
Expand Down

0 comments on commit eb0fa56

Please sign in to comment.