Preprocessing and First Level Model for Task fMRI with ACPC Alignment

John Muschelli

2021-03-03

ACPC Version

Overview of spm12r functions

Requires MATLAB (installs SPM to R library)

Data used

library(httr)
install_dir = tempdir()
url = paste0("https://ndownloader.figshare.com/articles/",
             "5442298/versions/1")
zipfile = tempfile(fileext = ".zip")
res = GET(
  url, 
  write_disk(path = zipfile),
  if (interactive()) progress())
run_dir = tempfile()
if (!dir.exists(run_dir)) {
  dir.create(run_dir)
}
out_files = utils::unzip(zipfile, exdir = run_dir)
names(out_files) = neurobase::nii.stub(
  out_files, bn = TRUE)

We know the repetition time (TR) is 2 seconds for this data. It may be encoded in the NIfTI file itself or come from a parameter file from the scanner. We will drop the first 20 seconds to allow for signal stabilization.

library(neurobase)
##################################
# Added quick reading of nifti header
##################################
oro_pkg = packageVersion("oro.nifti")
neuro_pkg = packageVersion("neurobase")
if (oro_pkg < 0.8 || neuro_pkg < 1.22) {
  get_nifti = neurobase::check_nifti 
} else {
  get_nifti = neurobase::check_nifti_header
}

fmri_filename = out_files["fmri"]
t1_fname = out_files["anat"]
tr = 1.8 # seconds
hdr = get_nifti(fmri_filename) # getting nifti header

nslices = oro.nifti::nsli(hdr)
n_time_points = oro.nifti::ntim(hdr)
time_points = seq(n_time_points)
ta = 0
slice_order = c(
  1740, 1680, 1620, 1560, 1500, 1440, 1380, 
  1320, 1260, 1200, 1140, 1080, 1020, 960, 
  900, 840, 780, 720, 660, 600, 540, 480, 
  420, 360, 300, 240, 180, 120, 60, 0, 
  1740, 1680, 1620, 1560, 1500, 1440, 1380, 
  1320, 1260, 1200, 1140, 1080, 1020, 960, 
  900, 840, 780, 720, 660, 600, 540, 480, 420, 
  360, 300, 240, 180, 120, 60, 0)
ref_slice = 900

Checking MATLAB

As SPM requires MATLAB and calls all the functions through the matlabr package, we will have checks in this vignette/workflow that the user has MATLAB. The have_matlab() function returns a logical that is TRUE when matlabr can find MATLAB to run the subsequent commands.

library(matlabr)
have_matlab()
## [1] TRUE

If this is not TRUE, almost none of the functionality below will run because it would simply result in errors.

Overall Processing

We will show how to do spatial realignment, slice-timing correction, spatial normalization to the MNI template (2 different ways), and spatial smoothing. Overall, there are many different ways to order these operations, with different options, so this represents just one way to organize a preprocessing pipeline.

Image Realignment

Realignment is referring to in this case as within-subject registration of the 4D fMRI data.

library(spm12r)
####################################
# Realignment
####################################
if (have_matlab()) {
  
  realigned = spm12_realign( 
    filename = fmri_filename,
    time_points = time_points,
    quality = 0.98, 
    separation = 3,
    register_to = "mean",
    est_interp = "bspline4",
    reslice_interp = "bspline4",
    clean = FALSE,
    install_dir = install_dir
  )
  ################################
  # reading in the mean image
  ##########################
  mean_img = realigned[["mean"]]
  mean_nifti = readnii(mean_img)
  
  rpfile = realigned[['rp']]
  rp = read.table(file = rpfile, header = FALSE)
}
## # Reslice is all+mean
## # Running matlabbatch job
## # Creating matlabbatch job
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/spm12\n
## Running job: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd71de617b5.m, which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd717bb499ee.m
## Command run is:
## matlab  -nodesktop -nosplash   -nodisplay -r  "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd71de617b5.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0

Overall the spm12_realign does the realignment. There is some discussion of performing realignment before slice-timing correction because estimation of motion parameters may be skewed after slice-timing correction. We see that the output realigned has the output 4D fMRI data (outfiles), the realignment parameters (rp), voxel-wise mean after realignment (mean), and the matrix of transformations for the 4D series (mat).

Reading in the RP file

