Skip to content

Commit 6e74de6

Browse files
committed
changed subject key finding to support NIDM JSON map
1 parent fe42841 commit 6e74de6

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/nidm/experiment/tools/csv2nidm.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,23 @@ def main():
193193
id_field = None
194194
for key, value in column_to_terms.items():
195195
if "isAbout" in value:
196-
for isabout_key, isabout_value in value["isAbout"].items():
197-
if isabout_key in ("url", "@id"):
198-
if isabout_value == Constants.NIDM_SUBJECTID._uri:
199-
key_tuple = eval(key)
200-
# id_field=key
201-
id_field = key_tuple.variable
202-
# make sure id_field is a string for zero-padded subject ids
203-
# re-read data file with constraint that key field is read as string
204-
df = pd.read_csv(args.csv_file, dtype={id_field: str})
205-
break
196+
for concept in value["isAbout"]:
197+
for isabout_key, isabout_value in concept.items():
198+
if isabout_key in ("url", "@id"):
199+
if isabout_value == Constants.NIDM_SUBJECTID._uri:
200+
# get variable name from NIDM JSON file format:
201+
# DD(source=assessment_name, variable=column)
202+
id_field = (
203+
key.split("variable")[1]
204+
.split("=")[1]
205+
.split(")")[0]
206+
.lstrip("'")
207+
.rstrip("'")
208+
)
209+
# make sure id_field is a string for zero-padded subject ids
210+
# re-read data file with constraint that key field is read as string
211+
df = pd.read_csv(args.csv_file, dtype={id_field: str})
212+
break
206213

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

0 commit comments

Comments
 (0)