Skip to content

Commit

Permalink
[FIX] Address MEG issue with .ds format
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Levitas committed Feb 21, 2024
1 parent 804d196 commit e4fb1b9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 16 additions & 6 deletions handler/ezBIDS_core/ezBIDS_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,9 @@ def fix_multiple_dots(uploaded_img_list):
fix = True
ext = '.json'
elif img_file.endswith(tuple(MEG_extensions)) and img_file.count('.') > 1: # for MEG
fix = True
ext = img_file.split('.')[-1]
if not img_file.endswith('.ds'):
fix = True
ext = '.' + img_file.split('.')[-1]
else:
pass

Expand Down Expand Up @@ -385,10 +386,13 @@ def generate_MEG_json_sidecars(uploaded_img_list):
from mne_bids.config import MANUFACTURERS

for meg in MEG_img_files:
ext = Path(meg).suffix
if meg.endswith('.ds'):
ext = '.ds'
else:
ext = Path(meg).suffix

fname = f"{DATA_DIR}/{meg}"
json_output_name = fname.split(".")[0] + ".json"
json_output_name = fname.split(ext)[0] + ".json"
raw = mne.io.read_raw(fname, verbose=0)
acquisition_date_time = raw.info["meas_date"].strftime("%Y-%m-%dT%H:%M:%S.%f")
acquisition_date = acquisition_date_time.split("T")[0]
Expand Down Expand Up @@ -481,6 +485,8 @@ def modify_uploaded_dataset_list(uploaded_img_list):
ext = '.nii.gz'
elif img_file.endswith('.v.gz'):
ext = '.v.gz'
elif img_file.endswith('.ds'):
ext = '.ds'
else:
ext = Path(img_file).suffix

Expand Down Expand Up @@ -918,6 +924,8 @@ def generate_dataset_list(uploaded_files_list, exclude_data):
ext = '.nii.gz'
elif img_file.endswith('.v.gz'):
ext = '.v.gz'
elif img_file.endswith('.ds'):
ext = '.ds'
else:
ext = Path(img_file).suffix

Expand Down Expand Up @@ -2931,7 +2939,10 @@ def modify_objects_info(dataset_list):
"pngPaths": [],
"headers": protocol["headers"]})
elif item.endswith(tuple(MEG_extensions)):
name = Path(item).suffix
if item.endswith('.ds'):
name = '.ds'
else:
name = Path(item).suffix
items.append({"path": item,
"name": name,
"pngPaths": [],
Expand Down Expand Up @@ -3028,7 +3039,6 @@ def extract_series_info(dataset_list_unique_series):
uploaded_img_list = fix_multiple_dots(uploaded_img_list)

# Generate MEG json files, if MEG data was provided
# uploaded_img_list = generate_MEG_json_sidecars(uploaded_img_list)
generate_MEG_json_sidecars(uploaded_img_list)

# Filter uploaded files list for files that ezBIDS can't use and check for ezBIDS configuration file
Expand Down
4 changes: 3 additions & 1 deletion handler/find_img_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ def find_img_data(dir):
find_cmd = os.popen(f"find . -maxdepth 9 -type {type_search} -name '{meg_ext}'").read()
if find_cmd != '':
meg_data_list.append(find_cmd)

if len(meg_data_list):
meg_data_list = [x for x in meg_data_list[0].split('\n') if x != '']
# TODO - won't this remove different extensions?
meg_data_list = [x for x in meg_data_list[0].split('\n') if x != '' and 'hz.ds' not in x]

# Save the MRI, PET, MEG, and NIfTI lists (if they exist) to separate files
file = open(f'{root}/dcm2niix.list', 'w')
Expand Down

0 comments on commit e4fb1b9

Please sign in to comment.