- I don't process my data
- MATLAB/SPM
- R
- Python/Nipype
- BrainVoyager/FreeSurfer/AFNI
- Other
- Stata/SAS (just kidding)
April 10, 2016
Multi-sequence MRI dataset from Kirby 21 (https://www.nitrc.org/projects/multimodal):
files
anatomical functional
"KKI2009-19-MPRAGE.nii.gz" "KKI2009-19-fMRI.nii.gz" oro.nifti (Brandon Whitcher, CRAN)nifti object (S4)
image.nifti, orthographic

spm12r (me, CRAN)Requires MATLAB (installs SPM to R library)
spm12_slice_timing - slices are not taken instantaneouslyspm12_realign - people movespm12_coregister - structural imaging is higher resolutionspm12_segment - where's the gray matter?spm12_normalize - brains look better in MNIspm12_smooth - turn that noise downfslr (me, CRAN)nifti objectfslmaths - image manipulationfslstats - image statisticsfslbet - brain extraction/skull strippingortho2, double_ortho
fslr (me, CRAN)fsl_slicetimer - slices are not taken instantaneouslymcflirt - people moveflirt - structural imaging is higher resolutionfast - where's the gray matter? (not that fast)flirt+fnirt - brains look better in MNIfslsmooth - turn that noise downnifti objectfslr: readnii wraps oro.nifti::readNIfTI:
library(fslr) img = readnii(files["functional"]); print(img)
NIfTI-1 format Type : nifti Data Type : 16 (FLOAT32) Bits per Pixel : 32 Slice Code : 0 (Unknown) Intent Code : 0 (None) Qform Code : 1 (Scanner_Anat) Sform Code : 0 (Unknown) Dimension : 80 x 80 x 37 x 210 Pixel Dimension : 3 x 3 x 3.97 x 1 Voxel Units : mm Time Units : Unknown
fsl_slicetimer will do slice timing correction
tr = 2 # 2 seconds first_scan = floor(10.0 / tr) + 1 # 10 seconds "stabilization of signal" img = subset_4d(img, first_scan:ntim(img)) aimg = fsl_slicetimer(img, tr = 2, indexing = "up", acq_order = "contiguous") print(dim(aimg))
[1] 80 80 37 205
print(voxdim(aimg))
[1] 3.000000 3.000000 3.972973
library(fslr); median_image = apply(aimg, c(1, 2, 3), median) ortho2(median_image)

image(median_image, z = 18, plot.type = "single")

ANTsR (Brian Avants, GitHub)Located at https://github.com/stnava/ANTsR

extrantsr ("extra ANTsR", me, GitHub)Located at https://github.com/muschelli2/extrantsr
ANTsR functionality
nifti object useants2oro conversion for ANTs images to nifti
antsMotionCalculation calculates motion parameters (rp)motionCorrectionResults = antsMotionCalculation( boldImage, fixed = average_image, txtype = "Rigid")

timeseries2matrix creates \(T\times V\) matrix, \(V\) voxels in mask
averageImage = getAverageOfTimeSeries(moco_img) boldMatrix = timeseries2matrix(img = moco_img, mask = averageImage > mean(averageImage)) print(dim(boldMatrix))

computeDVARS does what the names says
DVARS = computeDVARS(boldMatrix) fd = motionCorrectionResults$fd

compcor: PCA on high-variance voxels (Behzadi et al. 2007)
compCorNuisanceVariables = compcor(moco_img, maskImage, ncompcor = 6) nuisanceVariables = cbind(moco_params, compCorNuisanceVariables)


lm works great here for regression \(\left(\text{data is }T×V\right)\)
nuisanceVariables = scale(nuisanceVariables) nuisance_mod = lm(boldMatrix ~ nuisanceVariables) rMatrix = residuals(nuisance_mod)

frequencyFilterfMRI calls mFilter::cffilterrMatrix = frequencyFilterfMRI(rMatrix, tr = 2, freqLo = 0.01, freqHi = 0.1, opt = "trig")

smoothImage - Gaussian smoothing FWHM = 6mm\(^3\)cleanBoldImage = matrix2timeseries(boldImage, maskImage, rMatrix) smoothCleanBoldImage = smoothImage(cleanBoldImage, sigma = c(rep(6, 3), 0), FWHM = TRUE)

fmri package (ask Joerg)AnalyzeFMRIcudaBayesregBehzadi, Yashar, Khaled Restom, Joy Liau, and Thomas T Liu. 2007. “A Component Based Noise Correction Method (CompCor) for BOLD and Perfusion Based FMRI.” Neuroimage 37 (1). Elsevier: 90–101.