-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmeta.py
58 lines (52 loc) · 2.07 KB
/
meta.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
############################################
####### MRIGHT METADATA EDITOR FILE ######
####### BBSLab Jun 2024 ######
############################################
import os
import json
json_meta = os.path.join(os.path.dirname(os.path.realpath(__file__)), "meta.json")
def meta_create():
'''This function creates an empty meta.json file at the mright root'''
if os.path.isfile(json_meta) == False:
empty_dict = {
"dicom": "",
"dicom_list": "",
"bids_in": "",
"bids_out": "",
"heuristic": "",
"ses": "",
"recons": "",
"bold": "",
"qc": ""
}
with open(json_meta, 'a') as file:
json.dump(empty_dict, file)
def meta_func(var, msg, msg2="", ispath=True):
'''This function collects, updates and returns all the user-inputed data needed
for the MRIght pipeline. This data is stored at meta.json'''
with open(json_meta, 'r') as file:
data = json.load(file)
edit_data = False
if data[var] != "":
value_ok = False
while value_ok == False:
value_check = input("Is this {}?:\n{}\n(Y/N) ".format(msg, data[var])).upper()
if value_check == 'Y':
value_ok = True
elif value_check == 'N':
data[var] = input(r"Please, enter {}{}: ".format(msg, msg2))
if ispath == True:
data[var] = os.path.normpath(data[var]).strip(" '") # remove '' from string
edit_data = True
value_ok = True
else:
print("Please, enter a valid response.")
else:
data[var] = os.path.normpath(input(r"Please, enter {}{}: ".format(msg, msg2)).strip(" '"))
edit_data = True
if edit_data == True:
with open(json_meta, 'w') as file:
json.dump(data, file)
return data[var]