Created
August 2, 2018 19:37
-
-
Save mgxd/afbb0aa632e836b90d3100e72058014d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def create_key(template, outtype=('nii.gz'), annotation_classes=None): | |
if template is None or not template: | |
raise ValueError('Template must be a valid format string') | |
return (template, outtype, annotation_classes) | |
def infotodict(seqinfo): | |
"""Heuristic evaluator for determining which runs belong where | |
allowed template fields - follow python string module: | |
item: index within category | |
subject: participant id | |
seqitem: run number during scanning | |
subindex: sub index within group | |
""" | |
# anatomical | |
t1 = create_key('sub-{subject}/anat/sub-{subject}_acq-vNav_T1w') | |
t2 = create_key('sub-{subject}/anat/sub-{subject}_acq-vNav_T2w') | |
# field map (epi) | |
fmap_ap = create_key('sub-{subject}/fmap/sub-{subject}_dir-AP_run-{item:01d}_epi') | |
fmap_pa = create_key('sub-{subject}/fmap/sub-{subject}_dir-PA_run-{item:01d}_epi') | |
# BOLD | |
rest = create_key('sub-{subject}/func/sub-{subject}_task-rest_run-{item:01d}_bold') | |
dynloc = create_key('sub-{subject}/func/sub-{subject}_task-dynloc_run-{item:01d}_bold') | |
langloc = create_key('sub-{subject}/func/sub-{subject}_task-langloc_run-{item:01d}_bold') | |
wmspatial = create_key('sub-{subject}/func/sub-{subject}_task-wmspatial_run-{item:01d}_bold') | |
sart = create_key('sub-{subject}/func/sub-{subject}_task-sart_run-{item:01d}_bold') | |
# dwi | |
dwi98 = create_key('sub-{subject}/dwi/sub-{subject}_acq-dir98_run-{item:01d}_dwi') | |
dwi99 = create_key('sub-{subject}/dwi/sub-{subject}_acq-dir99_run-{item:01d}_dwi') | |
# sbref | |
dwi98sb = create_key('sub-{subject}/dwi/sub-{subject}_acq-dir98_run-{item:01d}_sbref') | |
dwi99sb = create_key('sub-{subject}/dwi/sub-{subject}_acq-dir99_run-{item:01d}_sbref') | |
restsb = create_key('sub-{subject}/func/sub-{subject}_task-rest_run-{item:01d}_sbref') | |
dynlocsb = create_key('sub-{subject}/func/sub-{subject}_task-dynloc_run-{item:01d}_sbref') | |
langlocsb = create_key('sub-{subject}/func/sub-{subject}_task-langloc_run-{item:01d}_sbref') | |
wmspatialsb = create_key('sub-{subject}/func/sub-{subject}_task-wmspatial_run-{item:01d}_sbref') | |
sartsb = create_key('sub-{subject}/func/sub-{subject}_task-sart_run-{item:01d}_sbref') | |
info = {t1: [], t2: [], # anatomical | |
fmap_ap: [], fmap_pa: [], # field maps | |
dwi98: [], dwi99: [], # diffusion | |
rest: [], dynloc: [], langloc: [], wmspatial: [], sart: [], # BOLD | |
dwi98sb: [], dwi99sb: [], restsb: [], dynlocsb: [], | |
langlocsb: [], wmspatialsb: [], sartsb: [], #SB reference | |
} | |
for idx, s in enumerate(seqinfo): | |
# helper definitions | |
is_sbref = 'SBRef' in s.series_description | |
# T1 | |
if (s.dim3 == 208) and (s.dim4 == 1): | |
if 'T1w' in s.protocol_name: | |
info[t1] = [s.series_id] | |
elif 'T2w' in s.protocol_name: | |
info[t2] = [s.series_id] | |
# field maps | |
elif (s.dim3 == 72) and (s.dim4 == 3) and ('fmap-epi' in s.protocol_name): | |
if 'dir-AP' in s.protocol_name: | |
info[fmap_ap].append(s.series_id) | |
elif 'dir-PA' in s.protocol_name: | |
info[fmap_pa].append(s.series_id) | |
# diffusion | |
elif 'dwi' in s.protocol_name: | |
if 'dir98' in s.protocol_name: | |
if s.dim4 == 99: | |
info[dwi98].append(s.series_id) | |
elif is_sbref: | |
info[dwi98sb].append(s.series_id) | |
elif 'dir99' in s.protocol_name: | |
if s.dim4 == 100: | |
info[dwi99].append(s.series_id) | |
elif is_sbref: | |
info[dwi99sb].append(s.series_id) | |
elif 'func-bold' in s.protocol_name: | |
if 'task-rest' in s.protocol_name: | |
if s.dim4 >= 400: | |
info[rest].append(s.series_id) | |
elif is_sbref: | |
info[restsb].append(s.series_id) | |
elif 'task-dynloc' in s.protocol_name: | |
if s.dim4 >= 280: | |
info[dynloc].append(s.series_id) | |
elif is_sbref: | |
info[dynlocsb].append(s.series_id) | |
elif 'task-langloc' in s.protocol_name: | |
if s.dim4 >= 465: | |
info[langloc].append(s.series_id) | |
elif is_sbref: | |
info[langlocsb].append(s.series_id) | |
elif 'task-wmspatial' in s.protocol_name: | |
if s.dim4 >= 500: | |
info[wmspatial].append(s.series_id) | |
elif is_sbref: | |
info[wmspatialsb].append(s.series_id) | |
elif 'task-sart' in s.protocol_name: | |
if s.dim4 >= 400: | |
info[sart].append(s.series_id) | |
elif is_sbref: | |
info[sartsb].append(s.series_id) | |
return info |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment