R notebook for analysis of frontal eye field coordinates in the sacc-tDCS dataset.

Setup

# Load some libraries
library(here) # file paths
here() starts at /Volumes/research$/reteig/sacc-tDCS
library(tidyverse) # importing, transforming, and visualizing data frames
Loading tidyverse: ggplot2
Loading tidyverse: tibble
Loading tidyverse: tidyr
Loading tidyverse: readr
Loading tidyverse: purrr
Loading tidyverse: dplyr
Conflicts with tidy packages ---------------------------------------------------------------------------------
filter(): dplyr, stats
lag():    dplyr, stats
library(knitr) # R markdown output (html, pdf, etc.)
# set default output and figure options
knitr::opts_chunk$set(message = FALSE, warning = FALSE, fig.width = 7, fig.asp = 0.618, out.width = "75%", fig.align = "center")
sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] knitr_1.15.1    dplyr_0.5.0     purrr_0.2.2     readr_1.1.0     tidyr_0.6.1     tibble_1.3.0
[7] ggplot2_2.2.1   tidyverse_1.1.1 here_0.1

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.10     cellranger_1.1.0 compiler_3.4.0   plyr_1.8.4       forcats_0.2.0    tools_3.4.0
 [7] jsonlite_1.4     lubridate_1.6.0  gtable_0.2.0     nlme_3.1-131     lattice_0.20-35  psych_1.7.3.21
[13] DBI_0.6-1        parallel_3.4.0   haven_1.0.0      xml2_1.1.1       stringr_1.2.0    httr_1.2.1
[19] hms_0.3          rprojroot_1.2    grid_3.4.0       R6_2.2.0         readxl_1.0.0     foreign_0.8-67
[25] reshape2_1.4.2   modelr_0.1.0     magrittr_1.5     backports_1.0.5  scales_0.4.1     rvest_0.3.2
[31] assertthat_0.2.0 mnormt_1.5-5     colorspace_1.3-2 stringi_1.1.5    lazyeval_0.2.0   munsell_0.4.3
[37] broom_0.4.2     

List the subjects that were excluded in the eye data analyses.

subs2exclude <- c("S21","S25","S16","S22","S28")

Coordinates in native space

These were determined for each subject’s scan; see neuronav_notes.md for further info.

dataFile <- here("data", "FEF_coords_native.csv")
nativeCoords <- read_csv2(dataFile)
nativeCoords %>% 
  select(-folder, -scan) %>% # drop columns with folder and scan names
  filter(!(subject %in% subs2exclude)) %>% # drop rows with excluded subjects
  kable(.)
subject native.X native.Y native.Z
S01 96 132 137
S02 89 118 132
S03 153 124 177
S04 96 127 131
S05 93 116 138
S06 101 131 182
S07 92 127 147
S08 101 123 159
S09 99 125 158
S10 94 124 125
S11 147 123 149
S12 97 121 176
S13 144 125 140
S14 87 122 129
S15 118 111 125
S17 161 135 175
S18 153 147 173
S19 146 155 172
S20 78 124 99
S24 160 134 141
S26 156 141 150
S27 148 122 156
S29 90 131 153
S30 95 125 149
S32 147 140 146
S33 159 149 168

Transform to MNI space

Run shell script

mni_coords.sh reads in the native coordinates, converts them to MNI space, and writes out a .csv of the same format as for the native coordinates.

Under # FSL setup, replace FSLDIR with the directory path you installed FSL to.

Arguments:

  1. Input: csv file with coordinates in native space
  2. Output: csv file coordinates in MNI space
  3. Passing all as a 3rd argument first (re)runs skull stripping and registration to the MNI template.
# FSL Setup
FSLDIR=/usr/local/fsl
PATH=${FSLDIR}/bin:${PATH}
export FSLDIR PATH
. ${FSLDIR}/etc/fslconf/fsl.sh

# Run shell script to compute MNI coordinates
bash src/func/mni_coords.sh data/FEF_coords_native.csv data/FEF_coords_MNI.csv all

MNI coordinates

Load in the MNI coordinates that were written to a .csv file by the shell script.

dataFile <- here("data", "FEF_coords_MNI.csv")
mniCoords <- read_delim(dataFile, ";")
mniCoords <- filter(mniCoords, !(subject %in% subs2exclude)) # exclude subjects
mniCoords %>%
  select(-folder, -scan) %>% # drop columns with folder and scan names
  kable(.)
