diff --git a/.gitignore b/.gitignore index bb34216..b2a7e1e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,9 @@ # images in data folder Data/*.png -# Test data (if missing will be downloaded from NeuroVault) +# Test data test/data +test/moxunit_testsuite/MOxUnit #nii files *.nii @@ -30,4 +31,4 @@ test/data #ZIP files *.zip -_ignored* \ No newline at end of file +_ignored* diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..066247a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,40 @@ +language: python +# use container-based infrastructure +sudo: required +services: + - docker +cache: + pip: true + timeout: 1000 +python: + - "3.5" +bundler_args: --retry 9 +# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors +install: + - pip install --upgrade setuptools + - cd test/moxunit_testsuite +# Download MoxUnit for unit testing + - git clone https://github.com/MOxUnit/MOxUnit.git + - ls + - cd .. +# Download data + - cd data + - wget https://neurovault.org/collections/2210/download + - unzip download + - mv NIDM-Results\ 1.3.0\ examples\ -\ nidmfsl\ 1.2.01\ and\ SPM12\ r6906/* . + - rm -r NIDM-Results\ 1.3.0\ examples\ -\ nidmfsl\ 1.2.01\ and\ SPM12\ r6906/ + - cd ../.. + - ls +script: + # Run docker snapshot of dev octave (until 4.4 is released) + - did=$(sudo docker run -ti -d --rm -v `pwd`:/spmviewer cmaumet/octave-spm) + # Run tests in Octave + - sudo docker exec -t -i $did bash -c "sudo chmod 755 /spmviewer/test/moxunit_testsuite/runTest.sh; sudo /spmviewer/test/moxunit_testsuite/runTest.sh" +before_install: + # Update docker version + - sudo apt-get update + - sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce + - git config --global user.name "TravisCI" + - git config --global user.email "travis@dummy.com" + - sudo docker pull cmaumet/octave-spm + \ No newline at end of file diff --git a/README.md b/README.md index d7cfe48..53dec1b 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,7 @@ Read and display NIDM-Results packs in the SPM environment. -##### Usage - +#### Usage To view NIDM results using the NIDM results viewer run the following 1. Open `SPM fMRI` from the Matlab command line. @@ -33,11 +32,11 @@ To view NIDM results using the NIDM results viewer run the following :-------------------------:|:-------------------------: **Fig. 5.** Table data and images | **Fig. 6.** Summary statistics -##### Requirements +#### Requirements - [SPM12](http://www.fil.ion.ucl.ac.uk/spm/software/spm12/) -##### Installation +#### Installation 1. Add the filepath to SPM in Matlab; @@ -49,15 +48,44 @@ To view NIDM results using the NIDM results viewer run the following /toolbox/ ``` -##### Testing +#### Testing + +Currently, two versions of the test suite exist. One is based on the `matlab unittesting framework` and the other is based on the [`MOxUnit`](https://github.com/MOxUnit/MOxUnit) library. + +The `matlab unittesting framework` tests are recommended for testing the code locally in `Matlab` as they perform much faster and do not require any additional installation. The `MOxUnit` tests are recommended for testing the code locally in `Octave` and are also used for the Travis CI. Below is a description of how to run each test set. + +##### Matlab Unittesting Framework -1. Add the filepath to the 'tests' folder; +1. Add the filepath to the 'tests/matlabunit_testsuite' folder. In the Matlab commandline type; ``` -addpath(fullfile(fileparts(which('nidm_results_display')), 'test')) +addpath(fullfile(fileparts(which('nidm_results_display')), 'test', 'matlabunit_testsuite')) ``` -2. Run runTest; +2. Run runTest. In the Matlab commandline type; ``` runTest(); ``` + + ##### MOxUnit Framework + + 1. Download the MOxUnit testing framework to 'tests/moxunit_testsuite'. In the bash commandline type; + + ``` +cd /tests/moxunit_testsuite +git clone https://github.com/MOxUnit/MOxUnit.git + ``` + 2. Download the test data from [NeuroVault](https://neurovault.org/). In the bash commandline type; + + ``` +cd /tests/data +wget https://neurovault.org/collections/2210/download +unzip download +mv NIDM-Results\ 1.3.0\ examples\ -\ nidmfsl\ 1.2.01\ and\ SPM12\ r6906/* . +rm -r NIDM-Results\ 1.3.0\ examples\ -\ nidmfsl\ 1.2.01\ and\ SPM12\ r6906/ + ``` + 3. From 'tests/moxunit_testsuite' run the MOxUnit tests. In the Octave/Matlab terminal type; + + ``` + moxunit_runtests + ``` diff --git a/lib/changeNIDMtoTabDat.m b/lib/changeNIDMtoTabDat.m index e50b551..6cec20b 100644 --- a/lib/changeNIDMtoTabDat.m +++ b/lib/changeNIDMtoTabDat.m @@ -489,11 +489,11 @@ else %Calculate whichever statistic type is used. if strcmp(statType, 'T') - tableTemp{n, 9} = icdf('T',1-tableTemp{n, 11},errorDegrees); + tableTemp{n, 9} = spm_invTcdf(1-tableTemp{n, 11},errorDegrees); elseif strcmp(statType, 'X') - tableTemp{n, 9} = icdf('Chi',1-tableTemp{n, 11},errorDegrees); + tableTemp{n, 9} = spm_invXcdf(1-tableTemp{n, 11},errorDegrees); elseif strcmp(statType, 'F') - tableTemp{n, 9} = icdf('F',1-tableTemp{n, 11},effectDegrees, errorDegrees); + tableTemp{n, 9} = spm_invFcdf(1-tableTemp{n, 11},effectDegrees, errorDegrees); else tableTemp{n, 9} = ''; end diff --git a/lib/generateMIP.m b/lib/generateMIP.m index e5722fb..518e54e 100644 --- a/lib/generateMIP.m +++ b/lib/generateMIP.m @@ -46,5 +46,11 @@ function generateMIP(filepath, filename, DIM, units) %Write the image: mipPath = spm_file(fullfile(filepath, 'MIP.png')); imwrite(mip,gray(64),mipPath,'png'); + + %In some versions of octave/matlab the above removes + %the original .nii.gz file. + if ~exist(fullfile(filepath, filename), 'file') + gzip(strrep(fullfile(filepath, filename), '.gz', '')); + end end \ No newline at end of file diff --git a/test/runTest.m b/test/matlabunit_testsuite/runTest.m similarity index 75% rename from test/runTest.m rename to test/matlabunit_testsuite/runTest.m index b8b85c6..22a66b8 100644 --- a/test/runTest.m +++ b/test/matlabunit_testsuite/runTest.m @@ -8,13 +8,13 @@ function runTest() - %Clear previous classes (and keep debugging breakpoints) - clear classes; + %Clear previous classes. + clear all; %Setup steps for the test. import matlab.unittest.TestSuite; - addpath(fullfile(fileparts(mfilename('fullpath')),'..', 'lib')); - addpath(fullfile(fileparts(mfilename('fullpath')),'..')); + addpath(fullfile(fileparts(mfilename('fullpath')),'..', '..', 'lib')); + addpath(fullfile(fileparts(mfilename('fullpath')),'..', '..')); %Run all tests. tests = [matlab.unittest.TestSuite.fromFile(which('testDataSets')),... diff --git a/test/matlabunit_testsuite/testDataSets.m b/test/matlabunit_testsuite/testDataSets.m new file mode 100644 index 0000000..698fe17 --- /dev/null +++ b/test/matlabunit_testsuite/testDataSets.m @@ -0,0 +1,356 @@ +%========================================================================== +%Unit tests for testing whether datasets run in the viewer. To run the +%below run the runTest function. The html files generated can be found in +%the corresponding folders after the test has been run. +% +%Authors: Thomas Maullin, Camille Maumet. (Generated by the createTest +%function). +%========================================================================== + classdef testDataSets < matlab.unittest.TestCase + + methods + %Function for deleting any HTML generated previously by the viewer + function delete_html_file(testCase, data_path) + index = fullfile(data_path,'index.html'); + if exist(index, 'file') + delete(index); + else + for(i = 1:8) + index = fullfile(data_path,['index', num2str(i), '.html']); + if exist(index, 'file') + delete(index); + end + end + end + end + end + + methods(Test) + + %Test viewer displays ex_spm_HRF_informed_basis.nidm + function test_ex_spm_HRF_informed_basis(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_HRF_informed_basis.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/ex_spm_HRF_informed_basis.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','ex_spm_HRF_informed_basis.nidm'), 'All'); + end + + %Test viewer displays ex_spm_conjunction.nidm + function test_ex_spm_conjunction(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_conjunction.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/ex_spm_conjunction.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','ex_spm_conjunction.nidm'), 'All'); + end + + %Test viewer displays ex_spm_contrast_mask.nidm + function test_ex_spm_contrast_mask(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_contrast_mask.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/ex_spm_contrast_mask.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','ex_spm_contrast_mask.nidm'), 'All'); + end + + %Test viewer displays ex_spm_default.nidm + function test_ex_spm_default(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_default.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/ex_spm_default.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','ex_spm_default.nidm'), 'All'); + end + + %Test viewer displays ex_spm_full_example001.nidm + function test_ex_spm_full_example001(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_full_example001.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/ex_spm_full_example001.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','ex_spm_full_example001.nidm'), 'All'); + end + + %Test viewer displays ex_spm_group_ols.nidm + function test_ex_spm_group_ols(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_group_ols.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/ex_spm_group_ols.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','ex_spm_group_ols.nidm'), 'All'); + end + + %Test viewer displays ex_spm_group_wls.nidm + function test_ex_spm_group_wls(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_group_wls.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/ex_spm_group_wls.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','ex_spm_group_wls.nidm'), 'All'); + end + + %Test viewer displays ex_spm_partial_conjunction.nidm + function test_ex_spm_partial_conjunction(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_partial_conjunction.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/ex_spm_partial_conjunction.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','ex_spm_partial_conjunction.nidm'), 'All'); + end + + %Test viewer displays ex_spm_temporal_derivative.nidm + function test_ex_spm_temporal_derivative(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_temporal_derivative.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/ex_spm_temporal_derivative.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','ex_spm_temporal_derivative.nidm'), 'All'); + end + + %Test viewer displays ex_spm_thr_clustfwep05.nidm + function test_ex_spm_thr_clustfwep05(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_thr_clustfwep05.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/ex_spm_thr_clustfwep05.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','ex_spm_thr_clustfwep05.nidm'), 'All'); + end + + %Test viewer displays ex_spm_thr_clustunck10.nidm + function test_ex_spm_thr_clustunck10(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_thr_clustunck10.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/ex_spm_thr_clustunck10.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','ex_spm_thr_clustunck10.nidm'), 'All'); + end + + %Test viewer displays ex_spm_thr_voxelfdrp05.nidm + function test_ex_spm_thr_voxelfdrp05(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_thr_voxelfdrp05.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/ex_spm_thr_voxelfdrp05.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','ex_spm_thr_voxelfdrp05.nidm'), 'All'); + end + + %Test viewer displays ex_spm_thr_voxelfwep05.nidm + function test_ex_spm_thr_voxelfwep05(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_thr_voxelfwep05.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/ex_spm_thr_voxelfwep05.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','ex_spm_thr_voxelfwep05.nidm'), 'All'); + end + + %Test viewer displays ex_spm_thr_voxelunct4.nidm + function test_ex_spm_thr_voxelunct4(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_thr_voxelunct4.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/ex_spm_thr_voxelunct4.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','ex_spm_thr_voxelunct4.nidm'), 'All'); + end + + %Test viewer displays fsl_con_f_130.nidm + function test_fsl_con_f_130(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_con_f_130.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/fsl_con_f_130.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','fsl_con_f_130.nidm'), 'All'); + end + + %Test viewer displays fsl_contrast_mask_130.nidm + function test_fsl_contrast_mask_130(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_contrast_mask_130.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/fsl_contrast_mask_130.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','fsl_contrast_mask_130.nidm'), 'All'); + end + + %Test viewer displays fsl_default_130.nidm + function test_fsl_default_130(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_default_130.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/fsl_default_130.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','fsl_default_130.nidm'), 'All'); + end + + %Test viewer displays fsl_full_examples001_130.nidm + function test_fsl_full_examples001_130(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_full_examples001_130.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/fsl_full_examples001_130.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','fsl_full_examples001_130.nidm'), 'All'); + end + + %Test viewer displays fsl_gamma_basis_130.nidm + function test_fsl_gamma_basis_130(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_gamma_basis_130.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/fsl_gamma_basis_130.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','fsl_gamma_basis_130.nidm'), 'All'); + end + + %Test viewer displays fsl_gaussian_130.nidm + function test_fsl_gaussian_130(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_gaussian_130.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/fsl_gaussian_130.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','fsl_gaussian_130.nidm'), 'All'); + end + + %Test viewer displays fsl_group_btw_130.nidm + function test_fsl_group_btw_130(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_group_btw_130.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/fsl_group_btw_130.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','fsl_group_btw_130.nidm'), 'All'); + end + + %Test viewer displays fsl_group_ols_130.nidm + function test_fsl_group_ols_130(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_group_ols_130.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/fsl_group_ols_130.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','fsl_group_ols_130.nidm'), 'All'); + end + + %Test viewer displays fsl_group_wls_130.nidm + function test_fsl_group_wls_130(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_group_wls_130.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/fsl_group_wls_130.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','fsl_group_wls_130.nidm'), 'All'); + end + + %Test viewer displays fsl_hrf_fir_130.nidm + function test_fsl_hrf_fir_130(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_hrf_fir_130.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/fsl_hrf_fir_130.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','fsl_hrf_fir_130.nidm'), 'All'); + end + + %Test viewer displays fsl_hrf_gammadiff_130.nidm + function test_fsl_hrf_gammadiff_130(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_hrf_gammadiff_130.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/fsl_hrf_gammadiff_130.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','fsl_hrf_gammadiff_130.nidm'), 'All'); + end + + %Test viewer displays fsl_thr_clustfwep05_130.nidm + function test_fsl_thr_clustfwep05_130(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_thr_clustfwep05_130.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/fsl_thr_clustfwep05_130.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','fsl_thr_clustfwep05_130.nidm'), 'All'); + end + + %Test viewer displays fsl_thr_voxelfwep05_130.nidm + function test_fsl_thr_voxelfwep05_130(testCase) + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_thr_voxelfwep05_130.nidm'); + if(~exist(data_path, 'dir')) + mkdir(data_path); + websave([data_path, filesep, 'temp.zip'], 'http://neurovault.org/collections/2210/fsl_thr_voxelfwep05_130.nidm.zip'); + unzip([data_path, filesep, 'temp.zip'], [data_path, filesep]); + end + testCase.delete_html_file(data_path); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..','data','fsl_thr_voxelfwep05_130.nidm'), 'All'); + end + + end + + end \ No newline at end of file diff --git a/test/testFeatures.m b/test/matlabunit_testsuite/testFeatures.m similarity index 71% rename from test/testFeatures.m rename to test/matlabunit_testsuite/testFeatures.m index 8700d75..cf6543b 100644 --- a/test/testFeatures.m +++ b/test/matlabunit_testsuite/testFeatures.m @@ -15,41 +15,28 @@ function delete_html_file(testCase, data_path) delete(index); end end - - %Function for running SPM batch job with input and output as data_path. - function runBatch(testCase, data_path) - - %Write the batch. - matlabbatch{1}.spm.tools.NIDMdisplay.nidmpack = {fullfile(data_path, 'temp.nidm.zip')}; - matlabbatch{1}.spm.tools.NIDMdisplay.dir = {data_path}; - matlabbatch{1}.spm.tools.NIDMdisplay.exSet.allEx = 0; - - %Run the batch. - spm_jobman('run', matlabbatch); - - end end methods(Test) %Checking the viewer runs on SPM-nidm input. function checkViewerRunsSPM(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')), '..', 'test', 'data', 'ex_spm_default.nidm'); + data_path = fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'ex_spm_default.nidm'); if(~exist(data_path, 'dir')) mkdir(data_path) websave(fullfile(data_path, 'tmp.zip'), 'http://neurovault.org/collections/2210/ex_spm_default.nidm.zip'); unzip(fullfile(data_path, 'tmp.zip'), fullfile(data_path, '.')); end testCase.delete_html_file(data_path); - runBatch(testCase, data_path); + nidm_results_display(data_path); end %Checking the experiment title is somewhere in the output HTML %file. function checkForTitle(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')), '..', 'test', 'data', 'ex_spm_default.nidm'); + data_path = fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'ex_spm_default.nidm'); testCase.delete_html_file(data_path); - runBatch(testCase, data_path); + nidm_results_display(data_path); text = fileread(fullfile(data_path, 'index.html')); verifySubstring(testCase, text, 'tone counting vs baseline'); end @@ -57,7 +44,7 @@ function checkForTitle(testCase) %Checking the original functionality of the viewer with the %original SPM, xSPM and TabDat functions is unaffected. function checkOriginalViewerRuns(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')), '..', 'test', 'data', 'ex_spm_output'); + data_path = fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'ex_spm_output'); testCase.delete_html_file(data_path); cwd = pwd; cd(data_path) @@ -68,32 +55,29 @@ function checkOriginalViewerRuns(testCase) %Checking the viewer runs on FSL-nidm output. function checkViewerRunsFSL(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')), '..', 'test', 'data', 'fsl_default_130.nidm'); + data_path = fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'fsl_default_130.nidm'); testCase.delete_html_file(data_path); - runBatch(testCase, data_path); + nidm_results_display(data_path); end %Checking the viewer runs on SPM-nidm output with no MIP. function checkViewerRunsSPMwoMIP(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')), '..', 'test', 'data', 'ex_spm_default_wo_MIP'); + data_path = fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'ex_spm_default_wo_MIP'); %Copy contents of ex_spm_default NIDM pack. - copyfile(fullfile(fileparts(mfilename('fullpath')), '..', 'test', 'data', 'ex_spm_default.nidm', '*'),... - fullfile(fileparts(mfilename('fullpath')), '..', 'test', 'data', 'ex_spm_default_wo_MIP')); + copyfile(fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'ex_spm_default.nidm', '*'),... + fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'ex_spm_default_wo_MIP')); %Delete the pre-existing jsonld. - if exist(fullfile(fileparts(mfilename('fullpath')), '..', 'test', 'data', 'ex_spm_default_wo_MIP', 'nidm.jsonld'), 'file') - delete(fullfile(fileparts(mfilename('fullpath')), '..', 'test', 'data', 'ex_spm_default_wo_MIP', 'nidm.jsonld')); - end + delete(fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'ex_spm_default_wo_MIP', 'nidm.jsonld')); %Copy the jsonld without the MIP into the NIDM pack. - copyfile(fullfile(fileparts(mfilename('fullpath')), '..', 'test', 'data', 'testJsons', 'nidm.jsonld'),... - fullfile(fileparts(mfilename('fullpath')), '..', 'test', 'data', 'ex_spm_default_wo_MIP')); + copyfile(fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'testJsons', 'nidm.jsonld'), fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'ex_spm_default_wo_MIP')); %Run the test. testCase.delete_html_file(data_path); - runBatch(testCase, data_path); + nidm_results_display(data_path); end % %Checking the nidm json is not damaged by the viewer. % function checkNIDMUnaffected(testCase) -% fsl_default_dir = fullfile(fileparts(mfilename('fullpath')), '..', 'test', 'data', 'fsl_default'); +% fsl_default_dir = fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'fsl_default'); % testCase.delete_html_file(fsl_default_dir); % nidm_results_display(fullfile(fsl_default_dir, 'nidm.json')); % originalNIDM = spm_jsonread(fullfile(fsl_default_dir, 'nidmWithoutMip.json')); diff --git a/test/moxunit_testsuite/bug_patches/spm_file_template.patch b/test/moxunit_testsuite/bug_patches/spm_file_template.patch new file mode 100644 index 0000000..0a42e0b --- /dev/null +++ b/test/moxunit_testsuite/bug_patches/spm_file_template.patch @@ -0,0 +1,18 @@ +--- spm_file_template.m ++++ spm_file_template.m +@@ -28,11 +28,11 @@ + end + + properties (SetAccess='private', GetAccess='private') +- filekeys; +- filenames; ++ filekeys = {}; ++ filenames = {}; + +- varkeys; +- varvals; ++ varkeys = {}; ++ varvals = {}; + end + + %-Constructor \ No newline at end of file diff --git a/test/moxunit_testsuite/runTest.sh b/test/moxunit_testsuite/runTest.sh new file mode 100755 index 0000000..1348b7a --- /dev/null +++ b/test/moxunit_testsuite/runTest.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# ======================================================================= +# This file contains the setup for the NIDMResults SPM viewer CI travis +# tests which MUST be done inside the docker container. +# +# Author: Tom Maullin (22/05/2018) +# ======================================================================= + +# Install MOxUnit +echo "Installing MOxUnit for Octave..." +cd /spmviewer/test/moxunit_testsuite/MOxUnit +make install-octave +cd .. + +# Bug fix for SPM +patch -p0 < /spmviewer/test/moxunit_testsuite/bug_patches/spm_file_template.patch /code/spm12/spm_file_template.m + +# Run the tests. (We turn off the shadowed function warning as our copy of the +# statistics package contains several duplicate functions which casue errors when +# added to our path). +testresult=$(octave --no-window-system --eval "addpath(genpath('/spmviewer/'));moxunit_runtests") +echo "$testresult" + +# If the tests failed, we need to let Travis know. +if [[ $testresult = *"FAILED"* ]]; then + exit 1 +else + exit 0 +fi diff --git a/test/moxunit_testsuite/testDataSets.m b/test/moxunit_testsuite/testDataSets.m new file mode 100644 index 0000000..acc1008 --- /dev/null +++ b/test/moxunit_testsuite/testDataSets.m @@ -0,0 +1,220 @@ +%========================================================================== +%Unit tests for testing whether datasets run in the viewer. To run the +%below run the runTest function. The html files generated can be found in +%the corresponding folders after the test has been run. +% +%Authors: Thomas Maullin, Camille Maumet. (Adapted from the testDataSets +%matlab unittest function). +%========================================================================== + +function test_suite=testDataSets + try % assignment of 'localfunctions' is necessary in Matlab >= 2016 + test_functions=localfunctions(); + catch % no problem; early Matlab versions can use initTestSuite fine + end + initTestSuite; +end + +%Function for deleting any HTML generated previously by the viewer +function delete_html_file(data_path) + index = fullfile(data_path,'index.html'); + if exist(index, 'file') + delete(index); + else + for(i = 1:8) + index = fullfile(data_path,['index', num2str(i), '.html']); + if exist(index, 'file') + delete(index); + end + end + end +end + +%Test viewer displays ex_spm_HRF_informed_basis.nidm +function test_ex_spm_HRF_informed_basis() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_HRF_informed_basis.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','ex_spm_HRF_informed_basis.nidm.zip'), 'All'); +end + +%Test viewer displays ex_spm_conjunction.nidm +function test_ex_spm_conjunction() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_conjunction.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','ex_spm_conjunction.nidm.zip'), 'All'); +end + +%Test viewer displays ex_spm_contrast_mask.nidm +function test_ex_spm_contrast_mask() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_contrast_mask.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','ex_spm_contrast_mask.nidm.zip'), 'All'); +end + +%Test viewer displays ex_spm_default.nidm +function test_ex_spm_default() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_default.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','ex_spm_default.nidm.zip'), 'All'); +end + +%Test viewer displays ex_spm_full_example001.nidm +function test_ex_spm_full_example001() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_full_example001.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','ex_spm_full_example001.nidm.zip'), 'All'); +end + +%Test viewer displays ex_spm_group_ols.nidm +function test_ex_spm_group_ols() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_group_ols.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','ex_spm_group_ols.nidm.zip'), 'All'); +end + +%Test viewer displays ex_spm_group_wls.nidm +function test_ex_spm_group_wls() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_group_wls.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','ex_spm_group_wls.nidm.zip'), 'All'); +end + +%Test viewer displays ex_spm_partial_conjunction.nidm +function test_ex_spm_partial_conjunction() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_partial_conjunction.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','ex_spm_partial_conjunction.nidm.zip'), 'All'); +end + +%Test viewer displays ex_spm_temporal_derivative.nidm +function test_ex_spm_temporal_derivative() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_temporal_derivative.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','ex_spm_temporal_derivative.nidm.zip'), 'All'); +end + +%Test viewer displays ex_spm_thr_clustfwep05.nidm +function test_ex_spm_thr_clustfwep05() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_thr_clustfwep05.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','ex_spm_thr_clustfwep05.nidm.zip'), 'All'); +end + +%Test viewer displays ex_spm_thr_clustunck10.nidm +function test_ex_spm_thr_clustunck10() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_thr_clustunck10.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','ex_spm_thr_clustunck10.nidm.zip'), 'All'); +end + +%Test viewer displays ex_spm_thr_voxelfdrp05.nidm +function test_ex_spm_thr_voxelfdrp05() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_thr_voxelfdrp05.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','ex_spm_thr_voxelfdrp05.nidm.zip'), 'All'); +end + +%Test viewer displays ex_spm_thr_voxelfwep05.nidm +function test_ex_spm_thr_voxelfwep05() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_thr_voxelfwep05.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','ex_spm_thr_voxelfwep05.nidm.zip'), 'All'); +end + +%Test viewer displays ex_spm_thr_voxelunct4.nidm +function test_ex_spm_thr_voxelunct4() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','ex_spm_thr_voxelunct4.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','ex_spm_thr_voxelunct4.nidm.zip'), 'All'); +end + +%Test viewer displays fsl_con_f_130.nidm +function test_fsl_con_f_130() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_con_f_130.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','fsl_con_f_130.nidm.zip'), 'All'); +end + +%Test viewer displays fsl_contrast_mask_130.nidm +function test_fsl_contrast_mask_130() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_contrast_mask_130.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','fsl_contrast_mask_130.nidm.zip'), 'All'); +end + +%Test viewer displays fsl_default_130.nidm +function test_fsl_default_130() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_default_130.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','fsl_default_130.nidm.zip'), 'All'); +end + +%Test viewer displays fsl_full_examples001_130.nidm +function test_fsl_full_examples001_130() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_full_examples001_130.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','fsl_full_examples001_130.nidm.zip'), 'All'); +end + +%Test viewer displays fsl_gamma_basis_130.nidm +function test_fsl_gamma_basis_130() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_gamma_basis_130.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','fsl_gamma_basis_130.nidm.zip'), 'All'); +end + +%Test viewer displays fsl_gaussian_130.nidm +function test_fsl_gaussian_130() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_gaussian_130.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','fsl_gaussian_130.nidm.zip'), 'All'); +end + +%Test viewer displays fsl_group_btw_130.nidm +function test_fsl_group_btw_130() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_group_btw_130.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','fsl_group_btw_130.nidm.zip'), 'All'); +end + +%Test viewer displays fsl_group_ols_130.nidm +function test_fsl_group_ols_130() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_group_ols_130.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','fsl_group_ols_130.nidm.zip'), 'All'); +end + +%Test viewer displays fsl_group_wls_130.nidm +function test_fsl_group_wls_130() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_group_wls_130.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','fsl_group_wls_130.nidm.zip'), 'All'); +end + +%Test viewer displays fsl_hrf_fir_130.nidm +function test_fsl_hrf_fir_130() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_hrf_fir_130.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','fsl_hrf_fir_130.nidm.zip'), 'All'); +end + +%Test viewer displays fsl_hrf_gammadiff_130.nidm +function test_fsl_hrf_gammadiff_130() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_hrf_gammadiff_130.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','fsl_hrf_gammadiff_130.nidm.zip'), 'All'); +end + +%Test viewer displays fsl_thr_clustfwep05_130.nidm +function test_fsl_thr_clustfwep05_130() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_thr_clustfwep05_130.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','fsl_thr_clustfwep05_130.nidm.zip'), 'All'); +end + +%Test viewer displays fsl_thr_voxelfwep05_130.nidm +function test_fsl_thr_voxelfwep05_130() + data_path = fullfile(fileparts(mfilename('fullpath')),'..','data','fsl_thr_voxelfwep05_130.nidm.zip'); + delete_html_file(strrep(data_path, '.zip', '')); + nidm_results_display(fullfile(fileparts(mfilename('fullpath')), '..', 'data','fsl_thr_voxelfwep05_130.nidm.zip'), 'All'); +end diff --git a/test/moxunit_testsuite/testFeatures.m b/test/moxunit_testsuite/testFeatures.m new file mode 100644 index 0000000..a945e02 --- /dev/null +++ b/test/moxunit_testsuite/testFeatures.m @@ -0,0 +1,99 @@ +%========================================================================== +%Unit tests for testing features of the viewer. To run the below run the +%runTest function. +% +%Authors: Thomas Maullin, Camille Maumet. +%========================================================================== + +function test_suite=testFeatures + try % assignment of 'localfunctions' is necessary in Matlab >= 2016 + test_functions=localfunctions(); + catch % no problem; early Matlab versions can use initTestSuite fine + end + initTestSuite; +end + +% Function for deleting any HTML generated previously by the viewer +function delete_html_file(data_path) + index = fullfile(data_path,'index.html'); + if exist(index, 'file') + delete(index); + else + for(i = 1:8) + index = fullfile(data_path,['index', num2str(i), '.html']); + if exist(index, 'file') + delete(index); + end + end + end +end + +% testing the viewer runs on SPM-nidm input. +function testViewerRunsSPM() + data_path = fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'ex_spm_default.nidm'); + delete_html_file(data_path); + nidm_results_display(data_path); +end + +% testing the experiment title is somewhere in the output HTML +% file. +function testForTitle() + data_path = fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'ex_spm_default.nidm'); + delete_html_file(data_path); + nidm_results_display(data_path); + text = fileread(fullfile(data_path, 'index.html')); + assertEqual(~isempty(findstr(text, 'tone counting vs baseline')),true); +end + +% testing the original functionality of the viewer with the +% original SPM, xSPM and TabDat functions is unaffected. +function testOriginalViewerRuns() + data_path = fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'ex_spm_output'); + delete_html_file(data_path); + cwd = pwd; + cd(data_path) + testData = load(fullfile(data_path, 'nidm_example001.mat')); + spm_results_export(testData.SPM, testData.xSPM, testData.TabDat); + cd(cwd); +end + +% testing the viewer runs on FSL-nidm output. +function testViewerRunsFSL() + data_path = fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'fsl_default_130.nidm'); + delete_html_file(data_path); + nidm_results_display(data_path); +end + +%testing the viewer runs on SPM-nidm output with no MIP. +function testViewerRunsSPMwoMIP() + data_path = fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'ex_spm_default_wo_MIP'); + % Make the directory if needed. + if ~exist(data_path) + mkdir(data_path) + end + % Copy contents of ex_spm_default NIDM pack. + copyfile(fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'ex_spm_default.nidm', '*'),... + data_path); + %Delete the pre-existing jsonld. + delete(fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'ex_spm_default_wo_MIP', 'nidm.jsonld')); + % Copy the jsonld without the MIP into the NIDM pack. + copyfile(fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'testJsons', 'nidm.jsonld'), data_path); + % Run the test. + delete_html_file(data_path); + nidm_results_display(data_path); +end + +% %testing the nidm json is not damaged by the viewer. +% function testNIDMUnaffected() +% fsl_default_dir = fullfile(fileparts(mfilename('fullpath')), '..', 'data', 'fsl_default'); +% delete_html_file(fsl_default_dir); +% nidm_results_display(fullfile(fsl_default_dir, 'nidm.json')); +% originalNIDM = spm_jsonread(fullfile(fsl_default_dir, 'nidmWithoutMip.json')); +% currentNIDM = spm_jsonread(fullfile(fsl_default_dir, 'nidm.json')); +% %Choose a random vertex in the graph that we know should not have been changed. +% testObject = 20; +% while testObject == 20 +% testObject = randi(length(originalNIDM.x_graph)); +% end +% verifyEqual(currentNIDM.x_graph{testObject}, originalNIDM.x_graph{testObject}); +% end diff --git a/test/retrieveFile.m b/test/retrieveFile.m deleted file mode 100644 index ecdd910..0000000 --- a/test/retrieveFile.m +++ /dev/null @@ -1,27 +0,0 @@ -%========================================================================== -%This function deletes the current file under 'filename' and checks to see -%if there is a file 'filenameTemp' stored. If there is, then 'filenameTemp' -%is renamed to 'filename'. This can be used in the teardown procedures for -%the tests. It takes as inputs: -% -%filepath - the location of the file. -%filename - the name to be recovered. -% -%Authors: Thomas Maullin, Camille Maumet. -%========================================================================== - -function retrieveHTMLFile(filepath, filename) - - %If the file exists delete it. - if exist(fullfile(filepath, filename), 'file') == 2 - delete(fullfile(filepath, filename)) - end - - %If the temp version exists move it back. - [~, name, ext] = fileparts(filename); - filenameTemp = [name, 'Temp', ext]; - if exist(fullfile(filepath, filenameTemp), 'file') == 2 - movefile(fullfile(filepath, filenameTemp), fullfile(filepath, filename), 'f'); - end - -end diff --git a/test/storeFile.m b/test/storeFile.m deleted file mode 100644 index 7311327..0000000 --- a/test/storeFile.m +++ /dev/null @@ -1,32 +0,0 @@ -%========================================================================== -%This function moves the file 'filename' to a temporary location -%'filenameTemp' to prevent the tests overwriting any of the users data. If -%only one argument is provided it is assumed the file in question is named -%'index.html'. It takes the following inputs: -% -%filepath - the location of the file. -%filename - the name to be changed. If not entered it is assumed we are -%looking for the 'index.html' file. -% -%Authors: Thomas Maullin, Camille Maumet -%========================================================================== - -function storeFile(filepath, filename) - - %If there's one input move 'index.html'. - if nargin == 1 - if exist(fullfile(filepath, 'index.html')) == 2 - movefile(fullfile(filepath, 'index.html'), spm_file(fullfile(filepath, 'indexTemp.html'), 'unique')); - end - end - - %If there's two inputs move filename. - if nargin == 2 - if exist(fullfile(filepath, filename)) == 2 - [~, name, ext] = fileparts(filename); - filenameTemp = [name, 'Temp', ext]; - movefile(fullfile(filepath, filename), fullfile(filepath, filenameTemp)); - end - end - -end \ No newline at end of file diff --git a/test/testDataSets.m b/test/testDataSets.m deleted file mode 100644 index e48e9da..0000000 --- a/test/testDataSets.m +++ /dev/null @@ -1,342 +0,0 @@ -%========================================================================== -%Unit tests for testing whether datasets run in the viewer. To run the -%below run the runTest function. The html files generated can be found in -%the corresponding folders after the test has been run. -% -%Authors: Thomas Maullin, Camille Maumet. (Generated by the createTest -%function). -%========================================================================== - classdef testDataSets < matlab.unittest.TestCase - - methods - %Function for deleting any HTML generated previously by the viewer - function delete_html_file(testCase, data_path) - index = fullfile(data_path,'index.html'); - if exist(index, 'file') - delete(index); - else - for(i = 1:8) - index = fullfile(data_path,['index', num2str(i), '.html']); - if exist(index, 'file') - delete(index); - end - end - end - end - - %Function for running SPM batch job with input and output as data_path. - function runBatch(testCase, data_path) - - %Write the batch. - matlabbatch{1}.spm.tools.NIDMdisplay.nidmpack = {fullfile(data_path, 'temp.nidm.zip')}; - matlabbatch{1}.spm.tools.NIDMdisplay.dir = {data_path}; - matlabbatch{1}.spm.tools.NIDMdisplay.exSet.allEx = 0; - - %Run the batch. - spm_jobman('run', matlabbatch); - - end - end - - methods(Test) - - %Test viewer displays ex_spm_HRF_informed_basis.nidm - function test_ex_spm_HRF_informed_basis(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','ex_spm_HRF_informed_basis.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/ex_spm_HRF_informed_basis.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays ex_spm_conjunction.nidm - function test_ex_spm_conjunction(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','ex_spm_conjunction.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/ex_spm_conjunction.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays ex_spm_contrast_mask.nidm - function test_ex_spm_contrast_mask(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','ex_spm_contrast_mask.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/ex_spm_contrast_mask.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays ex_spm_default.nidm - function test_ex_spm_default(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','ex_spm_default.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/ex_spm_default.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays ex_spm_full_example001.nidm - function test_ex_spm_full_example001(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','ex_spm_full_example001.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/ex_spm_full_example001.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays ex_spm_group_ols.nidm - function test_ex_spm_group_ols(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','ex_spm_group_ols.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/ex_spm_group_ols.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays ex_spm_group_wls.nidm - function test_ex_spm_group_wls(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','ex_spm_group_wls.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/ex_spm_group_wls.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays ex_spm_partial_conjunction.nidm - function test_ex_spm_partial_conjunction(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','ex_spm_partial_conjunction.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/ex_spm_partial_conjunction.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays ex_spm_temporal_derivative.nidm - function test_ex_spm_temporal_derivative(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','ex_spm_temporal_derivative.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/ex_spm_temporal_derivative.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays ex_spm_thr_clustfwep05.nidm - function test_ex_spm_thr_clustfwep05(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','ex_spm_thr_clustfwep05.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/ex_spm_thr_clustfwep05.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays ex_spm_thr_clustunck10.nidm - function test_ex_spm_thr_clustunck10(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','ex_spm_thr_clustunck10.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/ex_spm_thr_clustunck10.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays ex_spm_thr_voxelfdrp05.nidm - function test_ex_spm_thr_voxelfdrp05(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','ex_spm_thr_voxelfdrp05.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/ex_spm_thr_voxelfdrp05.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays ex_spm_thr_voxelfwep05.nidm - function test_ex_spm_thr_voxelfwep05(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','ex_spm_thr_voxelfwep05.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/ex_spm_thr_voxelfwep05.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays ex_spm_thr_voxelunct4.nidm - function test_ex_spm_thr_voxelunct4(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','ex_spm_thr_voxelunct4.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/ex_spm_thr_voxelunct4.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays fsl_con_f_130.nidm - function test_fsl_con_f_130(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','fsl_con_f_130.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/fsl_con_f_130.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays fsl_contrast_mask_130.nidm - function test_fsl_contrast_mask_130(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','fsl_contrast_mask_130.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/fsl_contrast_mask_130.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays fsl_default_130.nidm - function test_fsl_default_130(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','fsl_default_130.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/fsl_default_130.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays fsl_full_examples001_130.nidm - function test_fsl_full_examples001_130(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','fsl_full_examples001_130.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/fsl_full_examples001_130.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays fsl_gamma_basis_130.nidm - function test_fsl_gamma_basis_130(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','fsl_gamma_basis_130.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/fsl_gamma_basis_130.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays fsl_gaussian_130.nidm - function test_fsl_gaussian_130(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','fsl_gaussian_130.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/fsl_gaussian_130.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays fsl_group_btw_130.nidm - function test_fsl_group_btw_130(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','fsl_group_btw_130.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/fsl_group_btw_130.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays fsl_group_ols_130.nidm - function test_fsl_group_ols_130(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','fsl_group_ols_130.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/fsl_group_ols_130.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays fsl_group_wls_130.nidm - function test_fsl_group_wls_130(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','fsl_group_wls_130.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/fsl_group_wls_130.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays fsl_hrf_fir_130.nidm - function test_fsl_hrf_fir_130(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','fsl_hrf_fir_130.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/fsl_hrf_fir_130.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays fsl_hrf_gammadiff_130.nidm - function test_fsl_hrf_gammadiff_130(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','fsl_hrf_gammadiff_130.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/fsl_hrf_gammadiff_130.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays fsl_thr_clustfwep05_130.nidm - function test_fsl_thr_clustfwep05_130(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','fsl_thr_clustfwep05_130.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/fsl_thr_clustfwep05_130.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - %Test viewer displays fsl_thr_voxelfwep05_130.nidm - function test_fsl_thr_voxelfwep05_130(testCase) - data_path = fullfile(fileparts(mfilename('fullpath')),'..','test','data','fsl_thr_voxelfwep05_130.nidm'); - if(~exist(data_path, 'dir')) - mkdir(data_path); - websave([data_path, filesep, 'temp.nidm.zip'], 'http://neurovault.org/collections/2210/fsl_thr_voxelfwep05_130.nidm.zip'); - end - testCase.delete_html_file(data_path); - runBatch(testCase, data_path); - end - - end - - end \ No newline at end of file