Skip to content

Commit 92b11d4

Browse files
committed
clean up
1 parent bfbf490 commit 92b11d4

File tree

10 files changed

+191
-48
lines changed

10 files changed

+191
-48
lines changed

README.md

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
<!-- lint disable -->
2-
3-
**Documentation**
4-
5-
**Code quality and style**
6-
7-
**Unit tests and coverage**
8-
9-
**How to cite**
10-
11-
**Contributors**
12-
131
# CPP ROI
142

15-
## :warning: :warning: :warning:
3+
---
4+
5+
## :warning:
166

17-
**This code is fairly unstable (:boom:) and might still change a lot.**
7+
**This code is fairly unstable and might still change.**
188

19-
Also this code currently has 0% test coverage...
9+
So make sure you "pin" which version or commit you are using for a given
10+
project, if you don't want your code to break in the future.
2011

2112
---
2213

@@ -57,8 +48,7 @@ as a submodule, and intitialized when running `initCppSpm`.
5748

5849
### Dependencies
5950

60-
=======
61-
TODO
51+
======= TODO
6252

6353
| Dependencies | Used version |
6454
| ---------------------------------------------------------- | ------------ |
@@ -98,8 +88,4 @@ TODO
9888
Also includes:
9989

10090
- Yeo's 7 networks "atlas"
101-
- add REF and URL
102-
103-
## Contributing
104-
105-
## Contributors
91+
<!-- add REF and URL -->

demos/roi/step_7_get_ROI_PSC.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
% This script will run through the ROIs made for each subject fo a ROI
22
% based anaylisis using MarsBar to get a time course of the activations and
33
% a percent signal change for each ROI and subject
4+
%
5+
% (C) Copyright 2020 CPP ROI developers
46

57
clc;
68

demos/roi/step_8_plot_PSC.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
% This script will run through the ROIs made for each subject fo a ROI
22
% based anaylisis using MarsBar to get a time course of the activations and
33
% a percent signal change for each ROI and subject
4+
%
5+
% (C) Copyright 2020 CPP ROI developers
46

57
% TODO
68
% - refactor

initCppRoi.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ function initCppRoi()
1212

1313
pathSep = ':';
1414
if ~isunix
15-
pathSep = ';';
15+
pathSep = ';';
1616
end
1717
% we add all the subfunctions that are in the sub directories
1818
CPP_ROI_PATHS = genpath(fullfile(thisDirectory, 'src'));
1919
CPP_ROI_PATHS = cat(2, CPP_ROI_PATHS, pathSep, ...
20-
fullfile(thisDirectory, 'lib', 'marsbar-0.44'));
20+
fullfile(thisDirectory, 'lib', 'marsbar-0.44'));
2121
addpath(CPP_ROI_PATHS, '-begin');
22-
22+
2323
marsbar('on');
2424
try
2525
marsbar('splash');
2626
catch
2727
end
28-
28+
2929
CPP_ROI_INITIALIZED = true();
3030

3131
else

src/atlas/returnAtlasDir.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
%
1111
% (C) Copyright 2021 CPP ROI developers
1212

13-
atlasDir = fullfile(fileparts(mfilename('fullpath')), '..', '..', 'atlas');
13+
atlasDir = fullfile(rootDir(), 'atlas');
1414

1515
if nargin > 0
1616

src/roi/get_ROI_Coordinates.m

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
function mni = get_ROI_Coordinates
2+
% This function gets the individual subject coordniates of the highest peak
3+
% within a specified Region of interest (usually coming from the group level univariate analysis)
4+
5+
% Critical t-value for each experimental condition or mask file
6+
CriticalTs = 1; % Critical t-value for visual condition in L-V5 and R-V5 and bilateral PT
7+
8+
%% load the data structure
9+
WD = pwd;
10+
11+
%% group of subjects to analyze
12+
opt.groups = {'EB', 'SCa', 'SCv'}; % {'EB','SCa','SCv'};
13+
% suject to run in each group
14+
opt.subjects = {[1:13], [1:10], [1:6]}; % {[1:13],[1:10],[1:6]};
15+
16+
%%
17+
smoothing = '6';
18+
19+
%% Regions that will be used to extract the highest t-value within that mask
20+
maskFn = { 'face_lFFA.nii'
21+
'face_rFFA.nii'
22+
};
23+
24+
CriticalTs = ones(1, length(maskFn)) * CriticalTs;
25+
26+
%% Location of the data
27+
data_path = '/Volumes/SanDisk/Oli_Data/Categs_BIDS/derivatives';
28+
29+
% create an mni cell with dimensions (1x number of masks)
30+
mni = cell(1, length(maskFn));
31+
SubNames = {};
32+
33+
% for each mask
34+
for iMask = 1:length(maskFn)
35+
36+
fprintf('Running Mask %.0f \n\n', iMask);
37+
CriticalT = CriticalTs(iMask); % get the critical t
38+
39+
subCounter = 0;
40+
for iGroup = 1:length(opt.groups)
41+
for iSub = 1:length(opt.subjects{iGroup})
42+
43+
fprintf('Running Subject %.0f \n', iSub);
44+
45+
SubName = ['sub-', opt.groups{iGroup}, ...
46+
sprintf('%02d', opt.subjects{iGroup}(iSub))];
47+
48+
fprintf('%s \n', SubName);
49+
subCounter = subCounter + 1;
50+
SubNames{subCounter, iMask} = SubName(5:end);
51+
52+
%% the first 4 masks are for the FACE condition, the other 4
53+
% are from the SCENE condition
54+
if iMask <= 2
55+
result_file = [data_path, '/', SubName, '/stats/ffx_visMotion/ffx_', smoothing, '/spmT_0013.nii']; % HUMAN > BIG_ENV
56+
else
57+
result_file = [data_path, '/', SubName, '/stats/ffx_audMotion/ffx_', smoothing, '/spmT_0014.nii']; % BIG_ENV > HUMAN
58+
end
59+
60+
%%
61+
mask_path = fullfile(WD, 'Kanwisher_ROIs', maskFn{iMask});
62+
63+
r = load_nii(result_file);
64+
m = load_nii(mask_path);
65+
66+
r.img(~m.img) = nan;
67+
68+
maxVal = max(r.img(:));
69+
maxVals(subCounter, iMask) = maxVal;
70+
71+
if maxVal > CriticalT %|| maxVal < CriticalT
72+
73+
% Get the location of the higest t-value in slice space
74+
voxel_idx = find(r.img == maxVal);
75+
76+
disp(maxVal);
77+
[x, y, z] = ind2sub(size(r.img), voxel_idx);
78+
79+
% convert space from slice number to mni
80+
mni{1, iMask}(subCounter, :) = cor2mni([x y z], mask_path);
81+
% mni{1,iMask}(iSub,1) = mni{1,iMask}(iSub,1)* -1; % If masks created from AFNI or FSL,
82+
% the x coordinate could be flipped (multiplied x -1). If this is the case, multiply x with -1.
83+
84+
mni{1, iMask}(subCounter, :);
85+
86+
else
87+
mni{1, iMask}(subCounter, 1:3) = nan;
88+
end
89+
90+
end
91+
end
92+
end
93+
94+
save('mni_coordinates.mat', 'mni', 'maskFn', 'opt', 'maxVals', 'SubNames');
95+
end
96+
97+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98+
%%% cor2mni
99+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100+
function mni = cor2mni(cor, nifti_image)
101+
% function mni = cor2mni(cor, T)
102+
% convert matrix coordinate to mni coordinate
103+
%
104+
% cor: an Nx3 matrix
105+
% T: (optional) rotation matrix
106+
% mni is the returned coordinate in mni space
107+
%
108+
% caution: if T is not given, the default T is
109+
% T = ...
110+
% [-4 0 0 84;...
111+
% 0 4 0 -116;...
112+
% 0 0 4 -56;...
113+
% 0 0 0 1];
114+
%
115+
% xu cui
116+
% 2004-8-18
117+
% last revised: 2005-04-30
118+
119+
% if nargin == 1
120+
% T = ...
121+
% [-4 0 0 84;...
122+
% 0 4 0 -116;...
123+
% 0 0 4 -56;...
124+
% 0 0 0 1];
125+
% end
126+
127+
V = spm_vol(nifti_image);
128+
T = V.mat;
129+
130+
cor = round(cor);
131+
mni = T * [cor(:, 1) cor(:, 2) cor(:, 3) ones(size(cor, 1), 1)]';
132+
mni = mni';
133+
mni(:, 4) = [];
134+
end