subject MNI_X MNI_Y MNI_Z
S01 29.4081 1.069700 54.8724
S02 33.0338 -2.245090 50.4239
S03 30.5837 -1.480360 50.5881
S04 25.7061 -3.761730 56.3648
S05 29.7780 -5.201110 55.8046
S06 29.7783 -1.120820 58.2622
S07 38.1233 2.975730 45.9613
S08 31.5014 0.526375 45.6200
S09 28.5103 3.632940 51.2804
S10 28.1080 -1.933630 50.7210
S11 30.5811 -3.787490 51.9535
S12 36.5129 -0.386049 46.7630
S13 26.2263 -1.069220 54.7079
S14 37.5005 -1.588150 52.5889
S15 31.8188 -8.357000 58.9671
S17 31.0229 -5.121250 54.3116
S18 34.9669 8.390570 49.8188
S19 28.0703 -3.834910 52.7607
S20 41.2127 -1.745790 47.5514
S24 37.3474 -0.862753 43.4371
S26 34.3288 -2.861210 49.1761
S27 27.6566 -10.061100 50.9743
S29 30.3161 -5.272910 55.2661
S30 26.8320 -3.868670 54.5619
S32 29.0049 4.888810 49.1404
S33 30.3099 -3.897600 50.9083

Calculate statistics over subjects:

mniCoords %>%
  gather(dimension, coord, MNI_X:MNI_Z) %>%
  group_by(dimension) %>%
  summarise(average = mean(coord), standard.deviation = sd(coord), minimum = min(coord), maximum = max(coord)) %>%
  kable(.)
dimension average standard.deviation minimum maximum
MNI_X 31.470735 4.036810 25.7061 41.21270
MNI_Y -1.806643 3.931623 -10.0611 8.39057
MNI_Z 51.645608 3.922225 43.4371 58.96710

Create spherical ROI for each coordinate

Exclude subjects

Write a new `.csv’ file with MNI coordinates, without the coordinates from the excluded subjects.

exclMNI <- here("data", "FEF_coords_MNI_excl.csv")
write_delim(mniCoords, exclMNI, delim = ";")
Sys.setenv(exclMNI = exclMNI) # port variable with csv file name to bash

Run script

The coords can be very nicely visualized with Surf Ice by running the plot_coords.m script (requires MATLAB)

Alternatively, fef_rois.sh takes the MNI coordinates and adds spherical masks, centered around each subjects FEF coordinate, to the MNI template.

Under # FSL setup, replace FSLDIR with the directory path you installed FSL to.

Arguments:

  1. Input: csv file with coordinates in MNI space
  2. Output: NIfTI file of MNI_152_1mm template with spherical ROI around each subject’s frontal eye field
  3. Radius of the spherical ROI in mm
# FSL Setup
FSLDIR=/usr/local/fsl
PATH=${FSLDIR}/bin:${PATH}
export FSLDIR PATH
. ${FSLDIR}/etc/fslconf/fsl.sh

# Run shell script to make spherical ROIs
bash src/func/fef_rois.sh $exclMNI neuronav/FEF_ROIs_bigspheres.nii.gz 2
LS0tCnRpdGxlOiAic2FjYy10RENTOiBGcm9udGFsIEV5ZSBGaWVsZCBjb29yZGluYXRlcyIKYXV0aG9yOiAiTGVvbiBSZXRlaWciCm91dHB1dDoKICBnaXRodWJfZG9jdW1lbnQ6CiAgICB0b2M6IHRydWUKICAgIHRvY19kZXB0aDogMgogIGh0bWxfbm90ZWJvb2s6IAogICAgaGlnaGxpZ2h0OiBweWdtZW50cwogICAgdG9jOiB0cnVlCiAgICB0b2NfZmxvYXQ6IHRydWUKLS0tCgpSIG5vdGVib29rIGZvciBhbmFseXNpcyBvZiBmcm9udGFsIGV5ZSBmaWVsZCBjb29yZGluYXRlcyBpbiB0aGUgYHNhY2MtdERDU2AgZGF0YXNldC4KCiMgU2V0dXAKCmBgYHtyIHNldHVwfQojIExvYWQgc29tZSBsaWJyYXJpZXMKbGlicmFyeShoZXJlKSAjIGZpbGUgcGF0aHMKbGlicmFyeSh0aWR5dmVyc2UpICMgaW1wb3J0aW5nLCB0cmFuc2Zvcm1pbmcsIGFuZCB2aXN1YWxpemluZyBkYXRhIGZyYW1lcwpsaWJyYXJ5KGtuaXRyKSAjIFIgbWFya2Rvd24gb3V0cHV0IChodG1sLCBwZGYsIGV0Yy4pCiMgc2V0IGRlZmF1bHQgb3V0cHV0IGFuZCBmaWd1cmUgb3B0aW9ucwprbml0cjo6b3B0c19jaHVuayRzZXQobWVzc2FnZSA9IEZBTFNFLCB3YXJuaW5nID0gRkFMU0UsIGZpZy53aWR0aCA9IDcsIGZpZy5hc3AgPSAwLjYxOCwgb3V0LndpZHRoID0gIjc1JSIsIGZpZy5hbGlnbiA9ICJjZW50ZXIi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