diff --git a/demos/roi/label_and_extract_clusters.m b/demos/roi/label_and_extract_clusters.m index 245ed28..18d74cd 100644 --- a/demos/roi/label_and_extract_clusters.m +++ b/demos/roi/label_and_extract_clusters.m @@ -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; diff --git a/demos/roi/neurosynth_left_right_rois.m b/demos/roi/neurosynth_left_right_rois.m index e3b328e..db1c4c2 100644 --- a/demos/roi/neurosynth_left_right_rois.m +++ b/demos/roi/neurosynth_left_right_rois.m @@ -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); @@ -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); diff --git a/demos/roi/roi_script.m b/demos/roi/roi_script.m index a31528e..6178739 100644 --- a/demos/roi/roi_script.m +++ b/demos/roi/roi_script.m @@ -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; diff --git a/docs/source/conf.py b/docs/source/conf.py index 9191e3f..a43815e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -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 --------------------------------------------------- diff --git a/docs/source/function_description.rst b/docs/source/function_description.rst index cd8b5dc..e6c93c1 100644 --- a/docs/source/function_description.rst +++ b/docs/source/function_description.rst @@ -14,10 +14,3 @@ Atlas .. automodule:: src.atlas .. autofunction:: returnAtlasDir - -Utilities -========= - -.. automodule:: src.utils - -.. autofunction:: renameFile diff --git a/run_tests.m b/run_tests.m index 4cdf841..428a795 100644 --- a/run_tests.m +++ b/run_tests.m @@ -9,6 +9,7 @@ testFolder = fullfile(fileparts(mfilename('fullpath')), 'tests'); addpath(fullfile(testFolder, 'utils')); +addpath(fullfile(fileparts(mfilename('fullpath')), 'atlas')); folderToCover = fullfile(testFolder, '..', 'src'); diff --git a/src/atlas/extractRoiFromAtlas.m b/src/atlas/extractRoiFromAtlas.m index 60746d8..81af5dd 100644 --- a/src/atlas/extractRoiFromAtlas.m +++ b/src/atlas/extractRoiFromAtlas.m @@ -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'); diff --git a/src/roi/keepHemisphere.m b/src/roi/keepHemisphere.m index 5ef2006..67bf8cf 100644 --- a/src/roi/keepHemisphere.m +++ b/src/roi/keepHemisphere.m @@ -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); diff --git a/src/roi/renameNeuroSynth.m b/src/roi/renameNeuroSynth.m index 477be69..0d6ea6d 100644 --- a/src/roi/renameNeuroSynth.m +++ b/src/roi/renameNeuroSynth.m @@ -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); diff --git a/src/utils/renameFile.m b/src/utils/renameFile.m deleted file mode 100644 index ad476a0..0000000 --- a/src/utils/renameFile.m +++ /dev/null @@ -1,48 +0,0 @@ -function newName = renameFile(inputFile, specification) - % - % Renames a BIDS valid file into another BIDS valid file given some - % specificationification. - % - % USAGE:: - % - % newName = renameFile(inputFile, specificationification) - % - % :param inputFile: better if fullfile path - % :type inputFile: string - % :param specificationification: structure specificationifying the details of the new name - % The structure content must resemble that of the - % output of bids.internal.parse_filename - % :type specificationification: structure - % - % (C) Copyright 2021 CPP ROI developers - - bf = bids.File(inputFile, 'use_schema', false); - - if isfield(specification, 'prefix') - bf.suffix = specification.prefix; - end - if isfield(specification, 'suffix') - bf.suffix = specification.suffix; - end - if isfield(specification, 'ext') - bf.extension = specification.ext; - end - if isfield(specification, 'entities') - entities = fieldnames(specification.entities); - for i = 1:numel(entities) - bf = bf.set_entity(entities{i}, ... - bids.internal.camel_case(specification.entities.(entities{i}))); - end - end - if isfield(specification, 'entity_order') - bf = bf.reorder_entities(specification.entity_order); - end - - bf = bf.update; - - newName = bf.filename; - outputFile = spm_file(inputFile, 'filename', newName); - - movefile(inputFile, outputFile); - -end diff --git a/tests/test_extractRoiFromAtlas.m b/tests/test_extractRoiFromAtlas.m index 9442a8d..0c87b19 100644 --- a/tests/test_extractRoiFromAtlas.m +++ b/tests/test_extractRoiFromAtlas.m @@ -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); @@ -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); diff --git a/tests/test_keepHemisphere.m b/tests/test_keepHemisphere.m index 71109b2..a1f22df 100644 --- a/tests/test_keepHemisphere.m +++ b/tests/test_keepHemisphere.m @@ -8,7 +8,7 @@ initTestSuite; end -function test_renameFile() +function test_keepHemisphere_basic() inputDir = fullfile(fileparts(mfilename('fullpath')), '..', 'demos', 'roi'); @@ -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 diff --git a/tests/test_unit_renameFile.m b/tests/test_unit_renameFile.m deleted file mode 100644 index 82c0fbb..0000000 --- a/tests/test_unit_renameFile.m +++ /dev/null @@ -1,27 +0,0 @@ -% (C) Copyright 2020 CPP ROI developers - -function test_suite = test_unit_renameFile %#ok<*STOUT> - try % assignment of 'localfunctions' is necessary in Matlab >= 2016 - test_functions = localfunctions(); %#ok<*NASGU> - catch % no problem; early Matlab versions can use initTestSuite fine - end - initTestSuite; -end - -function test_renameFile() - - inputFile = 'sub-03_task-test_bold.nii'; - system(['touch ' inputFile]); - - specification = struct('entities', struct('desc', 'renamed')); - - newName = renameFile(inputFile, specification); - - expected = 'sub-03_task-test_desc-renamed_bold.nii'; - assertEqual(exist(newName, 'file'), 2); - - assertEqual(newName, expected); - - delete(fullfile(pwd, 'sub-03_task-test_desc-renamed_bold.nii')); - -end diff --git a/tests/test_unit_renameNeuroSynth.m b/tests/test_unit_renameNeuroSynth.m index 4ea101b..13483a2 100644 --- a/tests/test_unit_renameNeuroSynth.m +++ b/tests/test_unit_renameNeuroSynth.m @@ -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); @@ -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); diff --git a/version.txt b/version.txt index 1474d00..985d22b 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v0.2.0 +v0.2.0dev