def runHelp(self): #make local variable conf = self.conf logname = conf.logname os.chdir(conf.subjfMRIDir) print '-Spatially smooth data-' run_shell_cmd('3dBlurInMask -input ' + conf.nextInputFilename[-2] + '+tlrc -FWHM ' + str(conf.FWHMSmoothing) + ' -mask ' + conf.subjMaskDir + conf.subjID + '_gmMask_func_dil1vox.nii.gz -prefix ' + conf.nextInputFilename[-1] + '.nii.gz', logname)
def set_structure(fname, structure, verbose=True): cmd = 'wb_command -set-structure %s %s' % (fname, structure) if verbose: print cmd output = run_shell_cmd(cmd) if verbose: print output
def set_structure(fname,structure,verbose=True): cmd='wb_command -set-structure %s %s'%(fname,structure) if verbose: print cmd output=run_shell_cmd(cmd) if verbose: print output
def run(self): #make local variable conf = self.conf logname = conf.logname os.chdir(conf.subjfMRIDir) numRuns = len(conf.epi_series) for runNum in range(1, numRuns + 1): print ' - Slice Time Correction for Run', runNum, '-' run_shell_cmd('3dTshift -overwrite -Fourier -TR ' + conf.TR + ' -tpattern ' + conf.tpattern + ' -prefix ' + conf.nextInputFilename[-1] + '_r' + str(runNum) + ' ' + conf.nextInputFilename[-2] + '_r' + str(runNum) + '+orig', logname) rmFileName = glob.glob(conf.nextInputFilename[-1] + '_r' + str(runNum) + '????.????.gz') if rmFileName: run_shell_cmd('rm -v ' + rmFilename,logname)
def runHelp(self): #make local variable conf = self.conf logname = conf.logname os.chdir(conf.subjfMRIDir) # Plotting motion parameters if self.showPlot == True: run_shell_cmd('1dplot -sep_scl -plabel ' + str(conf.subjID) + "Motion -volreg allruns_motion_params.1D'[0..5]'",logname) run_shell_cmd('echo "Mean, standard deviation, and absolute deviation of subject\'s motion in mm (left to right), by x,y,z direction (top to bottom):" > MotionInfo.txt',logname) run_shell_cmd("3dTstat -mean -stdev -absmax -prefix stdout: allruns_motion_params.1D'[0..2]'\\'" + " >> MotionInfo.txt",logname) run_shell_cmd('cat MotionInfo.txt',logname)
def run(self): #make local variable conf = self.conf logname = conf.logname os.chdir(conf.subjfMRIDir) # Get concat variables from conf object runList = conf.runList concatString = conf.concatString numRuns = len(conf.epi_series) print '- Concatenating Runs -' print 'Run list:', runList print 'Concatenation string (onset times of each run):', concatString # Run command run_shell_cmd('rm -v ' + conf.nextInputFilename[-1] + '+orig*',logname) run_shell_cmd('3dTcat -prefix ' + conf.nextInputFilename[-1] + ' ' + runList,logname) # Remove intermediate analysis file to save disk space rm_file = glob.glob(conf.nextInputFilename[-1] + 'r_*+????.????.gz') if rm_file: run_shell_cmd('rm -v ' + rm_file,logname)
def runHelp(self): # make local variable conf = self.conf logname = conf.logname print '-Percent Signal Change Normalization-' os.chdir(conf.subjfMRIDir) print '-Deoblique whole brain mask to align with original EPI image-' run_shell_cmd('3dWarp -card2oblique ' + conf.nextInputFilename[-2] + '+orig -prefix tmp_deoblique_wbm.nii.gz ' + conf.subjMaskDir + conf.subjID + '_wholebrainmask.nii.gz', logname) run_shell_cmd('3dresample -overwrite -master ' + conf.subjfMRIDir + conf.nextInputFilename[-2] + '+orig -inset tmp_deoblique_wbm.nii.gz -prefix tmp_deoblique_wbm_func.nii.gz',logname) print '-Run 3dTstat to get the mean activation for each voxel across time-' run_shell_cmd('3dTstat -mean -prefix tmp_tmean.nii.gz ' + conf.nextInputFilename[-2] + '+orig', logname) print '-Now run percent signal change, masking to deobliqued, whole brain mask-' run_shell_cmd('3dcalc -a ' + conf.nextInputFilename[-2] + "+orig -b tmp_tmean.nii.gz -c tmp_deoblique_wbm_func.nii.gz -expr '100 * a/b * ispositive(c)' -prefix " + conf.nextInputFilename[-1], logname) print '-Deleting intermediate files...-'
def run(self): # Function to run the block for line in self.commands: if not line.startswith('#'): run_shell_cmd(line, conf.logname)
def run_and_log(cmd, logfile='conversion_log.txt'): run_shell_cmd(cmd) logmsg(cmd, logfile)
def run(self): #make local variable conf = self.conf logname = conf.logname os.chdir(conf.subjfMRIDir) numRuns = len(conf.epi_series) # Getting raw fMRI data folder names # Modify: How to identify fMRI series directory in raw data [regular expression used to get series order correct] ### Edit this, not very clean ### rawDirRunList = [] for run in range(numRuns): # find epi series searchPath = glob.glob(conf.subjRawDataDir + conf.epi_series[run])[0] # append to rawDirRunList rawDirRunList.append(searchPath) print 'Raw data folder order:', rawDirRunList #For-loop for functions used across multiple runs (prior to run-concatenation) for runNum in range(1,numRuns + 1): print '--Run', runNum, '---' runRawDir = rawDirRunList[runNum-1] fileFindString = 'MR*' if glob.glob(runRawDir + '/*.dcm') == [] else '*.dcm' runRawFile = runRawDir + '/' + fileFindString # Sorting DICOM files (to make sure they will be read in the order they were collected in) using Freesurfer. run_shell_cmd('dicom-rename ' + runRawFile + ' --o ' + conf.basedir + '/SortedDICOMs/Run' + str(runNum) + '/MR',logname) # Converting from DICOM to NIFTI to AFNI format using Freesurfer run_shell_cmd('mri_convert ' + conf.basedir + '/SortedDICOMs/Run' + str(runNum) + '/*00001.dcm --in_type siemens --out_type nii epi_r' + str(runNum) + '.nii.gz',logname) run_shell_cmd('rm epi_r' + str(runNum) + '+orig*',logname) run_shell_cmd('3dcopy epi_r' + str(runNum) +'.nii.gz epi_r' + str(runNum),logname) run_shell_cmd('rm epi_r' + str(runNum) + '.nii.gz',logname) # Remove sorted DICOMs run_shell_cmd('rm -rf ' + conf.basedir + '/SortedDICOMs/Run' + str(runNum),logname) # If numTRsToSkip > 0, remove the first couple TRs for every epi run if conf.numTRsToSkip > '0': run_shell_cmd('3dcalc -a epi_r' + str(runNum) + '+orig"[' + conf.numTRsToSkip + '..$]" -expr ' + "'a' -prefix epi_r" + str(runNum) + ' -overwrite', logname)
def run(self): run_shell_cmd(self.cmd, self.conf.logname)
""" convert orginal ontology to YAML make two files: - one that just contains the hierarchy - another that just contains the mappings from ontology terms to search queries """ import pickle from run_shell_cmd import run_shell_cmd from matplotlib.cbook import flatten # fix the ontology for mac run_shell_cmd("cat PubBrainOntology.txt | tr '\r' '\n' > PubbrainOntology_fixed.txt") # first need to run mk_combined_atlas.py to generate atlas terms # *** getting rid of this by using consistent terms for atlas and ontology term_voxkeys=pickle.load(open('term_voxkeys.cpkl','rb')) lower_term_voxkeys=[i.lower() for i in term_voxkeys.keys()] f = open('PubbrainOntology_fixed.txt') lines=f.readlines() f.close() # find indention level of each line level=[] tree={} ctr=0
print modclust_infomap.modularity assgn = numpy.array([i + 1 for i in modclust_infomap.membership ]) # zero treated as unclustered # exclude small modules by setting to zero for c in numpy.unique(assgn): if numpy.sum(assgn == c) < size_thresh: assgn[assgn == c] = 0 print 'density %0.3f (%0.3f): %d clusters' % (densities[dens], pct, len(numpy.unique(assgn))) assignments[:, dens] = assgn numpy.savetxt('assignments.txt', assignments) #cons=pair_consensus(assignments.T.astype('int')) run_shell_cmd( '/Applications/MATLAB_R2015a.app/bin/matlab -nosplash -nodesktop < Consensus_infomap_simple.m' ) # modules start at zero # relabel all single-node modules as zero and ignore them labels = numpy.loadtxt('assignments_minsize5_regularized_consensus.txt') SHUFFLE = False if SHUFFLE: numpy.random.shuffle(labels) # load parcel info lines = open( '/Users/poldrack/Dropbox/data/selftracking/rsfmri/module_assignments.txt' ).readlines() modules = numpy.array([float(l.strip().split()[3]) for l in lines])
def run_and_log(cmd,logfile='conversion_log.txt'): run_shell_cmd(cmd) logmsg(cmd,logfile)
for c in copefiles: copenum = int(c.split('/')[-1].split('.')[0].replace(filetype, '')) for hemis in ['L', 'R']: outfile = os.path.join( newstatsdir, '%s%03d.%s.func.gii' % (filetype, copenum, hemis)) goodvoxmask = os.path.join( '/corral-repl/utexas/poldracklab/data/selftracking/volume_goodvoxels', '%s_%s_goodvoxels_333.nii.gz' % (subcode, tasknames[runcode][taskcode])) assert os.path.exists(goodvoxmask) wb_command = 'wb_command -volume-to-surface-mapping %s %s %s -ribbon-constrained %s %s -volume-roi %s' % ( c, surfaces['midthickness'][hemis], outfile, surfaces['white'][hemis], surfaces['pial'][hemis], goodvoxmask) if not os.path.exists(outfile): print wb_command run_shell_cmd(wb_command) if hemis == 'L': structure = 'CORTEX_LEFT' else: structure = 'CORTEX_RIGHT' wb_command = 'wb_command -set-structure %s %s' % (outfile, structure) print wb_command run_shell_cmd(wb_command) wb_command = 'wb_command -metric-smoothing %s %s 1.5 %s' % ( surfaces['midthickness'][hemis], outfile, outfile.replace('func.', 'smoothed.func.')) print wb_command run_shell_cmd(wb_command)
def runHelp(self): #make local variable conf = self.conf logname = conf.logname os.chdir(conf.subjfMRIDir) #### Talairach transform anatomical image print '-Run @auto_tlrc to talairach transform anatomical T1 image-' run_shell_cmd('@auto_tlrc -base ' + conf.atlasAnat + ' -input anat_mprage_skullstripped+orig -no_ss',logname) run_shell_cmd('3dcopy anat_mprage_skullstripped+tlrc anat_mprage_skullstripped_tlrc.nii.gz', logname) #format into NIFTI format # Create Mask run_shell_cmd("3dcalc -overwrite -a anat_mprage_skullstripped+tlrc -expr 'ispositive(a)' -prefix " + conf.subjMaskDir + "/wholebrain_mask.nii.gz" ,logname) # Link anatomical image to mask directory for checking alignment run_shell_cmd('ln -s anat_mprage_skullstripped_tlrc.nii.gz ' + conf.subjMaskDir,logname) print '-Run align_epi_anat.py to align EPIs to MPRAGE, motion correct, and Talairach transform EPIs (output in 222 space)-' print 'Make sure Python is version 2.6 or greater (ColeLabMac should be version 2.7)' run_shell_cmd('python -V',logname) # Correcting for motion, aligning fMRI data to MPRAGE, and aligning fMRI data to Talairach template [applying all transformation at once reduces reslicing artifacts] # [You could alternatively analyze all of the data, then Talairach transform the statistics (though this would make extraction of time series based on Talairached ROIs difficult)] # Visit for more info: http://afni.nimh.nih.gov/pub/dist/doc/program_help/align_epi_anat.py.html run_shell_cmd('align_epi_anat.py -overwrite -anat anat_mprage_skullstripped+orig -epi ' + conf.nextInputFilename[-2] + '+orig -epi_base 10 -epi2anat -anat_has_skull no -AddEdge -epi_strip 3dSkullStrip -ex_mode quiet -volreg on -deoblique on -tshift off -tlrc_apar anat_mprage_skullstripped+tlrc -master_tlrc ' + conf.atlasEPI,logname) # Convert to NIFTI run_shell_cmd('3dcopy ' + conf.nextInputFilename[-1] + '+tlrc ' + conf.nextInputFilename[-1] + '.nii.gz',logname) run_shell_cmd('cp ' + conf.nextInputFilename[-2] + "_vr_motion.1D allruns_motion_params.1D",logname)
def run(self): #make local variable conf = self.conf logname = conf.logname os.chdir(conf.subjfMRIDir) #change working directory to fMRI directory print 'Preparing MPRAGE file (anatomical image)' ##****## In the future, will want to adjust this to use os.walk to search subdirectories for files of *.dcm dirName = glob.glob(conf.subjRawDataDir + conf.T1_image)[0] # At this point, will only search for DICOMs with *.dcm extensions, or starting with MR* fileFindString = 'MR*' if glob.glob(dirName + '/*.dcm') == [] else '*.dcm' dicomRenameDir = dirName + '/' + fileFindString #Sort DICOM files (to make sure they will be read in the order they were collected in) using Freesurfer print 'Sorting DICOM...' run_shell_cmd('dicom-rename ' + dicomRenameDir + ' --o ' + conf.basedir + 'SortedDICOMs/MPRAGE/MR',logname) #Convert DICOM files to NIFTI format using Freesurfer print 'Converting DICOM...' run_shell_cmd('mri_convert ' + conf.basedir + 'SortedDICOMs/MPRAGE/*-00001.dcm --in_type siemens --out_type nii mprage.nii.gz',logname) #Remove sorted DICOMs run_shell_cmd('rm -rf ' + conf.basedir + 'SortedDICOMs/MPRAGE',logname) #### # Skull strip MPRAGE # Use Freesurfer's skullstripping (very slow, but more accurate) if conf.runFreesurfer == True: run_shell_cmd('recon-all -subject ' + conf.subjID + ' -all -sd ' + conf.freesurferDir + ' -i mprage.nii.gz',logname) # Convert to NIFTI run_shell_cmd('mri_convert --in_type mgz --out_type nii ' + conf.freesurferDir + '/mri/brain.mgz mprage_skullstripped.nii',logname) # gzip files and removed uncompressed file run_shell_cmd('3dcopy mprage_skullstripped.nii mprage_skullstripped.nii.gz',logname) run_shell_cmd('rm mprage_skullstripped.nii',logname) # Compressing file run_shell_cmd('3dcopy mprage_skullstripped.nii.gz anat_mprage_skullstripped',logname) run_shell_cmd('cp ' + conf.atlasAnat + '* .',logname)
def get_data_from_parcels(volfile, outfile, save_gii=True): surfaces = {} surfaces['midthickness'] = { 'L': os.path.join( basedir, 'fsaverage_LR32k/sub013.L.midthickness.32k_fs_LR.surf.gii'), 'R': os.path.join( basedir, 'fsaverage_LR32k/sub013.R.midthickness.32k_fs_LR.surf.gii') } surfaces['white'] = { 'L': os.path.join(basedir, 'fsaverage_LR32k/sub013.L.white.32k_fs_LR.surf.gii'), 'R': os.path.join(basedir, 'fsaverage_LR32k/sub013.R.white.32k_fs_LR.surf.gii') } surfaces['pial'] = { 'L': os.path.join(basedir, 'fsaverage_LR32k/sub013.L.pial.32k_fs_LR.surf.gii'), 'R': os.path.join(basedir, 'fsaverage_LR32k/sub013.R.pial.32k_fs_LR.surf.gii') } parcellations = { 'L': os.path.join( basedir, 'parcellation/all_selected_L_new_parcel_renumbered.func.gii'), 'R': os.path.join( basedir, 'parcellation/all_selected_R_new_parcel_renumbered.func.gii') } parcels = {} parceldata = {} for hemis in ['L', 'R']: tmpfile = tempfile.mkstemp(suffix='.%s.func.gii' % hemis) os.close(tmpfile[0]) outfile = tmpfile[1] print outfile wb_command = 'wb_command -volume-to-surface-mapping %s %s %s -ribbon-constrained %s %s' % ( volfile, surfaces['midthickness'][hemis], outfile, surfaces['white'][hemis], surfaces['pial'][hemis]) print wb_command run_shell_cmd(wb_command) if hemis == 'L': structure = 'CORTEX_LEFT' else: structure = 'CORTEX_RIGHT' wb_command = 'wb_command -set-structure %s %s' % (outfile, structure) print wb_command run_shell_cmd(wb_command) surfdata = nibabel.gifti.giftiio.read(outfile) parcels[hemis] = nibabel.gifti.giftiio.read(parcellations[hemis]) for i in numpy.unique(parcels[hemis].darrays[0].data): if i == 0: continue parcelvertices = parcels[hemis].darrays[0].data == i parceldata[i] = [] for da in range(len(surfdata.darrays)): parceldata[i].append( numpy.mean(surfdata.darrays[da].data[parcelvertices[:, 0]])) if save_gii: shutil.move(outfile, volfile.replace('nii.gz', '%s.func.gii' % hemis)) else: os.remove(outfile) nparcs = len(parceldata) ntp = len(parceldata[parceldata.keys()[0]]) parcs = numpy.unique(parceldata.keys()) parcs.sort() parcmtx = numpy.zeros((nparcs, ntp)) for p in range(len(parcs)): parcmtx[p] = parceldata[parcs[p]] return parcmtx
def run(self): print 'Running:', self.input run_shell_cmd(self.input, self.logname, cwd=self.pwd)
if numpy.sum(W) == 0: continue Y = cope[:, v].reshape((nsess, 1)) wls = sm.WLS(Y, X, weights=1.0 / varcope[:, v]) res = wls.fit() #beta_hat = numpy.linalg.inv(X.T.dot(W).dot(X)).dot(X.T).dot(W).dot(Y) #(X'WX)^{-1} X'WY #var_beta_hat = numpy.linalg.inv(X.T.dot(W).dot(X)) #(X'WX)^{-1} #tstat[v]=beta_hat / numpy.sqrt(var_beta_hat) tstat[v] = res.tvalues[0] outdir = '/corral-repl/utexas/poldracklab/data/selftracking/surface_stats_333' fname = os.path.join( outdir, 'task%03d_cope%03d.%s.tstat.smoothed.func.gii' % (task, copenum, hemis)) if hemis == 'L': structure = 'CORTEX_LEFT' else: structure = 'CORTEX_RIGHT' img = nibabel.gifti.GiftiImage() img.add_gifti_data_array( nibabel.gifti.GiftiDataArray.from_array( tstat, intent=f.darrays[0].intent, datatype=f.darrays[0].datatype, ordering='F', meta={'Name': 'task%03d_cope%03d.tstat' % (task, copenum)})) nibabel.gifti.giftiio.write(img, fname) cmd = 'wb_command -set-structure %s %s' % (fname, structure) run_shell_cmd.run_shell_cmd(cmd)
def runHelp(self): #make local variable conf = self.conf logname = conf.logname os.chdir(conf.subjfMRIDir) print '--Extract time series from white matter, ventricle masks--' run_shell_cmd('3dmaskave -quiet -mask ' + conf.subjMaskDir + conf.subjID + '_wmMask_func_eroded.nii.gz ' + conf.nextInputFilename[-1] + '.nii.gz > ' + conf.wm_timeseries + '.1D',logname) run_shell_cmd('3dmaskave -quiet -mask ' + conf.subjMaskDir + conf.subjID + '_ventricles_func_eroded.nii.gz ' + conf.nextInputFilename[-1] + '.nii.gz > ' + conf.ventricles_timeseries + '.1D',logname) print '--Extract whole brain signal--' os.chdir(conf.subjMaskDir) if conf.hcpData == False: # no need to run @auto_tlrc on hcpdata # Transform aseg to TLRC space run_shell_cmd('@auto_tlrc -apar ' + conf.subjfMRIDir + 'anat_mprage_skullstripped+tlrc -input ' + conf.subjID + '_fs_seg.nii.gz',logname) run_shell_cmd("3dcalc -overwrite -a " + conf.subjID + "_fs_seg.nii.gz -expr 'ispositive(a)' -prefix " + conf.subjID + '_wholebrainmask.nii.gz',logname) # Resample to functional space run_shell_cmd('3dresample -overwrite -master ' + conf.subjfMRIDir + conf.nextInputFilename[-1] + '.nii.gz -inset ' + conf.subjID + '_wholebrainmask.nii.gz -prefix ' + conf.subjID + '_wholebrainmask_func.nii.gz',logname) # Dilate mask by 1 functional voxel (just in case the resampled anatomical mask is off by a bit) run_shell_cmd("3dLocalstat -overwrite -nbhd 'SPHERE(-1)' -stat 'max' -prefix " + conf.subjID + '_wholebrainmask_func_dil1vox.nii.gz ' + conf.subjID + '_wholebrainmask_func.nii.gz',logname) os.chdir(conf.subjfMRIDir) run_shell_cmd('3dmaskave -quiet -mask ' + conf.subjMaskDir + conf.subjID + '_wholebrainmask_func_dil1vox.nii.gz ' + conf.nextInputFilename[-1] + '.nii.gz > ' + conf.wholebrain_timeseries + '.1D',logname)
import os import glob import shutil import run_shell_cmd dirs=glob.glob('ds*/sub*/model/model001') # make target dirs for d in dirs: print d newdir=d+'_fsl4' if not os.path.exists(newdir): os.mkdir(newdir) to_copy=glob.glob(os.path.join(d,'*.gfeat')) #if 0: for c in to_copy: cmd='cp -r %s %s'%(c,newdir) print cmd run_shell_cmd.run_shell_cmd(cmd) if 0: for c in to_copy: if os.path.exists(c.replace('model001','model001_fsl4')): cmd='rm -rf %s'%c print cmd run_shell_cmd.run_shell_cmd(cmd)
def runHelp(self): #make local variable conf = self.conf GLM = self.conf.GLM logname = conf.logname os.chdir(conf.subjfMRIDir) run_shell_cmd('cp Movement_Regressors_Rest_allruns.1D allruns_motion_params.1D', logname) run_shell_cmd('1d_tool.py -overwrite -infile ' + conf.wm_timeseries + '.1D -derivative -write ' + conf.wm_timeseries + '_deriv.1D', logname) run_shell_cmd('1d_tool.py -overwrite -infile ' + conf.ventricles_timeseries + '.1D -derivative -write ' + conf.ventricles_timeseries + '_deriv.1D', logname) run_shell_cmd('1d_tool.py -overwrite -infile ' + conf.wholebrain_timeseries + '.1D -derivative -write ' + conf.wholebrain_timeseries + '_deriv.1D', logname) print 'Run GLM to remove nuisance time series (motion, white matter, ventricles)' input = '-input ' + conf.nextInputFilename[-2] + '.nii.gz ' if GLM['input'] == None else GLM['input'] mask = '-mask ' + conf.subjMaskDir + conf.subjID + '_gmMask_func_dil1vox.nii.gz ' concat = '' if GLM['concat'] == False else '-concat ' + '"' + conf.concatString + '" ' polort = '-polort ' + str(GLM['polort']) + ' ' stimtimes = self.organizeStimTimes() num_stimts = '-num_stimts ' + str(len(stimtimes)) + ' ' # make stimtimes into a single string stimtimes = ''.join(stimtimes) # stimfile1 = '-stim_file 1 ' + conf.wm_timeseries + '.1D -stim_label 1 WM ' # stimfile2 = '-stim_file 2 ' + conf.ventricles_timeseries + '.1D -stim_label 2 Vent ' # stimfile3 = '-stim_file 3 ' + conf.wm_timeseries + '_deriv.1D -stim_label 3 WMDeriv ' # stimfile4 = '-stim_file 4 ' + conf.ventricles_timeseries + '_deriv.1D -stim_label 4 VentDeriv ' # stimfile5 = "-stim_file 5 allruns_motion_params.1D'[0]' -stim_base 5 " # stimfile6 = "-stim_file 6 allruns_motion_params.1D'[1]' -stim_base 6 " # stimfile7 = "-stim_file 7 allruns_motion_params.1D'[2]' -stim_base 7 " # stimfile8 = "-stim_file 8 allruns_motion_params.1D'[3]' -stim_base 8 " # stimfile9 = "-stim_file 9 allruns_motion_params.1D'[4]' -stim_base 9 " # stimfile10 = "-stim_file 10 allruns_motion_params.1D'[5]' -stim_base 10 " # these stimfiles are commented out because this had to be adapted from analyzing the HCP rest data # stimfile11 = "-stim_file 11 rest_allruns_motion_params.1D'[6]' -stim_base 11 " # stimfile12 = "-stim_file 12 rest_allruns_motion_params.1D'[7]' -stim_base 12 " # stimfile13 = "-stim_file 13 rest_allruns_motion_params.1D'[8]' -stim_base 13 " # stimfile14 = "-stim_file 14 rest_allruns_motion_params.1D'[9]' -stim_base 14 " # stimfile15 = "-stim_file 15 rest_allruns_motion_params.1D'[10]' -stim_base 15 " # stimfile16 = "-stim_file 16 rest_allruns_motion_params.1D'[11]' -stim_base 16 " # stimfile11 = "-stim_file 11 " + conf.wholebrain_timeseries + '.1D -stim_label 11 WholeBrain ' # stimfile12 = "-stim_file 12 " + conf.wholebrain_timeseries + '_deriv.1D -stim_label 12 WholeBrainDeriv ' xsave = '-xsave -x1D xmat_rall.x1D -xjpeg xmat_rall.jpg ' gltsym = '' if GLM['gltsym'] == None else GLM['gltsym'] + ' ' errts = '' if GLM['errts'] == None else '-errts ' + GLM['errts'] + ' ' fdr = '' if GLM['noFDR'] == False else '-noFDR ' fout = '-fout ' if GLM['fout'] == True else '' tout = '-tout ' if GLM['tout'] == True else '' if 'jobs' in GLM.keys(): jobs = '-jobs ' + str(GLM['jobs']) + ' -float ' else: jobs = '-jobs 1 -float ' # change outbucket output name according to type of GLM run if GLM['type'] == 'Activation': bucket = '-bucket ' + conf.AnalysisName + '_outbucket -cbucket ' + conf.AnalysisName + '_cbucket' else: bucket = '-bucket NuissanceResid_outbucket_' + conf.nextInputFilename[-2] + '+tlrc -overwrite' glm_command = '3dDeconvolve ' + input + mask + concat + polort + num_stimts + stimtimes + gltsym + fout + tout + xsave + errts + jobs + fdr + bucket print 'Running the GLM command:', glm_command run_shell_cmd(glm_command, logname) if GLM['type'] == 'rsfcMRI': run_shell_cmd('rm ' + conf.nextInputFilename[-1] + '*', logname) run_shell_cmd('3dcopy NuissanceResid_Resids+tlrc ' + conf.nextInputFilename[-1] + '+tlrc', logname) run_shell_cmd('rm NuissanceResid_Resids+tlrc', logname) elif GLM['type'] == 'Activation': run_shell_cmd('1dplot -sep_scl -plabel ' + conf.subjID + 'DesignMatrix xmat_rall.x1D &', logname)