Here we can read in the rp file to show the estimated parameters. These can be used as regressors in motion correction for further analyses.

####################################
# Read in Motion data
####################################
if (have_matlab()) {
  rpfile = realigned[['rp']]
  rp = read.table(file = rpfile, header = FALSE)
  colnames(rp) = c("x", "y", "z", 
                   "roll", "pitch", "yaw")
  rp = as.matrix(rp)
  print(head(rp))
  print(dim(rp))
}
##                 x           y             z          roll         pitch
## [1,] 0.0000000000  0.00000000  7.105427e-15  0.0000000000  0.000000e+00
## [2,] 0.0048211607 -0.05013463 -6.007747e-02 -0.0004428566  6.155483e-05
## [3,] 0.0157221950 -0.04831228  4.966902e-02 -0.0002809896 -4.321093e-05
## [4,] 0.0081128381 -0.04362921 -8.663088e-02 -0.0001192797 -1.334368e-05
## [5,] 0.0255457440 -0.07977505  1.169408e-03 -0.0003435793 -1.783017e-04
## [6,] 0.0007600395 -0.03691525 -7.887734e-02  0.0000856010 -1.312280e-04
##                yaw
## [1,]  0.000000e+00
## [2,] -1.649043e-05
## [3,] -1.591068e-04
## [4,] -9.216786e-05
## [5,] -6.443807e-05
## [6,]  5.631540e-06
## [1] 280   6

Slice-Timing Correction

A slice-timing correction does interpolation since each slice was not actually taken at the same time point, but a shifted time point over the course of an entire TR. The correction requires you to input the reference slice (in this case the median, ref_slice), the repetition time (tr), time between the first and the last slice within one scan (ta), and the order the slices were acquired. In our case, it was done in an ascending, contiguous order, so we created the slice order as such. If you used descending or interleaved acquisition, then this must be changed accordingly.

