Skip to content

Commit 3d42d03

Browse files
committed
add tests and update CI and rename demos
1 parent b6be0ec commit 3d42d03

File tree

7 files changed

+152
-14
lines changed

7 files changed

+152
-14
lines changed

.github/workflows/miss_hit.yml renamed to .github/workflows/miss_hit_quality.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: miss_hit
1+
name: miss_hit_quality
22

33
on:
44
push:
@@ -28,10 +28,8 @@ jobs:
2828
run: |
2929
python -m pip install --upgrade pip setuptools
3030
pip3 install -r requirements.txt
31-
32-
- name: MISS_HIT Code style
33-
run: |
34-
mh_style --process-slx
31+
cd tests
32+
make data
3533
3634
- name: MISS_HIT Metrics
3735
run: |
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: miss_hit_style
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches: '*'
9+
10+
jobs:
11+
build:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
17+
- uses: actions/checkout@v2
18+
with:
19+
submodules: true
20+
fetch-depth: 1
21+
22+
- name: Set up Python 3.6
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: 3.6
26+
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip setuptools
30+
pip3 install -r requirements.txt
31+
cd tests
32+
make data
33+
34+
- name: MISS_HIT Code style
35+
run: |
36+
mh_style
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
% (C) Copyright 2021 CPP ROI developers
2+
3+
% small demo to show how to create and rename ROIs that come from neurosynth
4+
% and how to only keep the data from one hemisphere of an image.
5+
6+
run ../../initCppRoi;
7+
8+
gunzip(fullfile('inputs', '*.gz'));
9+
zMap = fullfile(pwd, 'inputs', 'visual motion_association-test_z_FDR_0.01.nii');
10+
11+
zMap = renameNeuroSynth(zMap);
12+
roiImage = thresholdToMask(zMap, 5);
13+
14+
% keep only one hemisphere and appends a 'hs--[hemisphere label]'
15+
leftRoiImage = keepHemisphere(roiImage, 'L');
16+
rightRoiImage = keepHemisphere(roiImage, 'R');
17+
18+
% change the label entity and remove the hs one
19+
leftRoiImage = renameFile(leftRoiImage, ...
20+
struct('entities', struct( ...
21+
'label', 'ns left motion', ...
22+
'hemi', '')));
23+
rightRoiImage = renameFile(rightRoiImage, ...
24+
struct('entities', struct( ...
25+
'label', 'ns right motion', ...
26+
'hemi', '')));

src/atlas/extractRoiByLabel.m

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1-
% (C) Copyright 2021 CPP ROI developers
2-
31
function outputImage = extractRoiByLabel(sourceImage, labelStruct)
2+
%
3+
% Given a discrete segmentation source image fullpath and a look up table
4+
% label structure this creates a mask for that ROI and returns the fullpath to its BIDS name.
5+
% This will also create a JSON side car file for that image.
6+
%
7+
% USAGE::
8+
%
9+
% outputImage = extractRoiByLabel(sourceImage, labelStruct)
10+
%
11+
% :param sourceImage: discrete segmentation source image fullpath
12+
% :type sourceImage: string
13+
% :param labelStruct: 1x1 structure with fields ``ROI`` for the ROI name
14+
% and ``label`` for the corresponding label
15+
% :type labelStruct: structure
16+
%
17+
% (C) Copyright 2021 CPP ROI developers
418

519
hdr = spm_vol(sourceImage);
620
vol = spm_read_vols(hdr);
@@ -9,14 +23,13 @@
923
outputVol(vol == labelStruct.label) = true;
1024

1125
p = bids.internal.parse_filename(sourceImage);
12-
p.label = labelStruct.ROI;
26+
p.entities.label = labelStruct.ROI;
1327
p.suffix = 'mask';
1428
p.use_schema = false;
1529

1630
newName = bids.create_filename(p);
1731
hdr.fname = spm_file(hdr.fname, 'filename', newName);
1832

