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 """ # call cfmm for general labelling and get dictionary info = cfmminfodict(seqinfo) ContRecog = create_key( 'sub-{subject}/func/sub-{subject}_task-ContRecog_run-{item:02d}_bold') ContRecog_sbref = create_key( 'sub-{subject}/func/sub-{subject}_task-ContRecog_run-{item:02d}_sbref') info[ContRecog] = [] info[ContRecog_sbref] = [] for idx, s in enumerate(seqinfo): #func continuous recognition memory task if ('cmrr_ep' in s.protocol_name and 'test' not in s.protocol_name): if (s.dim4 == 1 and 'SBRef' in (s.series_description).strip()): info[ContRecog_sbref].append({'item': s.series_id}) elif (s.dim4 > 1): info[ContRecog].append({'item': s.series_id}) return info
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 """ # call cfmm for general labelling and get dictionary info = cfmminfodict(seqinfo) # create functional keys bold_mag = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-rest_part-mag_run-{item:02d}_bold' ) bold_phase = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-rest_part-phase_run-{item:02d}_bold' ) bold_sbref = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-rest_run-{item:02d}_sbref' ) # add functional keys to the dictionary info[bold_mag] = [] info[bold_phase] = [] info[bold_sbref] = [] for idx, s in enumerate(seqinfo): #bold if ('bold' in s.protocol_name): if (s.dim4 > 2 and ('M' in s.image_type[2].strip())): info[bold_mag].append({'item': s.series_id}) if (s.dim4 > 2 and ('P' in s.image_type[2].strip())): info[bold_phase].append({'item': s.series_id}) if (s.dim4 <= 2 and 'SBRef' in (s.series_description).strip()): info[bold_sbref].append({'item': s.series_id}) return info
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 """ # call cfmm for general labelling and get dictionary info = cfmminfodict(seqinfo) # create functional keys task_ge = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-{task}_acq-ge_part-mag_run-{run}_bold' ) task_ge_phase = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-{task}_acq-ge_part-phase_run-{run}_bold' ) task_se = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-{task}_acq-se_run-{run}_bold' ) # add functional keys to the dictionary info[task_ge] = [] info[task_ge_phase] = [] info[task_se] = [] # Now we loop through seqinfo again to grab just the functional files # the tasks are told apart by the length of the runs (will also ignore partial runs) # also save acquisition time in mag and phase list magacq = [] semagacq = [] phaseacq = [] for idx, s in enumerate(seqinfo): if ('bold' in s.protocol_name): if ('se' in (s.sequence_name).strip()): if (s.dim4 == 102): if ('M' in (s.image_type[2].strip())): info[task_se].append({ 'item': s.series_id, 'acqtime': s.acquisition_time, 'task': 'checkerboard' }) semagacq.append(float(s.acquisition_time)) elif (s.dim4 == 64): if ('M' in (s.image_type[2].strip())): info[task_se].append({ 'item': s.series_id, 'acqtime': s.acquisition_time, 'task': 'visuotopy' }) semagacq.append(float(s.acquisition_time)) elif ('fid' in (s.sequence_name).strip()): if (s.dim4 == 102): if ( ('M' == (s.image_type[2].strip())) or (('FMRI' in (s.image_type[2].strip())) and ('mbep2d' != s.series_description[0:6])) ): #If realtime was on phase will start with mb and mag with act info[task_ge].append({ 'item': s.series_id, 'acqtime': s.acquisition_time, 'task': 'checkerboard' }) magacq.append(float(s.acquisition_time)) elif ( ('P' == (s.image_type[2].strip())) or (('FMRI' in (s.image_type[2].strip())) and ('mbep2d' == s.series_description[0:6])) ): #If realtime was on phase will start with mb and mag with act info[task_ge_phase].append({ 'item': s.series_id, 'acqtime': s.acquisition_time, 'task': 'checkerboard' }) phaseacq.append(float(s.acquisition_time)) elif (s.dim4 == 64): if (('M' == (s.image_type[2].strip())) or (('FMRI' in (s.image_type[2].strip())) and ('mbep2d' != s.series_description[0:6]))): info[task_ge].append({ 'item': s.series_id, 'acqtime': s.acquisition_time, 'task': 'visuotopy' }) magacq.append(float(s.acquisition_time)) elif (('P' == (s.image_type[2].strip())) or (('FMRI' in (s.image_type[2].strip())) and ('mbep2d' == s.series_description[0:6]))): info[task_ge_phase].append({ 'item': s.series_id, 'acqtime': s.acquisition_time, 'task': 'visuotopy' }) phaseacq.append(float(s.acquisition_time)) # Now we have all the sequences in the right bins we need to link up the magnitudes and phases from the GE to ensure the runs match # find the unique magnitude runs and sort by start times magtimes = list(sorted(set(magacq))) semagtimes = list(sorted(set(semagacq))) # find the pairs of indicies corresponding to the same run magind = [None] * len(magtimes) phaseind = [None] * len(magtimes) for i in xrange(len(magtimes)): #find last phase file with that acq time (vunerable: assumes last phase recon is correct recon) magind[i] = magacq.index(magtimes[i]) try: phaseind[i] = len(phaseacq) - 1 - (phaseacq[::-1]).index( magtimes[i]) except: phaseind[i] = -1 # no phase run found do not append it # put the results sorted back into info maginfo = info[task_ge] phaseinfo = info[task_ge_phase] seinfo = info[task_se] info[task_se] = [] info[task_ge] = [] info[task_ge_phase] = [] for i in xrange(len(semagtimes)): print(i) info[task_se].append(seinfo[i]) info[task_se][i]['run'] = str(i + 1).zfill(2) for i in xrange(len(magind)): info[task_ge].append(maginfo[magind[i]]) info[task_ge][i]['run'] = str(i + 1).zfill(2) if phaseind[i] > -1: # if no run found phase is not appended phaseinfo[phaseind[i]]['run'] = str(i + 1).zfill(2) info[task_ge_phase].append(phaseinfo[phaseind[i]]) return info
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 """ # call cfmm for general labelling and get dictionary info = cfmminfodict(seqinfo) task_intact = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-intact_run-{item:02d}_bold' ) task_scrambled = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-scrambled_run-{item:02d}_bold' ) task_soundcheck = create_key( 'sourcedata/soundcheck_bold/{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-soundcheck_run-{item:02d}_bold' ) discarded = create_key( 'sourcedata/discarded_bold/{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-{task}_run-{item:02d}_bold' ) info[task_intact] = [] info[task_scrambled] = [] info[task_soundcheck] = [] info[discarded] = [] for idx, s in enumerate(seqinfo): if ('bold' in s.protocol_name or 'tasking_state' in s.series_description or 'mbep2d' in (s.series_description).strip() or 'ep_bold' in (s.series_description).strip() and not ('diff' in s.protocol_name or 'DWI' in s.series_description)): if ('SBRef' in (s.series_description).strip()): print('skipping sbref') else: #check what task it is if ('soundcheck' in (s.series_description).strip().lower()): taskname = 'soundcheck' taskvols = 40 if (s.dim4 < taskvols): info[discarded].append({ 'item': s.series_id, 'task': taskname }) elif (s.dim4 == taskvols): info[task_soundcheck].append({ 'item': s.series_id, 'task': taskname }) elif ('intact' in (s.series_description).strip().lower()): taskname = 'intact' taskvols = 320 if (s.dim4 < taskvols): info[discarded].append({ 'item': s.series_id, 'task': taskname }) elif (s.dim4 == taskvols): info[task_intact].append({ 'item': s.series_id, 'task': taskname }) elif ('scrambled' in (s.series_description).strip().lower()): taskname = 'scrambled' taskvols = 320 if (s.dim4 < taskvols): info[discarded].append({ 'item': s.series_id, 'task': taskname }) elif (s.dim4 == taskvols): info[task_scrambled].append({ 'item': s.series_id, 'task': taskname }) else: continue return info
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 """ # call cfmm for general labelling and get dictionary info = cfmminfodict(seqinfo) rest = create_key( 'sub-{subject}/func/sub-{subject}_task-rest_run-{item:02d}_bold') rest_sbref = create_key( 'sub-{subject}/func/sub-{subject}_task-rest_run-{item:02d}_sbref') rest_psf = create_key( 'sub-{subject}/func/sub-{subject}_task-rest_acq-psf_run-{item:02d}_bold' ) rest_psf_dico = create_key( 'sub-{subject}/func/sub-{subject}_task-rest_acq-psf_rec-dico_run-{item:02d}_bold' ) movie = create_key( 'sub-{subject}/func/sub-{subject}_task-movie_run-{item:02d}_bold') movie_sbref = create_key( 'sub-{subject}/func/sub-{subject}_task-movie_run-{item:02d}_sbref') fmap_PA = create_key('sub-{subject}/fmap/sub-{subject}_dir-PA_epi') fmap_PA_sbref = create_key('sub-{subject}/fmap/sub-{subject}_dir-PA_sbref') info[rest] = [] info[rest_sbref] = [] info[rest_psf] = [] info[rest_psf_dico] = [] info[movie] = [] info[movie_sbref] = [] info[fmap_PA] = [] info[fmap_PA_sbref] = [] for idx, s in enumerate(seqinfo): #rs func (incl opp phase enc) if ('Movie' in (s.series_description).strip()): if (s.dim4 == 1 and 'SBRef' in (s.series_description).strip()): info[movie_sbref].append({'item': s.series_id}) elif (s.dim4 > 1): info[movie].append({'item': s.series_id}) elif ('bold' in s.protocol_name or 'resting_state' in s.series_description or 'mbep2d' in (s.series_description).strip() or 'ep_bold' in (s.series_description).strip()): if (s.dim4 == 1 and 'SBRef' in (s.series_description).strip()): info[rest_sbref].append({'item': s.series_id}) elif (s.dim4 > 1): info[rest].append({'item': s.series_id}) if ('mi_ep2d' in (s.series_description).strip() and s.dim4 > 1): if ('DICO' in (s.image_type[4].strip())): info[rest_psf_dico].append({'item': s.series_id}) else: info[rest_psf].append({'item': s.series_id}) if ('PA' in (s.series_description).strip()): if (s.dim4 == 1): if 'SBRef' in (s.series_description).strip(): info[fmap_PA_sbref].append({'item': s.series_id}) else: info[fmap_PA].append({'item': s.series_id}) return info
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 """ # call cfmm for general labelling and get dictionary info = cfmminfodict(seqinfo) task_ge = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-{task}_part-mag_run-{item:02d}_bold' ) task_ge_phase = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-{task}_part-phase_run-{item:02d}_bold' ) task_sbref = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-{task}_run-{item:02d}_sbref' ) gre_diff = create_key( '{bids_subject_session_dir}/fmap/{bids_subject_session_prefix}_run-{item:02d}_phasediff' ) gre_magnitude = create_key( '{bids_subject_session_dir}/fmap/{bids_subject_session_prefix}_run-{item:02d}_magnitude' ) fmap_diff = create_key( '{bids_subject_session_dir}/fmap/{bids_subject_session_prefix}_phasediff' ) fmap_magnitude = create_key( '{bids_subject_session_dir}/fmap/{bids_subject_session_prefix}_magnitude' ) del info[fmap_diff] del info[fmap_magnitude] info[task_ge] = [] info[task_ge_phase] = [] info[task_sbref] = [] info[gre_diff] = [] info[gre_magnitude] = [] magacq = [] phaseacq = [] for idx, s in enumerate(seqinfo): print(idx, s.series_description, s.image_type) if ('bold' in (s.series_description).strip()): if s.dim4 == 1 and 'SBRef' in (s.series_description).strip( ) and 'M' == s.image_type[2].strip(): info[task_sbref].append({'item': s.series_id, 'task': 'rest'}) elif (s.dim4 > 1): if 'M' == s.image_type[2].strip(): timestr = s.series_uid.split('.')[-4][8:14] acquisition_time = (int(timestr[0:2]) * 60 + int( timestr[2:4])) * 60 + int(timestr[4:]) info[task_ge].append({ 'item': s.series_id, 'acqtime': acquisition_time, 'task': 'rest' }) magacq.append(acquisition_time) print(idx, 'is magnitude bold') elif 'P' == s.image_type[2].strip(): print(idx, 'is phase bold') timestr = s.series_uid.split('.')[-4][8:14] acquisition_time = (int(timestr[0:2]) * 60 + int( timestr[2:4])) * 60 + int(timestr[4:]) info[task_ge_phase].append({ 'item': s.series_id, 'acqtime': acquisition_time, 'task': 'rest' }) phaseacq.append(acquisition_time) if ('field_mapping' in s.protocol_name): if (s.dim4 == 1 and 'gre_field_mapping' in (s.series_description).strip()): if ('P' in (s.image_type[2].strip())): info[gre_diff].append({'item': s.series_id}) if ('M' in (s.image_type[2].strip())): info[gre_magnitude].append({'item': s.series_id}) # Now we have all the sequences in the right bins we need to link up the magnitudes and phases from the GE to ensure the runs match # find the unique magnitude runs and sort by start times print(magacq) magtimes = list(sorted(set(magacq))) # find the pairs of indicies corresponding to the same run magind = [None] * len(magtimes) phaseind = [None] * len(magtimes) for i in range(len(magtimes)): #find last phase file with that acq time (vunerable: assumes last phase recon is correct recon) magind[i] = magacq.index(magtimes[i]) try: phaseind[i] = len(phaseacq) - 1 - (phaseacq[::-1]).index( magtimes[i]) except: phaseind[i] = -1 # no phase run found do not append it # put the results sorted back into info maginfo = info[task_ge] phaseinfo = info[task_ge_phase] print(maginfo) print(phaseinfo) print(magind, phaseind) info[task_ge] = [] info[task_ge_phase] = [] for i in range(len(magind)): info[task_ge].append(maginfo[magind[i]]) info[task_ge][i]['run'] = str(i + 1).zfill(2) if phaseind[i] > -1: # if no run found phase is not appended phaseinfo[phaseind[i]]['run'] = str(i + 1).zfill(2) info[task_ge_phase].append(phaseinfo[phaseind[i]]) print(info[task_ge]) print(info[task_ge_phase]) return info
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 """ # call cfmm for general labelling and get dictionary info = cfmminfodict(seqinfo) loc = create_key( 'sub-{subject}/func/sub-{subject}_task-loc_run-{item:02d}_bold') loc_sbref = create_key( 'sub-{subject}/func/sub-{subject}_task-loc_run-{item:02d}_sbref') loc_PA = create_key( 'sub-{subject}/func/sub-{subject}_task-loc_acq-PA_run-{item:02d}_bold') loc_PA_sbref = create_key( 'sub-{subject}/func/sub-{subject}_task-loc_acq-PA_run-{item:02d}_sbref' ) loc_AP = create_key( 'sub-{subject}/func/sub-{subject}_task-loc_acq-AP_run-{item:02d}_bold') loc_AP_sbref = create_key( 'sub-{subject}/func/sub-{subject}_task-loc_acq-AP_run-{item:02d}_sbref' ) nback = create_key( 'sub-{subject}/func/sub-{subject}_task-nback_run-{item:02d}_bold') nback_sbref = create_key( 'sub-{subject}/func/sub-{subject}_task-nback_run-{item:02d}_sbref') nback_PA = create_key( 'sub-{subject}/func/sub-{subject}_task-nback_acq-PA_run-{item:02d}_bold' ) nback_PA_sbref = create_key( 'sub-{subject}/func/sub-{subject}_task-nback_acq-PA_run-{item:02d}_sbref' ) nback_AP = create_key( 'sub-{subject}/func/sub-{subject}_task-nback_acq-AP_run-{item:02d}_bold' ) nback_AP_sbref = create_key( 'sub-{subject}/func/sub-{subject}_task-nback_acq-AP_run-{item:02d}_sbref' ) info[loc] = [] info[loc_sbref] = [] info[loc_PA] = [] info[loc_PA_sbref] = [] info[loc_AP] = [] info[loc_AP_sbref] = [] info[nback] = [] info[nback_sbref] = [] info[nback_PA] = [] info[nback_PA_sbref] = [] info[nback_AP] = [] info[nback_AP_sbref] = [] for idx, s in enumerate(seqinfo): #func localizer and nback tasks (incl opp phase enc) if ('loc' in (s.protocol_name).strip()): if ('_PA' in (s.series_description).strip()): if (s.dim4 == 1 and 'SBRef' in (s.series_description).strip()): info[loc_PA_sbref].append({'item': s.series_id}) elif (s.dim4 > 1): info[loc_PA].append({'item': s.series_id}) elif ('_AP' in (s.series_description).strip()): if (s.dim4 == 1 and 'SBRef' in (s.series_description).strip()): info[loc_AP_sbref].append({'item': s.series_id}) elif (s.dim4 > 1): info[loc_AP].append({'item': s.series_id}) else: if (s.dim4 == 1 and 'SBRef' in (s.series_description).strip()): info[loc_sbref].append({'item': s.series_id}) elif (s.dim4 > 1): info[loc].append({'item': s.series_id}) elif ('ep_bold' in s.protocol_name): if ('_PA' in (s.series_description).strip()): if (s.dim4 == 1 and 'SBRef' in (s.series_description).strip()): info[nback_PA_sbref].append({'item': s.series_id}) elif (s.dim4 > 1): info[nback_PA].append({'item': s.series_id}) elif ('_AP' in (s.series_description).strip()): if (s.dim4 == 1 and 'SBRef' in (s.series_description).strip()): info[nback_AP_sbref].append({'item': s.series_id}) elif (s.dim4 > 1): info[nback_AP].append({'item': s.series_id}) else: if (s.dim4 == 1 and 'SBRef' in (s.series_description).strip()): info[nback_sbref].append({'item': s.series_id}) elif (s.dim4 > 1): info[nback].append({'item': s.series_id}) return info
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 """ # call cfmm for general labelling and get dictionary info = cfmminfodict(seqinfo) movie = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-movie_run-{item:02d}_bold' ) movie_sbref = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-movie_run-{item:02d}_sbref' ) rest = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-rest_run-{item:02d}_bold' ) rest_sbref = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-rest_run-{item:02d}_sbref' ) rest_psf = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-rest_acq-psf_run-{item:02d}_bold' ) rest_psf_dico = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-rest_acq-psf_rec-dico_run-{item:02d}_bold' ) rest_psf_flashref = create_key( '{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-rest_acq-psf_run-{item:02d}_flashref' ) #pilot = create_key('sourcedata/pilot_bold/{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-pilot_run-{item:02d}_bold') #pilot_psf = create_key('sourcedata/pilot_bold/{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-pilot_acq-psf_run-{item:02d}_bold') #pilot_psf_dico = create_key('sourcedata/pilot_bold/{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-pilot_acq-psf_rec-dico_run-{item:02d}_bold') #pilot_psf_flashref = create_key('sourcedata/pilot_bold/{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-pilot_acq-psf_run-{item:02d}_flashref') fmap = create_key( '{bids_subject_session_dir}/fmap/{bids_subject_session_prefix}_dir-{dir}_epi' ) #fmap_sbref = create_key('{bids_subject_session_dir}/fmap/{bids_subject_session_prefix}_dir-{dir}_sbref') info[rest] = [] info[rest_sbref] = [] info[rest_psf] = [] info[rest_psf_dico] = [] info[movie] = [] info[movie_sbref] = [] info[fmap] = [] # info[fmap_sbref]=[] # info[pilot]=[] # info[pilot_psf]=[] # info[pilot_psf_dico]=[] # info[pilot_psf_flashref]=[] for idx, s in enumerate(seqinfo): #rs func (incl opp phase enc) if len(s.image_type) > 2: if ('DIFFUSION' in s.image_type[2].strip()): continue elif ('Movie' in (s.series_description).strip()): if (s.dim4 == 1 and 'SBRef' in (s.series_description).strip()): info[movie_sbref].append({'item': s.series_id}) elif (s.dim4 > 1): info[movie].append({'item': s.series_id}) elif ('bold' in s.protocol_name or 'resting_state' in s.series_description or 'mbep2d' in (s.series_description).strip() or 'ep_bold' in (s.series_description).strip()): if ('SBRef' in (s.series_description).strip()): info[rest_sbref].append({'item': s.series_id}) elif (s.dim4 == 1): if ('PA' in (s.series_description).strip()): info[fmap].append({'item': s.series_id, 'dir': 'PA'}) elif ('AP' in (s.series_description).strip()): info[fmap].append({'item': s.series_id, 'dir': 'AP'}) elif ('LR' in (s.series_description).strip()): info[fmap].append({'item': s.series_id, 'dir': 'LR'}) elif ('RL' in (s.series_description).strip()): info[fmap].append({'item': s.series_id, 'dir': 'RL'}) # else: # if ('mi_ep2d' in (s.series_description).strip() ): # if ('DICO' in (s.image_type[4].strip())): # info[pilot_psf_dico].append({'item': s.series_id}) # else: # info[pilot_psf].append({'item': s.series_id}) # else: # info[pilot].append({'item': s.series_id}) else: # greater than 1 timepoint: if ('mi_ep2d' in (s.series_description).strip()): if ('DICO' in (s.image_type[4].strip())): info[rest_psf_dico].append({'item': s.series_id}) else: info[rest_psf].append({'item': s.series_id}) else: info[rest].append({'item': s.series_id}) return info