Skip to content

Instantly share code, notes, and snippets.

@divyanganar
Last active March 20, 2020 06:21
Show Gist options
  • Save divyanganar/399fc2021d838a1b81078180bd732a18 to your computer and use it in GitHub Desktop.
Save divyanganar/399fc2021d838a1b81078180bd732a18 to your computer and use it in GitHub Desktop.
White matter and CSF signal regression using Matlab and FSL
path = '/data/nimble/work/Divyangana_Rakesh/resting_state/t3/fmriprep';
subjectNames = dir(sprintf('%s',path));
subs = startsWith({subjectNames.name},'sub') & ~contains({subjectNames.name},'.html');
subject_names = {subjectNames.name};
subject_names = subject_names(subs);
TR = 1.4;
upper=((1/TR)/2)*100; upper=num2str(upper);
lower=((1/TR)/2)*10; lower=num2str(lower);
for i = 1:length(subject_names)
cd (sprintf('%s/%s/func',path,subject_names{i}))
fmrifile = sprintf('%s_task-rest_space-MNI152NLin2009cAsym_desc-smoothAROMAnonaggr_bold.nii',subject_names{i});
confounds = tdfread(sprintf('%s_task-rest_desc-confounds_regressors.tsv',subject_names{i}));
csf = confounds.csf;
wm = confounds.white_matter;
conf = [wm csf];
writetable(table(conf), 'conf.txt', 'Delimiter', ' ','WriteVariableNames',false)
% regress white matter and csf signal
output_name_wm_csf = sprintf('%s_bptf_AROMA_wm_csf.nii.gz',subject_names{i});
fprintf('regressing out WM, CSF signal for %s, index: %d\n',subject_names{i},i)
system(['/usr/local/fsl/bin/fsl_regfilt -i ' , fmrifile , ' -d conf.txt -f "1" ' '-o ' , output_name_wm_csf]);
% bandpass filter the data
fprintf('calculating the mean image for %s, index: %d\n',subject_names{i},i);
output_bptf_filename = sprintf('%s_AROMA_bptf_wm_csf.nii.gz',subject_names{i});
system(['/usr/local/fsl/bin/fslmaths ' , output_name_wm_csf , ' -Tmean mean.nii.gz']);
fprintf('bandpass filtering for %s, index: %d\n',subject_names{i},i)
system(['fslmaths ' , output_name_wm_csf , ' -bptf ' upper ' ' lower ' -add mean.nii.gz ' , output_bptf_filename]);
delete('mean.nii.gz');
end
% gsr = confounds.global_signal;
% conf_with_gsr = [wm csf gsr];
% writetable(table(conf_with_gsr), 'conf_with_gsr.txt', 'Delimiter', ' ','WriteVariableNames',false)
% output_name_gsr = sprintf('%s_bptf_AROMAnonaggr_wm_csf_gsr.nii.gz',subject_names{i});
% fprintf('regressing out GSR, WM, CSF signal for %s, index: %d\n',subject_names{i},i)
% system(['/usr/local/fsl/bin/fsl_regfilt -i ' , fmrifile , ' -d conf_with_gsr.txt -f "1" ' '-o ' , output_name_gsr]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment