-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_first_func.m
171 lines (129 loc) · 6.29 KB
/
run_first_func.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
function [] = run_first_func(subject)
%clear all
%==========================================================================
% Add paths - edit this section
%==========================================================================
% this section should add paths to all revevent scipts and toolboxes, which
% include: SPM, REST, marsbar and the current set of scripts
% where spm is
% spmdir = '/media/lindenmp/WD_2TB/Dropbox/scripts/matlab/spm8/';
spmdir = '/usr/local/spm8/matlab2014a.r5236/';
% addpath(genpath(spmdir));
% where REST is
% addpath(genpath('~/Dropbox/scripts/matlab/REST_V1.8_130615/'))
% directory where marsbar is. Path will be added and removed as required in
% script below to avoid conflict with spm routines
% marsbar_dir = '~/Dropbox/scripts/matlab/spm8/toolbox/marsbar/';
% where the pre-processing scripts are
% addpath(genpath('~/Dropbox/scripts/projects/OCDPG/rest_prepro/'))
addpath(genpath('/gpfs/M2Home/kristina_s/Monash076/Kristina/GenofCog/code/rest_prepro/'))
% set FSL environments
fsldir = '/usr/local/fsl/5.0.8/bin/'; % directory where fsl is
setenv('FSLDIR',fsldir(1:end-4));
setenv('FSLOUTPUTTYPE','NIFTI');
% setup Wavelet toolbox
% addpath('~/Dropbox/scripts/matlab/BrainWavelet')
% setup
% ------------------------------------------------------------------------------
% Subject list
% ------------------------------------------------------------------------------
%sublist='/gpfs/M2Home/kristina_s/Monash076/Kristina/GenofCog/code/sublists/trial.txt';
%fileID = fopen(sublist);
%subs = textscan(fileID,'%s');
%subs = subs{1};
% ------------------------------------------------------------------------------
% ROIs
% ------------------------------------------------------------------------------
roidir = '/gpfs/M2Home/kristina_s/Monash076/Kristina/GenofCog/code/ROIspheres/';
% generate list of roi file names
roifiles = dir([roidir,'*.nii']);
% ------------------------------------------------------------------------------
% Project dir
% ------------------------------------------------------------------------------
projdir = '/gpfs/M2Home/kristina_s/Monash076/Kristina/GenofCog/data/';
%for i = 1:length(subs)
%fprintf(1,'Processing subject %s\n',subs)
% ------------------------------------------------------------------------------
% Unzip archive
% ------------------------------------------------------------------------------
%subdir = [projdir,subs{i}];
%cd(subdir)
%jar xvf('rfMRI_Archive.zip')
%unzip('t1_Archive.zip')
% ------------------------------------------------------------------------------
% Inputs
% ------------------------------------------------------------------------------
% Directory of processed rfMRI data
rawdir = [projdir,subject,'/rfMRI/'];
cd(rawdir)
% Directory of T1 data
t1dir = [projdir,subject,'/t1/'];
gm = [t1dir,'crwc1t1.nii'];
extract_in = 'srest_prepro.nii';
% length of time series (no. vols)
N = 620;
% Repetition time of acquistion in secs
TR = 0.754;
%==========================================================================
% Extract ROI time series
%==========================================================================
roi_ts = [];
for i = 1:length(roifiles)
tic;
system([fsldir,'fslmaths ',[roidir,roifiles(i).name],' -mul ',gm,' roi_gs']);
system([fsldir,'fslmeants -i ',extract_in,' -o temp.txt -m roi_gs -w']);
roi_ts(:,i) = dlmread([rawdir,'temp.txt']);
fprintf('Time series extracted for ROI %d of %d \n',i,length(roifiles));
toc;
end
% Save out time series as .mat file
save('DiMartino_roi_ts.mat','roi_ts')
% ------------------------------------------------------------------------------
% Run first level
% ------------------------------------------------------------------------------
cd(rawdir);
% Split EPI into 3D files
spm_file_split(extract_in)
% Left hemi
R = roi_ts(:,1:6);
save spm_regs_L R
% estimate first level
mkdir('FirstLevel_L_DiMartino');
movefile('spm_regs_L.mat','FirstLevel_L_DiMartino')
first_level_3D([rawdir,'FirstLevel_L_DiMartino/'],'scans',TR,[rawdir,extract_in],N,[rawdir,'FirstLevel_L_DiMartino/spm_regs_L.mat'],[t1dir,'wt1_brain.nii']);
% run contrasts
first_level_contrasts_spheres(1,[rawdir,'FirstLevel_L_DiMartino/SPM.mat'])
% Right hemi
R = roi_ts(:,7:12);
save spm_regs_R R
% estimate first level
mkdir('FirstLevel_R_DiMartino');
movefile('spm_regs_R.mat','FirstLevel_R_DiMartino')
first_level_3D([rawdir,'FirstLevel_R_DiMartino/'],'scans',TR,[rawdir,extract_in],N,[rawdir,'FirstLevel_R_DiMartino/spm_regs_R.mat'],[t1dir,'wt1_brain.nii']);
% run contrasts
first_level_contrasts_spheres(1,[rawdir,'FirstLevel_R_DiMartino/SPM.mat'])
system('rm -f srest_prepro_*.nii')
fprintf('First level analysis done \n');
% ------------------------------------------------------------------------------
% rezip
% ------------------------------------------------------------------------------
% % Zip up rfMRI outputs
% % Change in subject's directory (i.e., one above rfMRI directory)
% cd(rawdir)
% cd ../
% % Make output directory for first level (we want to retain an unzipped copy of this)
% mkdir('rfMRI_FirstLevel_DiMartino')
% % Copy First level subdirs
% copyfile([rawdir,'FirstLevel_L_DiMartino'],'rfMRI_FirstLevel_DiMartino/FirstLevel_L')
% copyfile([rawdir,'FirstLevel_R_DiMartino'],'rfMRI_FirstLevel_DiMartino/FirstLevel_R')
% Make output directory for preprocessed nii file (we want to retain an unzipped copy of this)
% mkdir('rfMRI_preprocessed')
% % Copy preprocessed nifti file
% copyfile(rawdir,'srest_prepro.nii')
% % Zip rfMRI and t1 dir
% zip('rfMRI_Archive.zip','rfMRI')
% zip('t1_Archive.zip','t1')
% % Delete rfMRI and t1 dir
% rmdir('rfMRI','s')
% rmdir('t1','s')
end