####################################
# Slice Timing Correction
####################################
if (have_matlab()) {
  aimg = spm12_slice_timing(
    filename = realigned[['outfiles']],
    nslices = nslices,
    tr = tr, 
    slice_order = slice_order,
    time_points = seq(n_time_points),
    ta = ta, 
    ref_slice = ref_slice,
    prefix = "a", 
    clean = FALSE, 
    retimg = FALSE,
    install_dir = install_dir
    )
  print(aimg)
}
## # Running matlabbatch job
## # Creating matlabbatch job
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/spm12\n
## Running job: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd71293bbb22.m, which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd712ed70f84.m
## Command run is:
## matlab  -nodesktop -nosplash   -nodisplay -r  "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd71293bbb22.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
## $spm
## $spm
## $spm$temporal
## $spm$temporal$st
## $spm$temporal$st$scans
## [1] "{{'/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,1'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,2'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,3'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,4'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,5'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,6'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,7'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,8'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,9'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,10'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,11'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,12'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,13'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,14'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,15'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,16'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,17'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,18'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,19'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,20'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,21'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,22'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,23'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,24'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,25'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,26'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,27'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,28'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,29'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,30'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,31'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,32'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,33'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,34'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,35'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,36'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,37'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,38'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,39'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,40'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,41'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,42'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,43'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,44'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,45'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,46'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,47'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,48'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,49'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,50'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,51'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,52'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,53'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,54'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,55'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,56'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,57'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,58'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,59'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,60'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,61'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,62'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,63'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,64'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,65'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,66'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,67'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,68'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,69'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,70'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,71'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,72'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,73'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,74'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,75'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,76'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,77'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,78'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,79'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,80'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,81'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,82'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,83'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,84'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,85'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,86'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,87'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,88'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,89'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,90'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,91'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,92'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,93'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,94'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,95'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,96'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,97'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,98'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,99'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,100'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,101'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,102'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,103'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,104'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,105'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,106'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,107'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,108'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,109'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,110'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,111'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,112'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,113'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,114'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,115'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,116'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,117'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,118'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,119'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,120'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,121'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,122'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,123'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,124'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,125'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,126'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,127'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,128'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,129'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,130'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,131'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,132'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,133'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,134'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,135'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,136'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,137'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,138'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,139'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,140'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,141'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,142'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,143'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,144'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,145'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,146'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,147'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,148'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,149'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,150'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,151'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,152'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,153'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,154'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,155'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,156'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,157'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,158'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,159'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,160'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,161'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,162'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,163'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,164'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,165'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,166'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,167'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,168'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,169'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,170'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,171'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,172'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,173'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,174'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,175'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,176'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,177'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,178'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,179'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,180'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,181'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,182'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,183'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,184'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,185'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,186'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,187'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,188'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,189'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,190'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,191'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,192'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,193'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,194'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,195'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,196'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,197'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,198'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,199'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,200'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,201'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,202'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,203'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,204'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,205'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,206'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,207'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,208'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,209'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,210'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,211'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,212'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,213'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,214'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,215'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,216'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,217'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,218'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,219'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,220'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,221'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,222'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,223'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,224'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,225'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,226'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,227'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,228'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,229'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,230'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,231'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,232'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,233'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,234'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,235'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,236'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,237'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,238'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,239'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,240'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,241'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,242'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,243'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,244'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,245'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,246'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,247'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,248'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,249'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,250'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,251'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,252'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,253'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,254'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,255'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,256'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,257'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,258'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,259'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,260'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,261'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,262'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,263'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,264'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,265'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,266'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,267'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,268'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,269'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,270'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,271'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,272'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,273'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,274'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,275'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,276'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,277'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,278'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,279'\n '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef/rfmri.nii,280'\n}\n}';"
## 
## $spm$temporal$st$nslices
## [1] 60
## 
## $spm$temporal$st$tr
## [1] 1.8
## 
## $spm$temporal$st$ta
## [1] 0
## 
## $spm$temporal$st$so
## [1] "[1740, 1680, 1620, 1560, 1500, 1440, 1380, 1320, 1260, 1200, 1140, 1080, 1020, 960, 900, 840, 780, 720, 660, 600, 540, 480, 420, 360, 300, 240, 180, 120, 60, 0, 1740, 1680, 1620, 1560, 1500, 1440, 1380, 1320, 1260, 1200, 1140, 1080, 1020, 960, 900, 840, 780, 720, 660, 600, 540, 480, 420, 360, 300, 240, 180, 120, 60, 0];"
## 
## $spm$temporal$st$refslice
## [1] 900
## 
## $spm$temporal$st$prefix
## [1] "'a'"
## 
## 
## 
## 
## attr(,"class")
## [1] "matlabbatch"
## 
## $script
## [1] "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd715c354b1f.m"
## 
## $orig_filename
## [1] "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/rfmri.nii"
## 
## $base_name
## [1] "rfmri.nii"
## 
## $temporary_directory
## [1] "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd713cdb37ef"
## 
## $outfile
## [1] "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/arfmri.nii"
## 
## $result
## [1] 0

We see the output aimg has the filename of the slice-timing corrected 4D image.

Spatial Normalization

AC-PC Alignment

For the subsequent image normalization steps, SPM assumes the data is aligned along the anterior commissure (AC) posterior commissure (PC) line (AC-PC). The acpc_reorient function (based on nii_setOrigin from Dr. Chris Rorden) will do this. The syntax is that the first file (mean_img) is used to estimate the line/plane and the subsequent files are reoriented using this estimation (aimg). These are changes to the header of the image and the image with the new header is written to the same file as the input file.

if (have_matlab()) {
  acpc_reorient(
    infiles = c(mean_img, aimg$outfile),
    modality = "T1",
    install_dir = install_dir
  )
}
## 
##  #Reorientation /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/meanfmri.nii
## Script created: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd7139d26f3f.m
## Command run is:
## matlab  -nodesktop -nosplash   -nodisplay -r  "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd7139d26f3f.m'); catch err, disp(err.message); exit(1); end; exit(0);"
##   /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/meanfmri.nii 
## "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/meanfmri.nii" 
##            /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/arfmri.nii 
##   "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/arfmri.nii"

Anatomical MRI Coregistration to Mean fMRI

Here we will perform the registration of the T1-weighted anatomical image into the space of the mean fMRI image after realignment. This is referred to as “co-registration” as it is within-subject registration, but across modalities (where we referred to within-subject, within-modality as realignment).

Here, we also reorient the anatomical image the AC-PC line. We then perform the coregistration using spm12_coregister, where the fixed image is the mean image and the moving image is the anatomical.

