Skip to content

Instantly share code, notes, and snippets.

@satra
Last active August 29, 2015 14:14
Show Gist options
  • Save satra/5d9ebeba43cc2c242128 to your computer and use it in GitHub Desktop.
Save satra/5d9ebeba43cc2c242128 to your computer and use it in GitHub Desktop.
openfmri pieces
#!/bin/bash
for sub in '315' '318' '332' ; do
for run in 1 2 3 4 ; do
mkdir /om/project/gates/wmfilt/openfmri/ds001/${sub}
mkdir /om/project/gates/wmfilt/openfmri/ds001/${sub}/model
mkdir /om/project/gates/wmfilt/openfmri/ds001/${sub}/model/model001
mkdir /om/project/gates/wmfilt/openfmri/ds001/${sub}/model/model001/onsets
mkdir /om/project/gates/wmfilt/openfmri/ds001/${sub}/model/model001/onsets/task001_run00${run}
mkdir /om/project/gates/wmfilt/openfmri/ds001/${sub}/BOLD
mkdir /om/project/gates/wmfilt/openfmri/ds001/${sub}/BOLD/task001_run00${run}
mkdir /om/project/gates/wmfilt/openfmri/ds001/${sub}/behav
mkdir /om/project/gates/wmfilt/openfmri/ds001/${sub}/anatomy
#T1
ln -s /mindhive/xnat/data/GATES/${sub}/niftis/mprag2.nii /om/project/gates/wmfilt/openfmri/ds001/${sub}/anatomy/T1.nii
#BOLD
ln -s /mindhive/xnat/data/GATES/${sub}/niftis/WM${run}.nii /om/project/gates/wmfilt/openfmri/ds001/${sub}/BOLD/task001_run00${run}/bold.nii
ln -s /om/project/gates/wmfilt/openfmri/scan_key.txt /om/project/gates/wmfilt/openfmri/ds001/${sub}/BOLD/task001_run00${run}/scan_key.txt
#model
ln -s /om/project/gates/wmfilt/bips/onsets/wmfilt_run${run}/${sub}_delay_2R_c.txt /om/project/gates/wmfilt/openfmri/ds001/${sub}/model/model001/onsets/task001_run00${run}/cond001.txt
ln -s /om/project/gates/wmfilt/bips/onsets/wmfilt_run${run}/${sub}_delay_2R_m.txt /om/project/gates/wmfilt/openfmri/ds001/${sub}/model/model001/onsets/task001_run00${run}/cond002.txt
ln -s /om/project/gates/wmfilt/bips/onsets/wmfilt_run${run}/${sub}_delay_4RY_c.txt /om/project/gates/wmfilt/openfmri/ds001/${sub}/model/model001/onsets/task001_run00${run}/cond003.txt
ln -s /om/project/gates/wmfilt/bips/onsets/wmfilt_run${run}/${sub}_delay_4RY_m.txt /om/project/gates/wmfilt/openfmri/ds001/${sub}/model/model001/onsets/task001_run00${run}/cond004.txt
ln -s /om/project/gates/wmfilt/bips/onsets/wmfilt_run${run}/${sub}_delay_DRY_c.txt /om/project/gates/wmfilt/openfmri/ds001/
done
done
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
"""
# Create the T1 anatomy file
t1 = create_key('anatomy/T1_{item:03d}')
# Pull out the non word reptition fMRI run
nwr = create_key('BOLD/task001_run{item:03d}/bold')
#initialize a dictionary for all the scans you'll be grabbing
info = {t1:[],nwr:[]}
# commented out because not needed anymore
#info={}
# the basic "if" statement structure is a hack job customized to every project
# the first part of the if condition filters by some "unique-ish" number from columns 6,7,8, and 9
# the second, and, part of the condition filters by hopefully a meaningful sequence name that was used in the scanner.
# Note: the t1 image is NOT appended to info. Keep only the very last t1 run in the file.
# Note: the functional sequences use .append when adding values to the dictionary key. This is because multiple runs will have the same MRI sequence name, but we want all of them.
# Note: The 13th column is a boolean that refers to motion correction. Only keep runs where the boolean is false.
last_run = len(seqinfo)
for s in seqinfo:
x,y,sl,nt = (s[6], s[7], s[8], s[9])
if (sl == 176) and (nt ==1) and ('T1_MPRAGE' in s[12]):
info[t1]=[s[2]]
elif (nt == 42) and ('Nonword-Repetition' in s[12]):
if not s[13]:
info[nwr].append(s[2])
else:
pass
return info
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
"""
rs = create_key('resting/rest/bold', outtype=('dicom', 'nii.gz'))
spin = create_key('resting/rest/se', outtype=('dicom', 'nii.gz'))
dwi = create_key('dmri/dwi_{item:03d}', outtype=('dicom',))
t1 = create_key('anatomy/T1_{item:03d}')
t2 = create_key('anatomy/T2_{item:03d}')
pataka = create_key('BOLD/task001_run{item:03d}/bold')
sentences=create_key('BOLD/task002_run{item:03d}/bold')
nonwordrep=create_key('BOLD/task003_run{item:03d}/bold')
facematch=create_key('BOLD/task004_run{item:03d}/bold')
emosent=create_key('BOLD/task005_run{item:03d}/bold')
vowels=create_key('BOLD/task006_run{item:03d}/bold')
pitch_emph=create_key('BOLD/task007_run{item:03d}/bold')
movie_trailer=create_key('BOLD/task008_run{item:03d}/bold')
info = {rs: [], spin: [], dwi:[], t1:[], t2:[], pataka:[], sentences:[], nonwordrep:[], facematch:[], emosent:[], vowels:[], pitch_emph:[], movie_trailer:[]}
last_run = len(seqinfo)
for s in seqinfo:
x,y,sl,nt = (s[6], s[7], s[8], s[9])
if (nt == 300) and ('SMS5_rsfMRI' in s[12]):
info[rs] = [s[2]]
elif (nt == 4) and ('Spin_Echo' in s[12]):
info[spin].append(s[2])
elif (sl > 1) and (nt == 72) and ('SMS2-diff_b1000' in s[12]):
info[dwi].append(s[2])
elif (sl > 1) and (nt == 7 ) and ('SMS2-diff_b100_free' in s[12]):
info[dwi].append(s[2])
elif (sl == 176) and (nt ==1) and ('T1_MPRAGE' in s[12]):
info[t1].append(s[2])
elif (nt > 175) and ('PaTaKa' in s[12]):
info[pataka].append(s[2])
elif (nt == 57) and ('Sentences' in s[12]):
info[sentences].append(s[2])
elif (nt == 42 ) and ('Nonword' in s[12]):
info[nonwordrep].append(s[2])
elif (nt == 99) and ('FaceMatch' in s[12]):
info[facematch].append(s[2])
elif (nt == 42) and ('EmoSent' in s[12]):
info[emosent].append(s[2])
elif (nt == 55) and ('Vowels' in s[12]):
info[vowels].append(s[2])
elif (nt == 101) and ('PitchEmph' in s[12]):
info[pitch_emph].append(s[2])
elif (nt == 138) and ('Movie' in s[12]):
info[movie_trailer].append(s[2])
elif (sl == 176) and (nt == 1 ) and ('T2_SPACE' in s[12]):
info[t2] = [s[2]]
else:
pass
return info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment