1
function [subj] = feature_select_allcondandrestF(subj,data_patin,regsname,selsgroup, numfolds, fixed, fixednum, varargin)
2
%performs voxel selection based on anova of all conditions including rest
5
% [SUBJ] = FEATURE_SELECT(SUBJ,DATA_PATIN,REGSNAME,SELSGROUP,...)
7
% Calls a statmap generation function multiple times, using
8
% a different selector each time. This creates a group of
9
% statmaps, which are then thresholded to create a group of
10
% boolean masks, ready for use in no-peeking
11
% cross-validation classification.
13
% Adds the following objects:
14
% - pattern group of statmaps called NEW_MAP_PATNAME
15
% - mask group based on the statmaps called
16
% sprintf('%s%i',NEW_MASKSTEM,THRESH)
18
% DATA_PATIN should be the name of the pattern object that
19
% contains voxel (or other feature) values that you want to
20
% create a mask of. If DATA_PATIN is a group_name, then this
21
% will use a different member of the group for each
24
% REGSNAME should be a binary nConds x nTimepoints 1-of-n matrix
26
% SELSGROUP should be the name of a selectors group, such as
27
% created by create_xvalid_indices
29
% For each iteration: call the ANOVA on the DATA_PATIN data,
30
% which will produce a statmap, employing only the TRs
31
% labelled with a 1 in the selector for that iteration
33
% NEW_MAP_PATNAME (optional, default = DATA_PATIN +
34
% STRIPPED_NAME). The name of the new statmap pattern group
35
% to be created. By default, this will be 'anova' if
36
% STATMAP_FUNCT = 'statmap_anova' etc.
38
% NEW_MASKSTEM (optional, default = DATA_PATIN +
39
% 'anovathresh'). The name of the new thresholded boolean
40
% mask group to be created from the ANOVA statmap. You'll
41
% need to create multiple mask groups if you want to try out
42
% multiple thresholds, so adding the threshold to the name
45
% THRESH (optional, default = 0.05). Voxels that don't meet
46
% this criterion value don't get included in the boolean
47
% mask that gets created from the ANOVA statmap. If THRESH =
48
% [], the thresholding doesn't get run
50
% STATMAP_FUNCT (optional, default = 'statmap_anova'). Feed
51
% in a function name and this will create a function handle
52
% to that and use it to create the statmaps instead of
55
% STATMAP_ARG (optional, default = []). If you're using an
56
% alternative voxel selection method, you can feed it a
57
% single argument through this
59
% Need to implement a THRESH_TYPE argument (for p vs F
60
% values), which would also set the toggle differently xxx
62
% e.g. subj = feature_select( ...
63
% subj,'epi_z','conds','runs_nmo_xvalid','thresh',0.001)
66
%=====================================================================
68
% This is part of the Princeton MVPA toolbox, released under
69
% the GPL. See http://www.csbmb.princeton.edu/mvpa for more
72
% The Princeton MVPA toolbox is available free and
73
% unsupported to those who might find it useful. We do not
74
% take any responsibility whatsoever for any problems that
75
% you have related to the use of the MVPA toolbox.
77
% ======================================================================
80
defaults.new_map_patname = sprintf('');
81
defaults.new_maskstem = sprintf('%s_thresh',data_patin);
82
defaults.thresh = 0.05;
83
defaults.statmap_funct = 'statmap_anova';
84
defaults.statmap_arg = struct([]);
85
args = propval(varargin,defaults);
87
if isempty(args.new_map_patname)
88
% get the name of the function being run, e.g. 'statmap_anova' -> 'anova'
89
stripped_name = strrep(args.statmap_funct,'statmap_','');
90
args.new_map_patname = sprintf('%s_%s',data_patin,stripped_name);
93
% append the thresh to the end of the name
94
args.new_maskstem = sprintf( ...
95
'%s%s',args.new_maskstem,num2str(args.thresh));
97
% Find the selectors within the specified group
98
selnames = find_group(subj,'selector',selsgroup);
99
nIterations = length(selnames);
101
[data_patnames isgroup] = find_group_single(subj,'pattern',data_patin,'repmat_times',nIterations);
103
if length(data_patnames) ~= length(selnames)
104
error('Different number of patterns and selectors');
108
error('No selectors in %s group',selsgroup);
111
% % this warning used to be here to remind people of the
112
% % existence of peek_feature_select, but since there are good
113
% % reasons why one might want to have just one selector
114
% % without using peek_feature_select, i took it out
115
% if nIterations == 1
116
% warning('You''re only calling the anova once because you have one selector - use peek_feature_select instead?');
119
if ~ischar(args.statmap_funct)
120
error('The statmap function name has to be a string');
123
disp( sprintf('Starting %i %s iterations',nIterations,args.statmap_funct) );
128
% Get the pattern for this iteration
129
cur_data_patname = data_patnames{n};
131
% Get the selector name for this iteration
132
cur_selname = selnames{n};
134
% Name the new statmap pattern and thresholded mask that will be created
135
cur_maskname = sprintf('%s_%i',args.new_maskstem,n);
136
cur_map_patname = sprintf('%s_%i',args.new_map_patname,n);
138
% if a pattern with the same name already exists, it
139
% will trigger an error later in init_object, but we
140
% want to catch it here to save running the entire
142
if exist_object(subj,'pattern',cur_map_patname)
143
error('A pattern called %s already exists',cur_map_patname);
146
if ~isempty(args.statmap_arg) && ~isstruct(args.statmap_arg)
147
warning('Statmap_arg is supposed to be a struct');
150
% Add the current iteration number to the extra_arg, just in case
152
args.statmap_arg(1).cur_iteration = n;
154
% Create a handle for the statmap function handle and then run it
155
% to generate the statmaps
156
statmap_fh = str2func(args.statmap_funct);
157
subj = statmap_fh(subj,cur_data_patname,regsname,cur_selname,cur_map_patname,args.statmap_arg);
158
subj = set_objfield(subj,'pattern',cur_map_patname,'group_name',args.new_map_patname);
161
statvect=get_mat(subj, 'pattern', cur_map_patname);
162
[sortedValues,sortIndex] = sort(statvect,'ascend');
163
if fixednum<length(sortIndex)
164
lowerbound=statvect(sortIndex(fixednum));
166
lowerbound=statvect(sortIndex(end));
168
cur_maskname=[data_patin '_top' num2str(fixednum) '_' num2str(n)];
169
args.new_maskstem=[data_patin '_top' num2str(fixednum)];
170
subj = create_thresh_mask(subj,cur_map_patname,cur_maskname,lowerbound);
171
% subj = init_object(subj,'mask',cur_maskname);
172
% subj = set_mat(subj,'mask',cur_maskname,statvect)
173
subj = set_objfield(subj,'mask',cur_maskname,'group_name',args.new_maskstem);
176
if ~isempty(args.thresh) && ~fixed
177
% Now, create a new thresholded binary mask from the p-values
178
% statmap pattern returned by the anova
179
subj = create_thresh_mask(subj,cur_map_patname,cur_maskname,args.thresh);
180
subj = set_objfield(subj,'mask',cur_maskname,'group_name',args.new_maskstem);
186
disp( sprintf('Pattern statmap group ''%s'' and mask group ''%s'' created by feature_select', ...
187
args.new_map_patname,args.new_maskstem) );