Skip to content

Instantly share code, notes, and snippets.

@sitek
Created June 6, 2019 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sitek/61cdd1e89b4c9435b113292d9fc983f8 to your computer and use it in GitHub Desktop.
Save sitek/61cdd1e89b4c9435b113292d9fc983f8 to your computer and use it in GitHub Desktop.
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
"""
b1map = create_key('{bids_subject_session_dir}/fmap/{bids_subject_session_prefix}_B1map')
b0map_mag = create_key('{bids_subject_session_dir}/fmap/{bids_subject_session_prefix}_part-mag_B0map')
b0map_phase = create_key('{bids_subject_session_dir}/fmap/{bids_subject_session_prefix}_part-phase_B0map')
b1minusmap_head = create_key('{bids_subject_session_dir}/fmap/{bids_subject_session_prefix}_acq-head_B1minusmap')
b1minusmap_body = create_key('{bids_subject_session_dir}/fmap/{bids_subject_session_prefix}_acq-body_B1minusmap')
flash_mtw = create_key('{bids_subject_session_dir}/anat/{bids_subject_session_prefix}_acq-FLASH_MTw')
flash_pdw = create_key('{bids_subject_session_dir}/anat/{bids_subject_session_prefix}_acq-FLASH_PDw')
flash_t1w = create_key('{bids_subject_session_dir}/anat/{bids_subject_session_prefix}_acq-FLASH_T1w')
info = {b1map:[], b0map_mag:[], b0map_phase:[],
b1minusmap_head:[], b1minusmap_body:[],
flash_mtw:[], flash_pdw:[], flash_t1w:[]}
for idx, s in enumerate(seqinfo):
if ('b1map' in s.protocol_name):
info[b1map].append([s.series_id])
if ('gre_field_mapping_1acq_rl' in s.protocol_name):
if ('M' in s.image_type):
info[b0map_mag].append([s.series_id])
elif ('P' in s.image_type):
info[b0map_phase].append([s.series_id])
if ('head' in s.protocol_name):
info[b1minusmap_head].append([s.series_id])
if ('body' in s.protocol_name):
info[b1minusmap_body].append([s.series_id])
if ('t1w_kp_mtflash3d' in s.protocol_name):
info[flash_t1w].append([s.series_id])
if ('mtw_kp_mtflash3d' in s.protocol_name):
info[flash_mtw].append([s.series_id])
if ('pdw_kp_mtflash3d' in s.protocol_name):
info[flash_pdw].append([s.series_id])
return info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment