Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create cfmm_vnav.py #33

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 175 additions & 0 deletions heuristics/cfmm_vnav.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import os

# Adaptation of HCP-Lifespan & LOBE protocol
# Requires tar2bids > v0.0.5h for vNav clean-up

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
"""

t1w = create_key('{bids_subject_session_dir}/anat/{bids_subject_session_prefix}_acq-MPRvNav4eRMS_run-{item}_T1w')
t1w_me = create_key('{bids_subject_session_dir}/anat/{bids_subject_session_prefix}_acq-MPRvNav4e_run-{item}_echo_MEMPRAGE')
t1w_norm = create_key('{bids_subject_session_dir}/anat/{bids_subject_session_prefix}_acq-MPRvNavNorm4eRMS_run-{item}_T1w')
t1w_me_norm = create_key('{bids_subject_session_dir}/anat/{bids_subject_session_prefix}_acq-MPRvNavNorm4e_run-{item}_echo_MEMPRAGE')
t1w_vnavs = create_key('{bids_subject_session_dir}/anat/{bids_subject_session_prefix}_acq-MPRvNav_run-{item}_vNav')

t2w = create_key('{bids_subject_session_dir}/anat/{bids_subject_session_prefix}_acq-SPCvNavRMS_run-{item}_T2w')
t2w_norm = create_key('{bids_subject_session_dir}/anat/{bids_subject_session_prefix}_acq-SPCvNavNormRMS_run-{item}_T2w')
t2w_vnavs = create_key('{bids_subject_session_dir}/anat/{bids_subject_session_prefix}_acq-SPCvNav_run-{item}_vNav')


t1w_basic = create_key('{bids_subject_session_dir}/anat/{bids_subject_session_prefix}_acq-MPRAGE_run-{item}_T1w')
t2w_basic = create_key('{bids_subject_session_dir}/anat/{bids_subject_session_prefix}_acq-SPACE_run-{item}_T2w')

#Diffusion
dwi_ap = create_key('{bids_subject_session_dir}/dwi/{bids_subject_session_prefix}_dir-AP_run-{item}_dwi')
dwi_ap_sbref = create_key('{bids_subject_session_dir}/dwi/{bids_subject_session_prefix}_dir-AP_run-{item}_sbref')
dwi_pa = create_key('{bids_subject_session_dir}/dwi/{bids_subject_session_prefix}_dir-PA_run-{item}_dwi')
dwi_pa_sbref = create_key('{bids_subject_session_dir}/dwi/{bids_subject_session_prefix}_dir-PA_run-{item}_sbref')
dwi_lr = create_key('{bids_subject_session_dir}/dwi/{bids_subject_session_prefix}_dir-LR_run-{item}_dwi')
dwi_lr_sbref = create_key('{bids_subject_session_dir}/dwi/{bids_subject_session_prefix}_dir-LR_run-{item}_sbref')
dwi_rl = create_key('{bids_subject_session_dir}/dwi/{bids_subject_session_prefix}_dir-RL_run-{item}_dwi')
dwi_rl_sbref = create_key('{bids_subject_session_dir}/dwi/{bids_subject_session_prefix}_dir-RL_run-{item}_sbref')



#Field Maps:
fmap_spinecho_ap = create_key('{bids_subject_session_dir}/fmap/{bids_subject_session_prefix}_acq-spinecho_dir-AP_run-{item}_epi')
fmap_spinecho_pa = create_key('{bids_subject_session_dir}/fmap/{bids_subject_session_prefix}_acq-spinecho_dir-PA_run-{item}_epi')

movie_ap = create_key('{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-movie_acq-AP_run-{item}_bold')
movie_ap_sbref = create_key('{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-movie_acq-AP_run-{item}_sbref')

movie_pa = create_key('{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-movie_acq-PA_run-{item}_bold')
movie_pa_sbref = create_key('{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-movie_acq-PA_run-{item}_sbref')

rest_ap = create_key('{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-rest_acq-AP_run-{item}_bold')
rest_ap_sbref = create_key('{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-rest_acq-AP_run-{item}_sbref')
rest_pa = create_key('{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-rest_acq-PA_run-{item}_bold')
rest_pa_sbref = create_key('{bids_subject_session_dir}/func/{bids_subject_session_prefix}_task-rest_acq-PA_run-{item}_sbref')



info = {t1w_me:[],t1w_me_norm:[],t1w_vnavs:[],t1w:[],t1w_norm:[],
t2w_vnavs:[],t2w:[],t2w_norm:[],
t1w_basic:[],t2w_basic:[],
rest_ap:[],rest_ap_sbref:[],
rest_pa:[],rest_pa_sbref:[],
movie_ap:[],movie_ap_sbref:[],
movie_pa:[],movie_pa_sbref:[],
dwi_ap:[],dwi_pa:[],dwi_ap_sbref:[],dwi_pa_sbref:[],
dwi_lr:[],dwi_rl:[],dwi_lr_sbref:[],dwi_rl_sbref:[],
fmap_spinecho_ap:[],fmap_spinecho_pa:[]}

for idx, s in enumerate(seqinfo):


# T1w images
if 'T1w' in s.series_description:
if 'vNav' in s.series_description:
if 'setter' in s.series_description:
if 'MOSAIC' in s.image_type:
info[t1w_vnavs].append({'item': s.series_id})
else:
if 'OTHER' in s.image_type:
if 'NORM' in s.image_type:
print('skipping pre-scan norm RMS combined T1w')
#info[t1w_norm].append({'item': s.series_id})
else:
info[t1w].append({'item': s.series_id})
if 'M' in s.image_type:
if 'NORM' in s.image_type:
print('skipping pre-scan norm separated echo T1w')
#info[t1w_me_norm].append({'item': s.series_id})
else:
info[t1w_me].append({'item': s.series_id})

else:
info[t1w_basic].append({'item': s.series_id})


#T2w images
if 'T2w' in s.series_description:
if 'setter' in s.series_description:
if 'MOSAIC' in s.image_type:
info[t2w_vnavs].append({'item': s.series_id})
elif 'vNav' in s.series_description:
if 'NORM' in s.image_type:
print('skipping pre-scan norm T2w')
# info[t2w_norm].append({'item': s.series_id})
else:
info[t2w].append({'item': s.series_id})
else:
info[t2w_basic].append({'item': s.series_id})

#spinecho field maps

if ('SpinEchoFieldMap_AP' in s.series_description):
info[fmap_spinecho_ap].append({'item': s.series_id})

if ('SpinEchoFieldMap_PA' in s.series_description):
info[fmap_spinecho_pa].append({'item': s.series_id})


#dwi
if 'dMRI' in s.series_description or 'diff' in s.series_description:
if 'AP' in s.series_description:
if 'DIFFUSION' in s.image_type and 'ORIGINAL' in s.image_type:
info[dwi_ap].append({'item': s.series_id})
elif 'SBRef' in s.series_description:
info[dwi_ap_sbref].append({'item': s.series_id})
if 'PA' in s.series_description:
if 'DIFFUSION' in s.image_type and 'ORIGINAL' in s.image_type:
info[dwi_pa].append({'item': s.series_id})
elif 'SBRef' in s.series_description:
info[dwi_pa_sbref].append({'item': s.series_id})
if 'LR' in s.series_description:
if 'DIFFUSION' in s.image_type and 'ORIGINAL' in s.image_type:
info[dwi_lr].append({'item': s.series_id})
elif 'SBRef' in s.series_description:
info[dwi_lr_sbref].append({'item': s.series_id})
if 'RL' in s.series_description:
if 'DIFFUSION' in s.image_type and 'ORIGINAL' in s.image_type:
info[dwi_rl].append({'item': s.series_id})
elif 'SBRef' in s.series_description:
info[dwi_rl_sbref].append({'item': s.series_id})


#rs func (incl opp phase enc)
if 'rfMRI_REST_AP' in s.series_description:
if (s.dim4==1 and 'SBRef' in s.series_description):
info[rest_ap_sbref].append({'item': s.series_id})
else:
info[rest_ap].append({'item': s.series_id})
if 'rfMRI_REST_PA' in s.series_description:
if (s.dim4==1 and 'SBRef' in s.series_description):
info[rest_pa_sbref].append({'item': s.series_id})
else:
info[rest_pa].append({'item': s.series_id})

if 'movie_AP' in s.series_description:
if (s.dim4==1 and 'SBRef' in s.series_description):
info[movie_ap_sbref].append({'item': s.series_id})
else:
info[movie_ap].append({'item': s.series_id})

if 'movie_PA' in s.series_description:
if (s.dim4==1 and 'SBRef' in s.series_description):
info[movie_pa_sbref].append({'item': s.series_id})
else:
info[movie_pa].append({'item': s.series_id})


return info