Skip to content

Commit

Permalink
Merge pull request #23 from nicholst/SnPM13.1.5
Browse files Browse the repository at this point in the history
SnPM 13.1.5: hot fix for two-sample test
  • Loading branch information
Camille Maumet authored Jul 22, 2016
2 parents 5b66750 + 8d16b07 commit f254ffc
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 25 deletions.
44 changes: 25 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ run(test_oneSample, 'test_onesample_1')
This section describes the bugs that have been reported, along with the appropriate fixes.
Updated versions of appropriate SnPM functions are available at [snpm13_updates](http://warwick.ac.uk/snpm/distribution/snpm13_updates)

#### SnPM 13.1.04
##### SnPM 13.1.05
* fix: two-sample t-test with nscans>12 was errored due to call to undefined variable `nPerm` (bug introduced in previous release: 13.1.4) (`snpm_pi_TwoSampT`)
* fix: warning on size of `SnPM_ST.mat` was never raised
* Add seed shuffling for paired two-sample test modules (`snpm_pi_PairT`, `snpm_pi_PairTrand`)
* Version 13.1.05 (`snpm`)

##### SnPM 13.1.04
* snpm
SnPM version 13.1.04

Expand Down Expand Up @@ -77,14 +83,14 @@ test_onesub_twocondrepl, test_twoSample, test_twosample_twocond
Test in command-line mode with no shuffling for the random seed, using new rng
syntax.

#### Updates from SnPM 13.1.03
##### Updates from SnPM 13.1.03
* snpm
SnPM version 13.1.03

* snpm_pi_PairT
Now allows more than 52 subjects, as previously that would generate a "Maximum variable size allowed by the program" error message.

#### Updates from SnPM 13.1.02
##### Updates from SnPM 13.1.02
* snpm
SnPM version 13.1.02

Expand All @@ -94,30 +100,30 @@ Update contrast display for compatibility with Matlab R2014b.
* generic_test_snpm
Updates affecting tests only.

#### Updates from SnPM 13.1.01
##### Updates from SnPM 13.1.01
* snpm
SnPM version 13.1.01

* snpm_pp
Check that 'Locs_vox' is integer according to a pre-defined tolerance level (as in snpm_cp).

#### Updates from SnPM13.1.00
##### Updates from SnPM13.1.00
* snpm_cp, snpm_pp, generic_test_snpm, test_oneSample
Cluster-forming threshold defined by a P-value are now extended to pseudo-T statistic (with variance smoothing). The Z-score corresponding to the selected P-value is used as an approximation of pseudo-T values.

#### Updates from SnPM13.0.14
##### Updates from SnPM13.0.14
* snpm_bch_ui_Corr, snpm_bch_ui_Corr1S, snpm_pi_Corr, snpm_pi_Corr1S, test_multisubsimpleregression, test_onesub_regression
Introduce nuisance covariates in simple-subject and multi-subject regressions.

#### Updates from SnPM13.0.13
##### Updates from SnPM13.0.13
* snpm_combo_pp
Fix: Set bNeg to 0 for F-tests.

#### Updates from SnPM13.0.12
##### Updates from SnPM13.0.12
* snpm_pi_OneSampT
Fix: Added new random mode for sampling of sign flips (Above 53 scans the binary-coding fails as Matlab's double significand runs out of precision).

#### Updates from SnPM13.0.11
##### Updates from SnPM13.0.11
* snpm_ui
Fix: When relative thresholding is set, then global calculation (user defined or mean) must be computed.

Expand All @@ -127,22 +133,22 @@ Fix: Unbalanced two-sample tests were wrongly aborted.
* test_multisubpaired2cond, test_oneSample, test_twoSample, test_twosample_twocond
Updates affecting tests only.

#### Updates from SnPM13.0.10
##### Updates from SnPM13.0.10
* snpm_ui
Fix: ANCOVA normalisation (with an image presenting negative mean using spm_globals).

#### Updates from SnPM13.09
##### Updates from SnPM13.09
* snpm_cp
Increase tolerance in checking that 'Locs_vox' is integer.

#### Updates from SnPM13.08
##### Updates from SnPM13.08
* snpm_cp, spm_append_96
Display warning message if SnPM_ST file becomes very large. Display more meaningful error message when Locs_vox is not interger.

* snpm_pp
Display warning message if SnPM_ST can not be loaded.

#### Updates from SnPM13.07
##### Updates from SnPM13.07
* snpm
For backward-compatibility, open SPM batch window and display where to find SnPM tools when 'snpm' in called at the Matlab prompt.

Expand All @@ -152,14 +158,14 @@ Fix: slow cluster inference with variance smoothing.
* generic_test_snpm, test_oneSample, test_twoSample
Updates affecting tests only.

#### Updates from SnPM13.06
##### Updates from SnPM13.06
* snpm_ui
Apply user-defined scaling.

* generic_test_snpm, test_oneSample, test_onesub_twocondrepl, test_twoSample
Updates affecting tests only.

#### Updates from SnPM13.05
##### Updates from SnPM13.05
* snpm_STcalc
Cluster labels from spm_max are not necessarily continuous.

Expand All @@ -169,15 +175,15 @@ Fix: if number of requested permutations is equal to the maximum number of possi
* snpm_pi_TwoSampTss, snpm_pi_TwoSampPairT, snpm_pi_TwoSampT
Compute possible permutations (PiCond) in a more efficient way to avoid potential memory faults for large groups.

#### Updates from SnPM13.04
##### Updates from SnPM13.04
* snpm_ui
Apply absolute and relative masking.

#### Updates from SnPM13.03
##### Updates from SnPM13.03
* snpm_pi_TwoSampT
Compute possible permutations (PiCond) in a more efficient way to avoid potential memory faults for large groups.

#### Updates from SnPM13.02
##### Updates from SnPM13.02
* snpm_pp
Fix: if the extension is missing in the provided result file name, use .nii by default.
Use NaNs in thresholded map background instead of zeros.
Expand All @@ -191,7 +197,7 @@ Minor update in the display.
* test/
Miror corrections affecting tests procedure only.

#### Updates from SnPM13.01
##### Updates from SnPM13.01
* snpm_cp
Synopsis: When half the permutations are computed (i.e. bhPerms is true) and StartPerm is 2 then the initial number of permutation could be 2 depending on sign of T0.

Expand Down
48 changes: 45 additions & 3 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,56 @@ This file describes the bugs that have been reported, along with the appropriate
Updated versions of appropriate SnPM functions are available from in the snpm13_updates:
http://warwick.ac.uk/snpm/distribution/snpm13_updates

--- SnPM13.1.03 ---
--- SnPM 13.1.05 ---
* fix: two-sample t-test with nscans>12 was errored due to call to undefined variable `nPerm` (bug introduced in previous release: 13.1.4) (`snpm_pi_TwoSampT`)
* fix: warning on size of `SnPM_ST.mat` was never raised
* Add seed shuffling for paired two-sample test modules (`snpm_pi_PairT`, `snpm_pi_PairTrand`)
* Version 13.1.05 (`snpm`)

--- SnPM 13.1.04 ---
* snpm
SnPM version 13.1.04

* snpm_bch_ui, snpm_cp, snpm_ui
Fix: implicit masking for non-float datatypes

* snpm_pi_ANOVAbtwnS, snpm_pi_ANOVAwithinS, snpm_pi_Corr, snpm_pi_Corr1S,
snpm_pi_OneSampT, snpm_pi_TwoSampPairT, snpm_pi_TwoSampT, snpm_pi_TwoSampTss
Update syntax to set the seed of the random number generator (rng)

* snpm_defaults
New SnPM global parameter shuffle_seed. If true, the rng uses a 'shuffle' seed providing different results for each run. If false Matlab's 'default' seed or any seed defined by the user will be used .

* snpm_pi_TwoSampT
Allows MC permutation (with reptitions) for large enough nPerms

* snpm_pp, snpm_ui
Do not display figures in command-line mode

* snpm, snpm_check_nperm, snpm_combo, snpm_cp, snpm_init, snpm_pi_ANOVAbtwnS,
snpm_pi_ANOVAwithinS, snpm_pi_Corr, snpm_pi_Corr1S, snpm_pi_OneSampT,
snpm_pi_PairT, snpm_pi_PairTrand, snpm_pi_TwoSampPairT, snpm_pi_TwoSampT,
snpm_pi_TwoSampTss, snpm_pp, snpm_t2z, snpm_uc_FDR, snpm_ui, spm_append_96
Add identifiers to errors and warnings

* snpm_cp
Fix: Do not assume statistic is T when computing cluster forming threshold from P-value

* generic_test_snpm, skeleton_class, test_ANOVAbetween,
test_multisub_withinsubanova, test_multisubpaired2cond,
test_multisubsimpleregression, test_oneSample, test_onesub_regression,
test_onesub_twocondrepl, test_twoSample, test_twosample_twocond
Test in command-line mode with no shuffling for the random seed, using new rng
syntax.

--- Updates from SnPM 13.1.03 ---
* snpm
SnPM version 13.1.03

* snpm_pi_PairT
Now allows more than 52 subjects, as previously that would generate a "Maximum variable size allowed by the program" error message.

--- SnPM13.1.02 ---
--- Updates from SnPM 13.1.02 ---
* snpm
SnPM version 13.1.02

Expand All @@ -21,7 +63,7 @@ Update contrast display for compatibility with Matlab R2014b.
* generic_test_snpm
Updates affecting tests only.

--- SnPM13.1.01 ---
--- Updates from SnPM 13.1.01 ---
* snpm
SnPM version 13.1.01

Expand Down
2 changes: 1 addition & 1 deletion snpm.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

%-Parameters
%-----------------------------------------------------------------------
SnPMver = 'SnPM13.1.04';
SnPMver = 'SnPM13.1.05';

%-Format arguments
%-----------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions snpm_pi_PairT.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@
nCond = 2; % Number of conditions
iGloNorm = '123'; % Allowable Global norm. codes
sDesSave = 'iCond iRepl PiSubj';

if snpm_get_defaults('shuffle_seed')
% Shuffle seed of random number generator
try
rng('shuffle');
catch
% Old syntax
rand('seed',sum(100*clock));
end
end

% PlugIn variables to save in cfg file

%-Get number of subjects
Expand Down
10 changes: 10 additions & 0 deletions snpm_pi_PairTrand.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@
iGloNorm = '123'; % Allowable Global norm. codes
sDesSave = 'iCond iRepl PiSubj';
% PlugIn variables to save in cfg file

if snpm_get_defaults('shuffle_seed')
% Shuffle seed of random number generator
try
rng('shuffle');
catch
% Old syntax
rand('seed',sum(100*clock));
end
end

%-Get number of subjects
nSubj = spm_input('# subjects','+1');
Expand Down
2 changes: 1 addition & 1 deletion snpm_pi_TwoSampT.m
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
% Fill subsequent rows, checking that we're not repeating
for i=2:nPiCond
tmp=PiCond(i-1,randperm(nScan));
if nPerm<=nPermMC
if job.nPerm<=nPermMC
while any(all(PiCond(1:(i-1),:)'==meshgrid(tmp,1:(i-1))'))
tmp=PiCond(i-1,randperm(nScan));
end
Expand Down
2 changes: 1 addition & 1 deletion snpm_pp.m
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ function snpm_pp(CWD,varargin)
try
load(fullfile(CWD,'SnPM_ST'))
catch exception
if strcmp(exception.message, 'File may be corrupt.')
if strcmp(exception.identifier, 'MATLAB:load:unableToReadMatFile')
warning('SnPM:SnPMSTFileNotLOaded', ...
['SnPM_ST file can not be loaded. Consider using' ...
' ''set cluster-forming threshold now (fast)'' option' ...
Expand Down
100 changes: 100 additions & 0 deletions test/test_snpm_pp.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
% Perform tests on error and warnings thrown by snpm_pp
%_______________________________________________________________________
% Copyright (C) 2016 The University of Warwick
% Camille Maumet
classdef test_snpm_pp < matlab.unittest.TestCase
properties
testDataDir;
batchResDir;
parentDataDir;
matlabbatch;
testName;
SnPMrefVersion;
warningId;
end

methods (TestMethodSetup)

function setGlobals(testCase)
% Random number generator should not be initialised with a
% shuffled seed
global SnPMdefs
SnPMdefs.shuffle_seed = false;

% Run the tests in command line mode (no display)
global defaults;
defaults.cmdline = true;

% Disable warning on very small number of permutations
warning('off','SnPM:VeryFewPermsCoarseExactPValues')

snpm_test_config;
cd(spm_str_manip(which('snpm_test_config'), 'h'))
global testDataDir;
global SnPMrefVersion;
testCase.SnPMrefVersion = SnPMrefVersion;

if isempty(testDataDir)
error('SnPM:NotTestDataDir', 'Test data directory not set, please update snpm_test_config');
end

testCase.parentDataDir = spm_str_manip(testDataDir, 'h');
testCase.testDataDir = testDataDir;

testCase.warningId = '';
end
end

methods (Test)
% Test error: No covariate, no variance smoothing and cluster stat
% and huge SnPM_ST file leading to Matlab error
function test_onesample_cluster_err_bigfile(testCase)
testCase.testName = 'onesample_cluster_err_bigfile';
batch_dir = fullfile(testCase.parentDataDir, 'results', 'batch');
testCase.batchResDir = fullfile(batch_dir, testCase.testName);

% Assumes that the onesample_cluster test has been computed
cluster_dir = fullfile(batch_dir, 'onesample_cluster');
if ~isdir(cluster_dir)
error('SnPM:test:MissingOneSampleClusterTest', ...
'One-sample cluster test is missing: Test of the snpm_pp cannot be computed')
end

copyfile(fullfile(cluster_dir),testCase.batchResDir)

% Create very big SnPM.mat
snpmmatfile = fullfile(testCase.batchResDir, 'SnPM_ST.mat');
load(snpmmatfile);
init_ST = SnPM_ST;

SnPM_ST = init_ST;
SnPM_ST = [SnPM_ST; SnPM_ST];
% save(fullfile(testCase.batchResDir, 'SnPM_ST.mat'), 'SnPM_ST')

fid = fopen(snpmmatfile,'a');
fwrite(fid,SnPM_ST,'double');
fclose(fid);

% MATLAB:load:unableToReadMatFile

testCase.matlabbatch{1}.spm.tools.snpm.inference.SnPMmat = {fullfile(testCase.batchResDir, 'SnPM.mat')};
testCase.matlabbatch{1}.spm.tools.snpm.inference.Thr.Clus.ClusSize.CFth = 4;
testCase.matlabbatch{1}.spm.tools.snpm.inference.Thr.Clus.ClusSize.ClusSig.PthC = 0.1;
testCase.matlabbatch{1}.spm.tools.snpm.inference.WriteFiltImg.name = 'SnPMt_filtered_clus_4_unc_p10.nii';

testCase.warningId = 'SnPM:SnPMSTFileNotLOaded';
end
end

methods (TestMethodTeardown) % Start with last method...
function run_batch_and_test(testCase)
verifyError(testCase, @()(spm_jobman('run', testCase.matlabbatch)),'matlabbatch:run:jobfailederr')
% Check manually for warning as is overwritten by error and
% therefore cannot be checked directly with verifyWarning
[~, msgid] = lastwarn;
if ~msgid == testCase.warningId
error(['SnPM:test:MissingWarwning:' testCase.warningId], ['Missing warning: ' testCase.warningId]);
end
end
end
end
Loading

0 comments on commit f254ffc

Please sign in to comment.