ABCDCon
Repository details
This repository contains the code used to collect data and generate analyses for the following paper:
The scripts contained here were used to collect and analyze data using Matlab r2014b and R version 3.3.2 run in RStudio and have not been tested for compatibility with later versions or across operating systems. They are provided for the purposes of openness and transparency of the data generation and analysis process.
Note, these are the scripts I used at the time of data collection and analysis and I might suggest more efficient or cleaner coding solutions to the same problems now (so use at your own risk and please be kind if you find bugs).
Environment setup
Setting paths
- Copy the config.yml.example file to config.yml and edit the paths for the current machine.
cp config.yml.example config.yml
vim config.yml
Python
- Install python
- Install python requirements:
pip install -r requirements.txt
R
- Required pacakges:
- dplyr (>= 0.4.0)
- ggplot2 (>= 1.0.1)
- halle (>=0.5.6)
- lme4(>= 1.1-11)
- R.matlab (>= 3.2.0)
- reshape2(>= 1.4.1)
- stringr (>= 1.0.0)
- tidyr (>= 0.2.0)
- yaml (>= 2.1.13)
Outside functions and packages
Code from other sources has been included in the vendor
directory. This is not code that I wrote and therefore is subject to the usage license and instructions of those authors. It is included here out of convenience for those trying to run the scripts in the current repository.
Scripts
Variables that are common across Matlab scripts will be set by scripts/mri_analyses/initialize_ABCDCon.m
(This will need to be added to your Matlab path).
Data collection
- These scripts are all contained in
scripts/run_task
- For the study, scripts were run in the following order:
ABCDCon_contextEnc.m
ABCDCon_objectEnc.m
ABCDCon_objectRecog_MRI.m
ABCDCon_locationRecog.m
Behavioral data analysis
These scripts can be found in abcdcon_RScripts
. They are setup as an R package for ease of loading required packages and functions, but this is probably a non-standard use of an R package. You should open abcdcon.Rproj
and then run scripts from here (this should set the current working directory correctly without using setwd()
).
load_ABCDCon.R
analyze_ABCDCon.R
MRI: Univariate analyses
Assumes have already run load_ABCDCon.R
, downloaded .zip MRI files, converted dicom images, set subject-specific folder names, commonized folder names (e.g., run1
instead of whatever the MRI scanner outputs), and run data quality assurance. Scripts assume they are being run relative to scripts/mri_analyses
.
- Preprocess the data using
preprocess.m
- Generate regressors for the first-level analyses using
generate_regressors.m
- Run first-level analyses using
first_level.m
- Put contrast images into MNI space using
new_segment_write_deformations_batch.m
- Smooth the resultant
wcon
images using a 3mm kernal. (I set this up manually in the SPM GUI.) - Run second-level (group) analyses using
second_level_job.m
MRI: Multivariate analyses
Assumes you have already preprocessed, run QA (to generate spike regressors), and have traced ROIs.
- Generate single-trial regressors using
RSA_generate_single_trial_regressors.m
- Estimate the single trial betas using
RSA_single_trial_models_batch.m
- Identify outlier beta timepoints using
RSA_beta_timeseries_graphs.m
to visually identify the group threshold and thenRSA_beta_timeseries_id_outliers.m
to mark excluded betas on a subject-by-subject basis - Gather the ROIs of interest ensuring that have them split so can look at body separate from head and tail. This involves extracting the ROIs of interest from the ASHS tracing files (
RSA_extractROIs.m
), combining subfields (RSA_combine_rois.py
), and splitting along the long axis (RSA_split_anterior_posterior.m
).- In order to split into head/body/tail, you must manually identify transitions. The slice numbers that define the subject-unique transitions are written out into files; the splitting scripts will assume the transitions file is in the <RAW_BEHAVIORAL> directory for each subject and are called
s*_hc_transitions.yml
. Use thehc_transitions.yml.example
file for consistent formatting.
- In order to split into head/body/tail, you must manually identify transitions. The slice numbers that define the subject-unique transitions are written out into files; the splitting scripts will assume the transitions file is in the <RAW_BEHAVIORAL> directory for each subject and are called
- Reslice the ROIs into EPI space (if using ASHS, these will be in T2 space) using
RSA_reslice_t2_and_ROIs_batch.m
- Binarize the ROIs so they can be used as masks using
RSA_binarize_ROIs_batch.m
- Generate trial labels
- This is a convoluted system that should be re-implemented differently if these analysis scripts were re-generated from scratch. However, what I did was first extract trial IDs from the single trial betas using
RSA_trial_ids_from_betas.m
and then usedecode_single_trial_labels.R
to mark trials that needed to be excluded (e.g., outlier betas).
- This is a convoluted system that should be re-implemented differently if these analysis scripts were re-generated from scratch. However, what I did was first extract trial IDs from the single trial betas using
- Extract beta values for trials of interest using
RSA_btwn_runs_exclude_outlier_trials.m
- Calculate the pattern similarity values of interest using
pattern_similarity_no_outlier_trials_load_data_btwn_runs.R
- Analyze using mixed models with
mixed_models.R
Supplemental analyses
- Use FIR to estimate shape of univariate response in each subfield (Supplemental Figure 3):
- Generate FIR regressors:
control_analysis_RSA_generate_single_trial_regressors_FIR.m
- Estimate FIR models:
control_analysis_first_level_FIR.m
- Extract beta values:
control_analysis_FIR_to_GLM_extract_betas.m
- Plot the data:
control_analysis_FIR_to_GLM_plot_betas.R
- Estimate univariate activity within each ROI (Supplemental Figure 4):
- Grab univariate activity by ROI:
control_analysis_univariate_contrast_estimates_by_roi.m
- Plot:
abcdcon_RScripts/control_analysis_summarize_univar_contrast_estimates_by_roi.R
- Look at distribution of beta values (Supplemental Figure 6)
- Get trial-wise mean betas:
control_analysis_betas_by_ROI.m
- Plot distrubtions:
control_analysis_plot_betas_by_ROI.m
- Plot individual pattern similarity data (Supplemental Figure 7):
control_analysis_plot_PS_matrices.R
- Estimate pattern similarity in "control" ROIs (Supplemental Figure 8):
control_analysis_mixed_models_other_ROIs.R
- Randomly select trials so that all conditions have equal bin sizes (Supplemental Figure 9):
control_analysis_matched_trial_numbers.R
- Correlate pattern similarity with reaction times (Supplemental Figure 10):
control_analysis_PS_RT_correlations.R
- Remove voxels of influence:
- Identify influential voxels:
control_analysis_drop_voxels.R
- Remove these voxels from pattern matrices:
control_analysis_remove_top_voxels.m
- Re-compute PS without these voxels:
control_analysis_PS_truncated_voxels.R
- Run stats:
control_analysis_PS_truncated_voxels_mixed_models.R