if (have_matlab()) {
  acpc_reorient(
  infiles = t1_fname,
  modality = "T1")
  coreg = spm12_coregister_estimate(
    fixed = realigned[["mean"]], 
    moving = t1_fname, 
    cost_fun = "nmi",
    retimg = FALSE,
    install_dir = install_dir
  )
}
## 
##  #Reorientation /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/anat.nii
## Script created: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd71703fc78b.m
## Command run is:
## matlab  -nodesktop -nosplash   -nodisplay -r  "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd71703fc78b.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## Checking Filenames
## # Running matlabbatch job
## # Creating matlabbatch job
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/spm12\n
## Running job: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd71437e5464.m, which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd717b963917.m
## Command run is:
## matlab  -nodesktop -nosplash   -nodisplay -r  "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd71437e5464.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
## # Removing scripts

We see the anatomical image has been transformed and resliced into the mean fMRI image space (and thus has the resolution of that image).

Anatomical MRI Segmentation (and Spatial Normalize Estimation)

Here we perform the segmentation of the co-registered anatomical image from above. This will segment the image into 6 different regions, where the regions are gray matter, white matter, cerebrospinal fluid (CSF), bone, soft tissue, and the background. You should inspect these visually before using them to ensure quality and no reordering due to artifacts.

if (have_matlab()) {
  seg = spm12_segment(
    filename = coreg$outfile,
    set_origin = FALSE, 
    bias_corrected = TRUE,
    native = TRUE,
    dartel = TRUE,
    unmodulated = TRUE,
    modulated = TRUE,
    affine = "mni",
    sampling_distance = 1.5,
    install_dir = install_dir,
    retimg = FALSE)
  print(names(seg))
}
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/spm12
## # Running script /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Executable.m
## which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Segment_job.m
## Command run is:
## matlab  -nodesktop -nosplash   -singleCompThread -nodisplay -r  "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Executable.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
## # Removing scripts
##  [1] "spm"                 "script"              "result"             
##  [4] "outfiles"            "outmat"              "deformation"        
##  [7] "inverse_deformation" "dartel"              "unmodulated"        
## [10] "modulated"           "bias_corrected"

In order to segment the image, SPM spatially normalizes the image to the MNI template, however. This transformation will be the one we use to transform the fMRI data to MNI space. We see in seg_reg a deformation file, which is the transformation. We also see the output segmentation files of the probability of each class, in native space. We only tend to care about the first 3 categories.

Applying Spatial Normalization Transformation

Now that we have estimated the transformation from the T1 image, we can take that deformation and apply it to the fMRI data using spm12_normalize_write. Again, we are registering to the MNI template and will use a standard bounding box. We pass the anatomical, mean fMRI, and 4D fMRI data in to be transformed.

if (have_matlab()) {
  norm = spm12_normalize_write(
    deformation = seg$deformation,
    other.files = aimg$outfile,
    bounding_box = matrix(
      c(-78, -112, -70, 
        78, 76, 85), nrow = 2, 
      byrow = TRUE),
    interp = "bspline5",
    retimg = FALSE,
    install_dir = install_dir
  )
  
  mean_norm = spm12_normalize_write(
    deformation = seg$deformation,
    other.files = mean_img,
    bounding_box = matrix(
      c(-78, -112, -70, 
        78, 76, 85), nrow = 2, 
      byrow = TRUE),
    interp = "bspline5",
    retimg = FALSE,
    install_dir = install_dir
    )  
  
  anat_norm = spm12_normalize_write(
    deformation = seg$deformation,
    other.files = seg$bias_corrected,
    bounding_box = matrix(
      c(-78, -112, -70, 
        78, 76, 85), nrow = 2, 
      byrow = TRUE),
    interp = "bspline5",
    voxel_size = c(1, 1, 1),
    retimg = FALSE,
    install_dir = install_dir
  )
  
  anat_norm2x2x2 = spm12_normalize_write(
    deformation = seg$deformation,
    other.files = seg$bias_corrected,
    bounding_box = matrix(
      c(-78, -112, -70, 
        78, 76, 85), nrow = 2, 
      byrow = TRUE),
    interp = "bspline5",
    voxel_size = c(2, 2, 2),
    retimg = FALSE,
    install_dir = install_dir
  )  
}
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/spm12
## # Running script /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Executable.m
## which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Normalize_Write_job.m
## Command run is:
## matlab  -nodesktop -nosplash   -singleCompThread -nodisplay -r  "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Executable.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
## # Removing scripts
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/spm12
## # Running script /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Executable.m
## which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Normalize_Write_job.m
## Command run is:
## matlab  -nodesktop -nosplash   -singleCompThread -nodisplay -r  "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Executable.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
## # Removing scripts
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/spm12
## # Running script /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Executable.m
## which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Normalize_Write_job.m
## Command run is:
## matlab  -nodesktop -nosplash   -singleCompThread -nodisplay -r  "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Executable.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
## # Removing scripts
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/spm12
## # Running script /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Executable.m
## which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Normalize_Write_job.m
## Command run is:
## matlab  -nodesktop -nosplash   -singleCompThread -nodisplay -r  "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Executable.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
## # Removing scripts

