Last active
July 17, 2016 15:56
-
-
Save jminas/c2ff8ed6507838981c6fed57cb7f1e27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"%reset -f\n", | |
"import os\n", | |
"from glob import glob\n", | |
"import re #regular expression\n", | |
"import datetime" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"## Args\n", | |
"model=121\n", | |
"task_list=[6]\n", | |
"subj_wild = 'voice875*' #'voice*'\n", | |
"hpfilter=120\n", | |
"\n", | |
"# user specific\n", | |
"fmri_py_script='/om/user/gr21783/git/openfmri/subject_level/fmri_ants_openfmri_sparse.py'\n", | |
"work_dir_base='/om/scratch/Wed/gr21783/voice20151111'\n", | |
"crashdump_base='/home/gr21783/OMerrLog'\n", | |
"out_dir_base = '/om/project/voice/processedData/l1analysis/l1output_20151106'\n", | |
"\n", | |
"# leave alone\n", | |
"file_path_openfmri='/om/project/voice/processedData/openfmri'\n", | |
"targetTemplate='/om/project/voice/processedData/resting/templates/OASIS-30_Atropos_template_in_MNI152_2mm.nii.gz'\n", | |
"fsdata_base='/om/project/voice/processedData/fsdata'\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n", | |
"# Copy this file and the workflow script to the output directory\n", | |
"#mkdir -p $out_dir\n", | |
"#cp submit_sparseL1.sh $out_dir\n", | |
"#cp $fmri_py_script $out_dir" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"['/om/project/voice/processedData/openfmri/participant_models/model200/voice987/session001_visit001/voice987_task001_run001_pataka', '/om/project/voice/processedData/openfmri/participant_models/model200/voice987/session001_visit001/voice987_task001_run002_pataka']\n", | |
"['/om/project/voice/processedData/openfmri/participant_models/model200/voice987/session001/voice987_task001', '/om/project/voice/processedData/openfmri/participant_models/model200/voice987/session001/voice987_task001']\n", | |
"\n", | |
"['/om/project/voice/processedData/openfmri/participant_models/model200/voice987/session001/voice987_task001']\n", | |
"\n" | |
] | |
} | |
], | |
"source": [ | |
"# Key idea: Only loop over sessions that have specified model onsets, T1, and functional data\n", | |
"file_list = []\n", | |
"for task in task_list:\n", | |
" file_list.extend(glob(os.path.join(file_path_openfmri, 'participant_models', 'model%03d' % model,\n", | |
" subj_wild, 'session*', '*_task%03d_*' % task)))\n", | |
"\n", | |
"print file_list\n", | |
"\n", | |
"# Make list unique based on session, since openfmri globs over visits\n", | |
"# Replace session###_visit### with session###\n", | |
"# Replace_run# with ''\n", | |
"file_list = [re.sub('_visit\\d+', '', i) for i in file_list]\n", | |
"file_list = [re.sub('_run\\d+_[a-z]+', '', i) for i in file_list]\n", | |
"print file_list\n", | |
" \n", | |
"print\n", | |
"file_list = list(set(file_list)) # remove duplicate entries now that visit and run are gone\n", | |
"file_list.sort()\n", | |
"print file_list\n", | |
"\n", | |
"print\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"sbatch openfmriL1_1subj1task.sh /om/user/gr21783/git/openfmri/subject_level/fmri_ants_openfmri_sparse.py voice987 session001 /om/project/voice/processedData/fsdata/voice987/session001 200 /om/project/voice/processedData/l1analysis/l1output_20151106/model200/task001 /om/project/voice/processedData/openfmri /om/project/voice/processedData/resting/templates/OASIS-30_Atropos_template_in_MNI152_2mm.nii.gz /om/scratch/Wed/gr21783/voice20151106/model200/task001/voice987 120 1 /home/gr21783/OMerrLog/task001_2015110609/voice987/session001\n" | |
] | |
} | |
], | |
"source": [ | |
"# Remove if no T1 for given subject, session tuple\n", | |
"for idx, text in enumerate(file_list):\n", | |
" try: \n", | |
" subj = re.search('voice\\d+', text).group(0)\n", | |
" except AttributeError:\n", | |
" # AAA, ZZZ not found in the original string\n", | |
" subj = '' # apply your error hand\n", | |
" \n", | |
" try: \n", | |
" session = re.search('session\\d+', text).group(0)\n", | |
" except AttributeError:\n", | |
" # AAA, ZZZ not found in the original string\n", | |
" session = '' # apply your error hand \n", | |
" \n", | |
" try: \n", | |
" task = re.search('task\\d+', text).group(0)\n", | |
" except AttributeError:\n", | |
" # AAA, ZZZ not found in the original string\n", | |
" task = '' # apply your error hand \n", | |
" task = int(task[4:])\n", | |
" \n", | |
" \n", | |
" out_dir=os.path.join(out_dir_base,\n", | |
" 'model%03d' % model, 'task%03d' % task)\n", | |
" \n", | |
" file_path_anatomy_T1 = glob(os.path.join(file_path_openfmri, subj, session + '*', 'anatomy', '*T1w*.nii.gz'))\n", | |
" # If there are multiple anatomy folders, check each one for a *T1w*.nii.gz\n", | |
" if file_path_anatomy_T1:\n", | |
" # proceed to processing\n", | |
" fsdata_dir=os.path.join(fsdata_base, subj, session)\n", | |
"\n", | |
" crashdump_dir=os.path.join(crashdump_base, 'task%03d_%s' % \n", | |
" (task, datetime.datetime.now().strftime('%Y%m%d%H')), subj, session)\n", | |
"\n", | |
" workingDir=os.path.join(work_dir_base, 'model%03d' % model, 'task%03d' % task, subj)\n", | |
"\n", | |
"\n", | |
" #echo openfmriL1_1subj1task.sh $fmri_py_script $subj $session $fsdata_dir $model ${out_dir} $file_path_openfmri $targetTemplate $workingDir $hpfilter $task $crashdump_dir\n", | |
"\n", | |
" cmd_str = 'sbatch openfmriL1_1subj1task.sh ' + fmri_py_script + ' ' + subj + ' ' + session \\\n", | |
" + ' ' + fsdata_dir + ' ' + str(model) + ' ' + out_dir + ' ' + file_path_openfmri + ' ' + \\\n", | |
" targetTemplate + ' ' + workingDir + ' ' + str(hpfilter) + ' ' + str(task) + ' ' +\\\n", | |
" crashdump_dir\n", | |
"\n", | |
"\n", | |
" print cmd_str \n", | |
" os.system(cmd_str)\n", | |
" else:\n", | |
" print '*** NO T1 PRESENT ***: ' + subj + ' ' + session \n", | |
" " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.10" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment