Skip to content

Commit bdee0e0

Browse files
authored
Merge pull request #17 from HBClab/ignore_nonbids
add check for bids formatting in download
2 parents 4960b87 + 1eb372f commit bdee0e0

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

xnat_downloader/cli/run.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def download_scan_unformatted(self, scan, dest, scan_repl_dict, bids_num_len,
285285
from glob import glob
286286
if scan not in self.scan_dict.keys():
287287
print('{scan} is not available for download'.format(scan=scan))
288-
return 1
288+
return 0
289289

290290
# No easy way to check for complete download
291291
# the session label (e.g. 20180613)
@@ -294,10 +294,10 @@ def download_scan_unformatted(self, scan, dest, scan_repl_dict, bids_num_len,
294294
scan_par = self.scan_dict[scan].parent()
295295
# the number id given to a scan (1, 2, 3, 400, 500)
296296
scan_id = self.scan_dict[scan].id()
297-
# TODO: change this hardcoding
298-
if scan_id == '1' or scan_id == '2':
299-
print('scan is a localizer or setup scan')
297+
if scan not in scan_repl_dict.keys():
298+
print('{scan} not a part of dictionary, skipping')
300299
return 0
300+
301301
bids_scan = scan_repl_dict[scan]
302302
# PU:task-rest_bold -> PU_task_rest_bold
303303
scan_fmt = re.sub(r'[\-\:\ \(\)]', '_', scan)
@@ -342,7 +342,11 @@ def download_scan_unformatted(self, scan, dest, scan_repl_dict, bids_num_len,
342342
scan_pattern = re.compile(SCAN_EXPR)
343343

344344
scan_pattern_dict = re.search(scan_pattern, bids_scan).groupdict()
345-
345+
# check if the modality is empty
346+
if scan_pattern_dict['modality'] is None:
347+
print('{scan} is not in BIDS, not converting'.format(scan=scan))
348+
return 0
349+
346350
# build up the bids directory
347351
bids_dir = os.path.join(dest, sub_name, ses_name, scan_pattern_dict['modality'])
348352

@@ -407,12 +411,10 @@ def download_scan(self, scan, dest):
407411
scan_par = self.scan_dict[scan].parent()
408412
# the number id given to a scan (1, 2, 3, 400, 500)
409413
scan_id = self.scan_dict[scan].id()
410-
if scan_id == '1' or scan_id == '2':
411-
print('scan is a localizer or setup scan')
412-
return 0
413414

414415
# PU:task-rest_bold -> PU_task_rest_bold
415-
scan_dir = scan_id + '-' + scan.replace('-', '_').replace(':', '_').replace(' ', '_')
416+
scan_fmt = re.sub(r'[\-\:\ \(\)]', '_', scan)
417+
scan_dir = scan_id + '-' + scan_fmt
416418

417419
dcm_outdir = os.path.join(dest, 'sourcedata')
418420
if not os.path.isdir(dcm_outdir):
@@ -448,7 +450,9 @@ def download_scan(self, scan, dest):
448450
# WARNING they will only be in the correct order if I am using
449451
# python3.6+
450452
scan_pattern_dict = re.search(scan_pattern, scan).groupdict()
451-
453+
if scan_pattern_dict['modality'] is None:
454+
print('{scan} is not in BIDS, not converting'.format(scan=scan))
455+
return 0
452456
# build up the bids directory
453457
bids_dir = os.path.join(dest, sub_name, ses_name, scan_pattern_dict['modality'])
454458

0 commit comments

Comments
 (0)