Skip to content

[REF & ENH] remove renameFile and deal with atlas entities #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demos/roi/label_and_extract_clusters.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

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

peakThreshold = 5;
Expand Down
20 changes: 11 additions & 9 deletions demos/roi/neurosynth_left_right_rois.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
run ../../initCppRoi;

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

zMap = renameNeuroSynth(zMap);
roiImage = thresholdToMask(zMap, 5);
Expand All @@ -16,11 +16,13 @@
rightRoiImage = keepHemisphere(roiImage, 'R');

% change the label entity and remove the hs one
leftRoiImage = renameFile(leftRoiImage, ...
struct('entities', struct( ...
'label', 'ns left motion', ...
'hemi', '')));
rightRoiImage = renameFile(rightRoiImage, ...
struct('entities', struct( ...
'label', 'ns right motion', ...
'hemi', '')));
specification = struct('entities', struct('label', 'ns left motion', ...
'hemi', ''));
bf = bids.File(leftRoiImage);
bf = bf.rename('spec', specification, 'dry_run', false, 'verbose', true);
leftRoiImage = fullfile(bf.path, bf.filename);

specification.entities.label = 'ns right motion';
bf = bids.File(rightRoiImage);
bf = bf.rename('spec', specification, 'dry_run', false, 'verbose', true);
rightRoiImage = fullfile(bf.path, bf.filename);
2 changes: 1 addition & 1 deletion demos/roi/roi_script.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
% You can use the resliceRoiImages for that.

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

opt.unzip.do = true;
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
author = "the CPP ROI dev team"

# The full version, including alpha/beta/rc tags
release = "v0.2.0"
release = "v0.2.0dev"


# -- General configuration ---------------------------------------------------
Expand Down
7 changes: 0 additions & 7 deletions docs/source/function_description.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,3 @@ Atlas
.. automodule:: src.atlas

.. autofunction:: returnAtlasDir

Utilities
=========

.. automodule:: src.utils

.. autofunction:: renameFile
1 change: 1 addition & 0 deletions run_tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
testFolder = fullfile(fileparts(mfilename('fullpath')), 'tests');

addpath(fullfile(testFolder, 'utils'));
addpath(fullfile(fileparts(mfilename('fullpath')), 'atlas'));

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

Expand Down
4 changes: 2 additions & 2 deletions src/atlas/extractRoiFromAtlas.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
% rename file
entities = struct('hemi', hemisphere, ...
'space', 'MNI', ...
'label', roiName, ...
'desc', atlasName);
'atlas', atlasName, ...
'label', roiName);
nameStructure = struct('entities', entities, ...
'suffix', 'mask', ...
'ext', '.nii');
Expand Down
9 changes: 5 additions & 4 deletions src/roi/keepHemisphere.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@

vol(discard, :, :) = NaN;

p = bids.internal.parse_filename(inputImage);
p.entities.hemi = hemisphere;
bidsFile = bids.File(p);
bf = bids.File(inputImage);
bf.entity_order = cat(1, 'hemi', fieldnames(bf.entities));
bf.entities.hemi = hemisphere;
bf = bf.reorder_entities;

hdr.fname = spm_file(inputImage, 'filename', bidsFile.filename);
hdr.fname = spm_file(inputImage, 'filename', bf.filename);

spm_write_vol(hdr, vol);

Expand Down
3 changes: 2 additions & 1 deletion src/roi/renameNeuroSynth.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@

basename = spm_file(inputImage, 'basename');
parts = strsplit(basename, '_');
p.entities.label = bids.internal.camel_case(['neurosynth ' parts{1}]);
p.entities.atlas = 'neurosynth';
p.entities.label = bids.internal.camel_case(parts{1});

bidsFile = bids.File(p);

Expand Down
48 changes: 0 additions & 48 deletions src/utils/renameFile.m

This file was deleted.

4 changes: 2 additions & 2 deletions tests/test_extractRoiFromAtlas.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function test_extractRoiFromAtlas_wang()

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

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

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

assertEqual(exist(fullfile(pwd, ...
'hemi-L_space-MNI_label-Amygdala_desc-neuromorphometrics_mask.nii'), ...
'hemi-L_space-MNI_atlas-neuromorphometrics_label-Amygdala_mask.nii'), ...
'file'), ...
2);

Expand Down
14 changes: 10 additions & 4 deletions tests/test_keepHemisphere.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
initTestSuite;
end

function test_renameFile()
function test_keepHemisphere_basic()

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

Expand All @@ -17,14 +17,20 @@ function test_renameFile()

zMap = renameNeuroSynth(zMap);

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

basename = 'space-MNI_atlas-neurosynth_label-visualMotion_probseg.nii';

assertEqual(exist(fullfile(inputDir, 'inputs', ...
'space-MNI_label-neurosynthVisualMotion_hemi-L_probseg.nii'), 'file'), 2);
['hemi-L_' basename]), ...
'file'), ...
2);
assertEqual(exist(fullfile(inputDir, 'inputs', ...
'space-MNI_label-neurosynthVisualMotion_hemi-R_probseg.nii'), 'file'), 2);
['hemi-R_' basename]), ...
'file'), ...
2);

% TODO check the data content

Expand Down
27 changes: 0 additions & 27 deletions tests/test_unit_renameFile.m

This file was deleted.

4 changes: 2 additions & 2 deletions tests/test_unit_renameNeuroSynth.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function test_renameNeuroSynth()

outputImage = renameNeuroSynth(inputImage);

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

assertEqual(outputImage, expected);
Expand All @@ -31,7 +31,7 @@ function test_renameNeuroSynth_unzipped()

outputImage = renameNeuroSynth(inputImage);

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

assertEqual(outputImage, expected);
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.2.0
v0.2.0dev