heuristic.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python
  2. def create_key(template, outtype=('nii.gz',), annotation_classes=None):
  3. if template is None or not template:
  4. raise ValueError('Template must be a valid format string')
  5. return template, outtype, annotation_classes
  6. def infotodict(seqinfo):
  7. # paths in BIDS format
  8. anat = create_key('sub-{subject}/{session}/anat/sub-{subject}_{session}_rec-{rec}_T1w')
  9. rest_pre = create_key('sub-{subject}/{session}/func/sub-{subject}_{session}_task-rest_rec-{rec}_run-pre_bold')
  10. rest_post = create_key('sub-{subject}/{session}/func/sub-{subject}_{session}_task-rest_rec-{rec}_run-post_bold')
  11. task = create_key('sub-{subject}/{session}/func/sub-{subject}_{session}_task-highspeed_rec-{rec}_run-{item:02d}_bold')
  12. fmap_topup = create_key('sub-{subject}/{session}/fmap/sub-{subject}_{session}_rec-{rec}_dir-{dir}_epi')
  13. info = {anat: [], rest_pre: [], rest_post: [], task: [], fmap_topup: []}
  14. for s in seqinfo:
  15. if 'NORM' in s.image_type:
  16. rec = 'prenorm'
  17. else:
  18. rec = 'nonorm'
  19. if ('t1' in s.series_description):
  20. info[anat].append({'item': s.series_id, 'rec': rec})
  21. if ('FM_' in s.series_description) and ('prenorm' in rec):
  22. info[fmap_topup].append({'item': s.series_id, 'rec': rec, 'dir': 'AP'})
  23. if ('FMInv_' in s.series_description) and ('prenorm' in rec):
  24. info[fmap_topup].append({'item': s.series_id, 'rec': rec, 'dir': 'PA'})
  25. if ('Rest_Pre' in s.series_description) and ('prenorm' in rec):
  26. info[rest_pre].append({'item': s.series_id, 'rec': rec})
  27. if ('Rest_Post' in s.series_description) and ('prenorm' in rec):
  28. info[rest_post].append({'item': s.series_id, 'rec': rec})
  29. # some participants have one post resting state labelled "Rest":
  30. if ('Rest' in s.series_description) and ('prenorm' in rec):
  31. info[rest_post].append({'item': s.series_id, 'rec': rec})
  32. if ('Run' in s.series_description) and ('prenorm' in rec):
  33. info[task].append({'item': s.series_id, 'rec': rec})
  34. return info