-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepro_extractTS_FSL.m
executable file
·69 lines (57 loc) · 2.99 KB
/
prepro_extractTS_FSL.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
function roiTS = prepro_extractTS_FSL(cfg)
% This function will extract resting state time series values from a parcellation image in MNI space.
% It will also weight the averaging by grey matter probability
%
% ------
% INPUTS
% ------
% cfg.subject - string containing subject ID = e.g., '1008.2.48.009'
%
% cfg.removeNoise - string defining noise strategy used for preprocessing (see prepro_noise.m)
%
% cfg.parcFile - location and name of MNI parcellation nifti file. e.g., /path/to/dir/parcellation.nii
%
% cfg.t1dir - location of grey matter probability mask
% cfg.normGM - name of grey matter prob mask
%
% Linden Parkes, Brain & Mental Health Laboratory, 2016
% ------------------------------------------------------------------------------
fprintf('\n\t\t ----- Times series extraction ----- \n\n');
fprintf(1, '\t\t Subject: %s \n', cfg.subject)
fprintf(1, '\t\t Noise correction: %s \n', cfg.removeNoise);
fprintf(1, '\t\t Input file: %s \n', cfg.ExtractIn);
fprintf(1, '\t\t Parcellation file: %s \n',cfg.parcFile);
fprintf(1, '\t\t Parcellation name: %s \n',cfg.parcName);
fprintf(1, '\t\t GM weighting: %s \n', cfg.weightGM);
fprintf('\n\t\t ----------------------------------- \n\n');
% ------------------------------------------------------------------------------
% ROIs
% ------------------------------------------------------------------------------
[parc_hdr,parc] = read(cfg.parcFile);
numROIs = numel(unique(parc))-1;
% ------------------------------------------------------------------------------
% Script
% ------------------------------------------------------------------------------
cd(cfg.preprocesseddir)
switch cfg.weightGM
case 'yes'
% multiply epi by gm prob
system([cfg.fsldir,'fslmaths ',cfg.ExtractIn,' -mul ',cfg.preprocesseddir,cfg.normGM,' epi_w']);
% take the average of the weighted epi data for each parcel
system([cfg.fsldir,'fslmeants -i epi_w.nii* --label=',cfg.parcFile,' -o epi_parc_mean.txt']);
% take the average of the gm probabilities for each parcel
system([cfg.fsldir,'fslmeants -i ',cfg.preprocesseddir,cfg.normGM,' --label=',cfg.parcFile,' -o gm_parc_mean.txt']);
x = dlmread('epi_parc_mean.txt');
y = dlmread('gm_parc_mean.txt');
for i = 1:numROIs
roiTS(:,i) = x(:,i)/y(i);
end
delete('epi_w.nii*','epi_parc_mean.txt','gm_parc_mean.txt')
case 'no'
% take the average of the weighted epi data for each parcel
system([cfg.fsldir,'fslmeants -i ',cfg.ExtractIn,' --label=',cfg.parcFile,' -o roiTS_',cfg.parcName,'.txt']);
roiTS = dlmread(['roiTS_',cfg.parcName,'.txt']);
delete('roiTS_*.txt')
end
fprintf('\n\t\t ----- ROI time series extracted ----- \n\n');
end