19-
% Cluster labels as their size.
2033
spm_write_vol(hdr, outputVol);
2134
outputImage = hdr.fname;
2235

src/roi/keepHemisphere.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
%
1010
% :param image:
1111
% :type image: string
12-
% :param hemisphere: ``'lh'`` or ``'rh'``
12+
% :param hemisphere: ``'L'`` or ``'R'``
1313
% :type hemisphere: string
1414
%
1515
%
@@ -23,19 +23,23 @@
2323
xDim = hdr.dim(1);
2424
xMid = round(xDim / 2);
2525

26-
switch lower(hemisphere)
26+
switch hemisphere
2727

28-
case 'lh'
28+
case 'L'
2929
discard = 1:xMid;
3030

31-
case 'rh'
31+
case 'R'
3232
discard = xMid:xDim;
33+
34+
otherwise
35+
error('hemisphere must be L or R.');
36+
3337
end
3438

3539
vol(discard, :, :) = NaN;
3640

3741
p = bids.internal.parse_filename(inputImage);
38-
p.entities.hs = lower(hemisphere);
42+
p.entities.hemi = hemisphere;
3943
p.use_schema = false;
4044
newName = bids.create_filename(p);
4145

tests/test_extractRoiByLabel.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
% (C) Copyright 2020 CPP ROI developers
2+
3+
function test_suite = test_extractRoiByLabel() %#ok<*STOUT>
4+
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
5+
test_functions = localfunctions(); %#ok<*NASGU>
6+
catch % no problem; early Matlab versions can use initTestSuite fine
7+
end
8+
initTestSuite;
9+
end
10+
11+
function test_lut_wang()
12+
13+
[atlasFile, lut] = getAtlasAndLut('neuromorphometrics');
14+
15+
labelStruct = struct('ROI', lut.ROI{1}, ...
16+
'label', lut.label(1));
17+
18+
outputImage = extractRoiByLabel(atlasFile, labelStruct);
19+
20+
assertEqual(exist(outputImage, 'file'), 2);
21+
22+
vol = spm_read_vols(spm_vol(outputImage));
23+
assertEqual(sum(vol(:) == 1), 291); % check the ROI has the right number of voxel
24+
25+
delete(fullfile(returnAtlasDir(), '*.nii'));
26+
delete(fullfile(returnAtlasDir(), '*.json'));
27+
28+
end

tests/test_keepHemisphere.m

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
% (C) Copyright 2020 CPP ROI developers
2+
3+
function test_suite = test_keepHemisphere %#ok<*STOUT>
4+
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
5+
test_functions = localfunctions(); %#ok<*NASGU>
6+
catch % no problem; early Matlab versions can use initTestSuite fine
7+
end
8+
initTestSuite;
9+
end
10+
11+
function test_renameFile()
12+
13+
inputDir = fullfile(fileparts(mfilename('fullpath')), '..', 'demos', 'roi');
14+
15+
gunzip(fullfile(inputDir, 'inputs', '*.gz'));
16+
zMap = fullfile(inputDir, 'inputs', 'visual motion_association-test_z_FDR_0.01.nii');
17+
18+
zMap = renameNeuroSynth(zMap);
19+
20+
% keep only one hemisphere and appends a 'hemi-[hemisphere label]'
21+
leftRoiImage = keepHemisphere(zMap, 'L');
22+
rightRoiImage = keepHemisphere(zMap, 'R');
23+
24+
assertEqual(exist(fullfile(inputDir, 'inputs', ...
25+
'space-MNI_label-neurosynthVisualMotion_hemi-L_probseg.nii'), 'file'), 2);
26+
assertEqual(exist(fullfile(inputDir, 'inputs', ...
27+
'space-MNI_label-neurosynthVisualMotion_hemi-R_probseg.nii'), 'file'), 2);
28+
29+
% TODO check the data content
30+
31+
delete(fullfile(inputDir, 'inputs', '*.nii'));
32+
33+
end

0 commit comments

Comments
 (0)