Now we have the indirect spatially normalized data in MNI template space.

Spatial Smoothing

Here we will perform spatial smoothing of the 4D fMRI data in template space. We can set the full-width half max (FWHM) for the Gaussian smoother. The relationship between the FWHM and the Gaussian standard deviation is:

\[ FWHM = \sigma \sqrt{8 \log(2)} \] where \(\log\)` is the natural log.

if (have_matlab()) {
  smooth_norm = spm12_smooth(
    norm$outfiles[[1]], 
    fwhm = 5, 
    prefix = "s5",
    retimg = FALSE,
    install_dir = install_dir
    )
}
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/spm12
## # Running script /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Executable.m
## which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Smooth_job.m
## Command run is:
## matlab  -nodesktop -nosplash   -singleCompThread -nodisplay -r  "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/Executable.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
## # Removing scripts

In many applications, this is the data you will use for post-processing and analysis. Motion correction has usually been applied above, but some motion correct this data as well.

First Level Model

Estimate Model

output_directory = file.path(run_dir, "output")
if (!dir.exists(output_directory)) {
  dir.create(output_directory)
}
output_directory = normalizePath(output_directory)

################################
# Same model just using condition list
################################
condition_list = list(
  list(name = "LeftHand",
       onset = c(20, 100, 180, 260, 340, 420),
       duration = c(20, 20, 20, 20, 20, 20)
  ),
  list(name = "RightHand",
       onset = c(60, 140, 220, 300, 380, 460),
       duration = c(20, 20, 20, 20, 20, 20)
  )
)
if (have_matlab()) {
  first_model = spm12_first_level(
    scans = smooth_norm$outfiles,
    n_time_points = n_time_points,
    units = "secs",
    slice_timed = FALSE,
    tr = tr,
    condition_list = condition_list,
    regressor_mat = rpfile,
    outdir = output_directory,
    clean = FALSE,
    install_dir = install_dir
  )
  
  cons = list.files(
    pattern = "beta.*[.]nii", 
    path = output_directory,
    full.names = TRUE)
  print(cons)
}
## Warning in normalizePath(spm): path[1]="/private/var/folders/1s/
## wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/filebd7177efc44/output/SPM.mat": No
## such file or directory
## # Running matlabbatch job
## # Creating matlabbatch job
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/spm12\n
## Running job: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd71acf8c3a.m, which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd71543d6573.m
## Command run is:
## matlab  -nodesktop -nosplash   -nodisplay -r  "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd71acf8c3a.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
## [1] "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/filebd7177efc44/output/beta_0001.nii"
## [2] "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/filebd7177efc44/output/beta_0002.nii"
## [3] "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/filebd7177efc44/output/beta_0003.nii"
## [4] "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/filebd7177efc44/output/beta_0004.nii"
## [5] "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/filebd7177efc44/output/beta_0005.nii"
## [6] "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/filebd7177efc44/output/beta_0006.nii"
## [7] "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/filebd7177efc44/output/beta_0007.nii"
## [8] "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/filebd7177efc44/output/beta_0008.nii"
## [9] "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/filebd7177efc44/output/beta_0009.nii"

Contrast Manager - Creating Contrasts

contrasts = list(
  list(
    name = "LeftHand",
    weights = c(1, rep(0, 7)),
    replicate = "none",
    type = "T" ),
  list(name = "RightHand",
       weights = c(0, 1, rep(0, 6)),
       replicate = "none",
       type = "T"), 
  list(name = "AllEffects",
       weights = rbind(
         c(1, rep(0, 7)),
         c(0, 1, rep(0, 6))
       ),
       replicate = "none",
       type = "F")   
)


if (have_matlab()) {
  contrast_res = spm12_contrast_manager(
    spm = first_model$spmmat,
    delete_existing = TRUE,
    contrast_list = contrasts,
    clean = FALSE,
    install_dir = install_dir
  )
}
## # Running matlabbatch job
## # Creating matlabbatch job
## # Adding SPMDIR: /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpOTmLMy/Rinstbd3f773fd5c5/spm12r/spm12\n
## Running job: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd714e970f91.m, which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd7121c601a9.m
## Command run is:
## matlab  -nodesktop -nosplash   -nodisplay -r  "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd714e970f91.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0
if (have_matlab()) {
  # dir(output_directory)
  
  cons = list.files(
    pattern = "con.*[.]nii", path = output_directory,
    full.names = TRUE)
  print(cons)
  stats = list.files(
    pattern = "spm(T|F).*[.]nii", 
    path = output_directory,
    full.names = TRUE)
  print(stats)
  spm1 = grep("spmT_0001", stats, value = TRUE)
  stats_img = readnii(spm1)
  t1_fname = anat_norm2x2x2$outfiles
  t1 = readnii(t1_fname)
  ortho2(t1, stats_img, col.y = scales::alpha(hotmetal(), 0.5))

  normed_mean = readnii(mean_norm$outfiles)
  ortho2(t1, normed_mean, col.y = scales::alpha(hotmetal(), 0.25))
  ortho2(t1, normed_mean, col.y = scales::alpha(hotmetal(), 0.25),
         xyz = c(32, 40, 32))
  
  # anat_img = readnii(anat_norm2x2x2$outfiles)
  # stat_t = readnii(stats[2])
}
## [1] "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/filebd7177efc44/output/con_0001.nii"
## [2] "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/filebd7177efc44/output/con_0002.nii"
## [1] "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/filebd7177efc44/output/spmF_0003.nii"
## [2] "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/filebd7177efc44/output/spmT_0001.nii"
## [3] "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/Rtmpmjc48T/filebd7177efc44/output/spmT_0002.nii"
## Warning in datatyper(nim, warn = warn): Need to change bitpix and datatype to
## FLOAT64 due to NAs

contrast_query_list = list(
  list(name = "LeftHand",
       weights = 1,
       threshold_type = "FWE",
       number_extent_voxels = 0,
       mask_type = "None"),
  list(name = "RightHand",
       weights = 2,
       threshold_type = "FWE",
       number_extent_voxels = 0,
       mask_type = "None")  
)

contrast_query_list = 
  list(
    list(
    name = "All Contrasts",
    weights = Inf,
    threshold_type = "FWE",
    number_extent_voxels = 0,
    mask_type = "None")
  )
if (have_matlab()) {
  display = all(Sys.getenv("DISPLAY") != "")
  desktop = display
  result_format = "csv"
  results = spm12_results(
    spm = first_model$spmmat,
    units = "Volumetric",
    result_format = result_format,
    contrast_list = contrast_query_list,
    clean = FALSE,
    display = display,
    desktop = FALSE,
    write_images = "binary_clusters",
    image_basename = "thresholded",
    install_dir = install_dir
    )
  out_results = list.files(
    pattern = paste0("spm.*[.]", result_format),
    path = output_directory,
    full.names = TRUE)  
  # out_dir = spm_directory(spm = first_model$spmmat)
}
## # Running matlabbatch job
## Warning in spm12_results(spm = first_model$spmmat, units = "Volumetric", :
## Writing Images may require desktop = TRUE
## # Creating matlabbatch job
## # Adding SPMDIR: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/spm12\n
## Running job: /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd71d765567.m, which calls /var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd717913f5eb.m
## Command run is:
## matlab  -nodesktop -nosplash    -r  "try, run('/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmpmjc48T/filebd71d765567.m'); catch err, disp(err.message); exit(1); end; exit(0);"
## # Result is 0

Bibliography

bib = '@article{ashburner2005unified,
  title={Unified segmentation},
  author={Ashburner, John and Friston, Karl J},
  journal={Neuroimage},
  volume={26},
  number={3},
  pages={839--851},
  year={2005},
  publisher={Elsevier}
}'