run_tests.m renamed to tests/run_tests.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
% (C) Copyright 2019 CPP ROI developers
22

3+
% Does not work due to some relative path of the data when testing
4+
35
warning('OFF');
46

57
spm('defaults', 'fMRI');
68

7-
folderToCover = fullfile(pwd, 'src');
8-
testFolder = fullfile(pwd, 'tests');
9+
testFolder = fullfile(fileparts(mfilename('fullpath')));
10+
11+
folderToCover = fullfile(testFolder, '..', 'src');
912

1013
success = moxunit_runtests( ...
1114
testFolder, ...

tests/test_unit_returnAtlasDir.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
initTestSuite;
99
end
1010

11+
function test_returnAtlasDir_no_input()
12+
13+
atlasDir = returnAtlasDir();
14+
15+
assertEqual(atlasDir, baseAtlasDir());
16+
17+
end
18+
1119
function test_returnAtlasDir_default()
1220

1321
atlasDir = returnAtlasDir('neuromorphometric');
@@ -38,6 +46,6 @@ function test_returnAtlasDir_anatomy_toobox()
3846

3947
function baseDir = baseAtlasDir()
4048

41-
baseDir = spm_file(fullfile(fileparts(mfilename('fullpath')), '..', 'atlas'), 'cpath');
49+
baseDir = spm_file(fullfile(rootDir(), 'atlas'), 'cpath');
4250

4351
end

tests/test_unzipAtlas.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@
1010

1111
function test_unzipAtlas_default()
1212

13+
cleanUp();
14+
1315
unzipAtlas('wang');
1416

1517
assertEqual(exist( ...
16-
fullfile(returnAtlasDir('wang'), 'subj_vol_all', 'space-MNI_hemi-lh_dseg.nii'), 'file'), ...
18+
fullfile(returnAtlasDir('wang'), ...
19+
'subj_vol_all', ...
20+
'space-MNI_hemi-lh_dseg.nii'), ...
21+
'file'), ...
1722
2);
1823

1924
cleanUp();
@@ -27,6 +32,10 @@ function cleanUp()
2732
if isOctave()
2833
confirm_recursive_rmdir (true, 'local');
2934
end
30-
rmdir(returnAtlasDir('wang'), 's');
35+
36+
try
37+
rmdir(returnAtlasDir('wang'), 's');
38+
catch
39+
end
3140

3241
end

uninitCppRoi.m

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
% (C) Copyright 2021 CPP ROI developers
22

33
function uninitCppRoi()
4-
5-
global CPP_ROI_INITIALIZED
6-
global CPP_ROI_PATHS
7-
8-
if isempty(CPP_ROI_INITIALIZED) || ~CPP_ROI_INITIALIZED
9-
fprintf('\n\nCPP_ROI not initialized\n\n');
10-
return
11-
12-
else
13-
marsbar('off');
14-
rmpath(CPP_ROI_PATHS);
15-
CPP_ROI_INITIALIZED = false;
16-
17-
end
18-
19-
end
204

5+
global CPP_ROI_INITIALIZED
6+
global CPP_ROI_PATHS
7+
8+
if isempty(CPP_ROI_INITIALIZED) || ~CPP_ROI_INITIALIZED
9+
fprintf('\n\nCPP_ROI not initialized\n\n');
10+
return
11+
12+
else
13+
marsbar('off');
14+
rmpath(CPP_ROI_PATHS);
15+
CPP_ROI_INITIALIZED = false;
16+
17+
end
18+
19+
end

0 commit comments

Comments
 (0)