def main(num, ana_roi_names): """ For each entry in <ana_roi_names> extract subject <num>'s data. """ # Remember where we started then # Get dir for num, and change to dir start_dir = os.getcwd() new_dir = subdir(num) print("Changing to {0}".format(new_dir)) os.chdir(new_dir) # Join the A/B data print("Joining task A and B.") func1 = roi.io.read_nifti("wartaskA.nii") func2 = roi.io.read_nifti("wartaskB.nii") func = roi.pre.join_time(func1, func2) # Loop over ana_roi_names for ana in ana_roi_names: print(ana) # Get the roi mask # and apply it to func print("Masking.") anaroi = roi.atlas.get_roi("HarvardOxford", ana) masked_func = roi.pre.mask(func, anaroi) # Store the result print("Writing.") roi.io.write_nifti(masked_func, 'wartaskAB_' + ana + '.gz') os.chdir(start_dir)
def data(num): """ Run a single subjects data. """ sdir = subdir(num) roi_names = [ "wartaskAB_Right Accumbens_str2.nii.gz", "wartaskAB_Right Accumbens.nii.gz", "wartaskAB_Right Caudate.nii.gz"] # -- # Get that Ss data and trial information. sdata = get_behave_data(num) sdata.update(get_similarity_data(num)) sdata.update(get_rl_data(num)) trials = get_trials_combined() durations = get_durations() # -- # Go! roi_results = [] for name in roi_names: print(name) spath = os.path.join(sdir, name) # Init this roi's models roiglm = fmri.catreward.roi.base.Catreward( 1.5, spath, trials, durations, sdata) # Get, reformat (extract), and store the results. roi_results.append(roiglm.run(name)) return roi_results
def meandata(num): """ Run a single subjects data, drawing the BOLD data from the /bold dir text files. """ sdir = subdir(num) roi_names = [ "wartaskAB_Right Accumbens_str2_bold.txt", "wartaskAB_Right Accumbens_bold.txt", "wartaskAB_Right Caudate_bold.txt"] # -- # Get that Ss data and trial information. sdata = get_behave_data(num) sdata.update(get_similarity_data(num)) sdata.update(get_rl_data(num)) trials = get_trials() durations = get_durations() # -- # Go! roi_results = [] for name in roi_names: print(name) spath = os.path.join(sdir, 'bold', name) # Init this roi's models roiglm = fmri.catreward.roi.exps.base.CatMean( 1.5, spath, trials, durations, sdata) # Get, reformat (extract), and store the results. roi_results.append(roiglm.run(name)) return roi_results
def run(num, roi_class_name, trials_name): """ For subject <num>, run all models for all ROIs. Note: Must be run from the parent folder of all the fMRI datasets.""" sdir = subdir(num) roi_class_path = roi_class_name.split('.') txt_classes = ['CatMean', 'Nobox', 'CatMeanFir', 'Subtime'] if roi_class_name == 'Catreward': roi_names = get_roi_names(kind='nii') elif roi_class_name in txt_classes: roi_names = get_roi_names(kind='txt') sdir = os.path.join(sdir, 'bold') ## Swich to the bold dir too else: raise ValueError("Could not find suitable ROI names.") # -- # Get that Ss data and trial information. sdata = get_behave_data(num) sdata.update(get_similarity_data(num)) sdata.update(get_rl_data(num)) durations = get_durations() trials = None if trials_name == 'get_trials': trials = get_trials() elif trials_name == 'get_trials_combined': trials = get_trials_combined() else: raise ValueError("trials_name was unkown.") # -- # Go! results = [] for name in roi_names: print(name) spath = os.path.join(sdir, name) # Init this roi's models Roiclass = getattr(bclasses, roi_class_name) roiglm = Roiclass(1.5, spath, trials, durations, sdata) # Get, reformat (extract), and store the results. # And del it to keep memory reasonable results.append(roiglm.run(name)) return results
def main(num, roi_names, roi_class_name): """ The main worker for run3.py. <num> is a valid subject number code (101-118) <roi_names> is the names of the rois you wish to analyze <roi_class_name> is the name of the fmri.catreward.roi.exps.base class you want to use for the experiment. This script saves each Ss data to seperate files, returning nothing. """ # -- # Get that Ss data and trial information. trials = get_trials_combined() durations = get_durations() sdata = get_behave_data(num) sdata.update(get_similarity_data(num)) sdata.update(get_rl_data(num)) sdata.update(get_cumrewards(num)) ## Add all data to sdata, a dict # -- # The fMRI data is located at: sdir = subdir(num) # -- results = [] for name in roi_names: print(name) spath = os.path.join(sdir, 'bold', name) # Init this roi's models Roiclass = getattr(bclasses, roi_class_name) roiglm = Roiclass(1.5, spath, trials, durations, sdata) # Get, reformat (extract), and store the results. # And del it to keep memory reasonable results.append(roiglm.run(name)) return results