Skip to content

Commit ba39937

Browse files
authored
Merge pull request #31 from cpp-lln-lab/atlas
[REF & ENH] remove renameFile and deal with atlas entities
2 parents 7870fd6 + a1d719f commit ba39937

15 files changed

+39
-110
lines changed

demos/roi/label_and_extract_clusters.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
gunzip(fullfile('inputs', '*.gz'));
1212

13-
zMap = fullfile(pwd, 'inputs', 'visual_motion_association-test_z_FDR_0.01.nii');
13+
zMap = fullfile(pwd, 'inputs', 'visual motion_association-test_z_FDR_0.01.nii');
1414
zMap = renameNeuroSynth(zMap);
1515

1616
peakThreshold = 5;

demos/roi/neurosynth_left_right_rois.m

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
run ../../initCppRoi;
77

88
gunzip(fullfile('inputs', '*.gz'));
9-
zMap = fullfile(pwd, 'inputs', 'visual_motion_association-test_z_FDR_0.01.nii');
9+
zMap = fullfile(pwd, 'inputs', 'visual motion_association-test_z_FDR_0.01.nii');
1010

1111
zMap = renameNeuroSynth(zMap);
1212
roiImage = thresholdToMask(zMap, 5);
@@ -16,11 +16,13 @@
1616
rightRoiImage = keepHemisphere(roiImage, 'R');
1717

1818
% 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', '')));
19+
specification = struct('entities', struct('label', 'ns left motion', ...
20+
'hemi', ''));
21+
bf = bids.File(leftRoiImage);
22+
bf = bf.rename('spec', specification, 'dry_run', false, 'verbose', true);
23+
leftRoiImage = fullfile(bf.path, bf.filename);
24+
25+
specification.entities.label = 'ns right motion';
26+
bf = bids.File(rightRoiImage);
27+
bf = bf.rename('spec', specification, 'dry_run', false, 'verbose', true);
28+
rightRoiImage = fullfile(bf.path, bf.filename);

demos/roi/roi_script.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
% You can use the resliceRoiImages for that.
3030

3131
%%
32-
zMap = fullfile(pwd, 'inputs', 'visual_motion_association-test_z_FDR_0.01.nii');
32+
zMap = fullfile(pwd, 'inputs', 'visual motion_association-test_z_FDR_0.01.nii');
3333
dataImage = fullfile(pwd, 'inputs', 'TStatistic.nii');
3434

3535
opt.unzip.do = true;

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
author = "the CPP ROI dev team"
2424

2525
# The full version, including alpha/beta/rc tags
26-
release = "v0.2.0"
26+
release = "v0.2.0dev"
2727

2828

2929
# -- General configuration ---------------------------------------------------

docs/source/function_description.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,3 @@ Atlas
1414
.. automodule:: src.atlas
1515

1616
.. autofunction:: returnAtlasDir
17-
18-
Utilities
19-
=========
20-
21-
.. automodule:: src.utils
22-
23-
.. autofunction:: renameFile

run_tests.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
testFolder = fullfile(fileparts(mfilename('fullpath')), 'tests');
1010

1111
addpath(fullfile(testFolder, 'utils'));
12+
addpath(fullfile(fileparts(mfilename('fullpath')), 'atlas'));
1213

1314
folderToCover = fullfile(testFolder, '..', 'src');
1415

src/atlas/extractRoiFromAtlas.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
% rename file
6262
entities = struct('hemi', hemisphere, ...
6363
'space', 'MNI', ...
64-
'label', roiName, ...
65-
'desc', atlasName);
64+
'atlas', atlasName, ...
65+
'label', roiName);
6666
nameStructure = struct('entities', entities, ...
6767
'suffix', 'mask', ...
6868
'ext', '.nii');

src/roi/keepHemisphere.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@
3838

3939
vol(discard, :, :) = NaN;
4040

41-
p = bids.internal.parse_filename(inputImage);
42-
p.entities.hemi = hemisphere;
43-
bidsFile = bids.File(p);
41+
bf = bids.File(inputImage);
42+
bf.entity_order = cat(1, 'hemi', fieldnames(bf.entities));
43+
bf.entities.hemi = hemisphere;
44+
bf = bf.reorder_entities;
4445

45-
hdr.fname = spm_file(inputImage, 'filename', bidsFile.filename);
46+
hdr.fname = spm_file(inputImage, 'filename', bf.filename);
4647

4748
spm_write_vol(hdr, vol);
4849

src/roi/renameNeuroSynth.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929

3030
basename = spm_file(inputImage, 'basename');
3131
parts = strsplit(basename, '_');
32-
p.entities.label = bids.internal.camel_case(['neurosynth ' parts{1}]);
32+
p.entities.atlas = 'neurosynth';
33+
p.entities.label = bids.internal.camel_case(parts{1});
3334

3435
bidsFile = bids.File(p);
3536

src/utils/renameFile.m

Lines changed: 0 additions & 48 deletions
This file was deleted.

tests/test_extractRoiFromAtlas.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function test_extractRoiFromAtlas_wang()
1212

1313
roiImage = extractRoiFromAtlas(pwd, 'wang', 'V1v', 'L');
1414

15-
assertEqual(exist(fullfile(pwd, 'hemi-L_space-MNI_label-V1v_desc-wang_mask.nii'), ...
15+
assertEqual(exist(fullfile(pwd, 'hemi-L_space-MNI_atlas-wang_label-V1v_mask.nii'), ...
1616
'file'), ...
1717
2);
1818

@@ -29,7 +29,7 @@ function test_extractRoiFromAtlas_neuromorphometrics()
2929
roiImage = extractRoiFromAtlas(pwd, 'neuromorphometrics', 'Amygdala', 'L');
3030

3131
assertEqual(exist(fullfile(pwd, ...
32-
'hemi-L_space-MNI_label-Amygdala_desc-neuromorphometrics_mask.nii'), ...
32+
'hemi-L_space-MNI_atlas-neuromorphometrics_label-Amygdala_mask.nii'), ...
3333
'file'), ...
3434
2);
3535

tests/test_keepHemisphere.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
initTestSuite;
99
end
1010

11-
function test_renameFile()
11+
function test_keepHemisphere_basic()
1212

1313
inputDir = fullfile(fileparts(mfilename('fullpath')), '..', 'demos', 'roi');
1414

@@ -17,14 +17,20 @@ function test_renameFile()
1717

1818
zMap = renameNeuroSynth(zMap);
1919

20-
% keep only one hemisphere and appends a 'hemi-[hemisphere label]'
20+
% keep only one hemisphere and add a 'hemi-[hemisphere label]' entity
2121
leftRoiImage = keepHemisphere(zMap, 'L');
2222
rightRoiImage = keepHemisphere(zMap, 'R');
2323

24+
basename = 'space-MNI_atlas-neurosynth_label-visualMotion_probseg.nii';
25+
2426
assertEqual(exist(fullfile(inputDir, 'inputs', ...
25-
'space-MNI_label-neurosynthVisualMotion_hemi-L_probseg.nii'), 'file'), 2);
27+
['hemi-L_' basename]), ...
28+
'file'), ...
29+
2);
2630
assertEqual(exist(fullfile(inputDir, 'inputs', ...
27-
'space-MNI_label-neurosynthVisualMotion_hemi-R_probseg.nii'), 'file'), 2);
31+
['hemi-R_' basename]), ...
32+
'file'), ...
33+
2);
2834

2935
% TODO check the data content
3036

tests/test_unit_renameFile.m

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/test_unit_renameNeuroSynth.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function test_renameNeuroSynth()
1515

1616
outputImage = renameNeuroSynth(inputImage);
1717

18-
expected = fullfile(pwd, 'space-MNI_label-neurosynthMotion_probseg.nii.gz');
18+
expected = fullfile(pwd, 'space-MNI_atlas-neurosynth_label-motion_probseg.nii.gz');
1919
assertEqual(exist(outputImage, 'file'), 2);
2020

2121
assertEqual(outputImage, expected);
@@ -31,7 +31,7 @@ function test_renameNeuroSynth_unzipped()
3131

3232
outputImage = renameNeuroSynth(inputImage);
3333

34-
expected = fullfile(pwd, 'space-MNI_label-neurosynthMotion_probseg.nii');
34+
expected = fullfile(pwd, 'space-MNI_atlas-neurosynth_label-motion_probseg.nii');
3535
assertEqual(exist(outputImage, 'file'), 2);
3636

3737
assertEqual(outputImage, expected);

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.2.0
1+
v0.2.0dev

0 commit comments

Comments
 (0)