-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathComputeBehaviorAnatomyMap.m
135 lines (110 loc) · 3.49 KB
/
ComputeBehaviorAnatomyMap.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
function res = ComputeBehaviorAnatomyMap(normbehaviordata,behaviorlabels,varargin)
res = struct;
%% parse inputs
timestamp = datestr(now,'yyyymmddTHHMMSSFFF');
[matfile,fdr_alpha,...
plotadjusted,maxpvalue,minpvalue,dologcmap,nslices,...
usecluster,nsamplestotal,nsamplesperbatch,scriptdir,timestamp,...
hfigs,doplot] = ...
myparse(varargin,'matfile','/groups/branson/bransonlab/projects/olympiad/FlyBowlAnalysis/ComputeBehaviorAnatomyMapData_ms_centers0.750000_w0.000010_r2_20150202.mat',...
'fdr_alpha',.25,...
'plotadjusted',false,...
'maxpvalue',[],'minpvalue',[],...
'dologcmap',true,'nslices',3,...
'usecluster',false,...
'nsamplestotal',1000,...
'nsamplesperbatch',1000,...
'scriptdir','',...
'timestamp',timestamp,...
'hfigs',[],...
'doplot',true);
if usecluster && isempty(scriptdir),
scriptdir = sprintf('/nobackup/branson/pv%s',timestamp);
if ~exist(scriptdir,'dir'),
mkdir(scriptdir);
end
if ~exist(scriptdir,'dir'),
error('Could not create directory %s',scriptdir);
end
end
if isempty(minpvalue),
if dologcmap,
minpvalue = .0001;
else
minpvalue = 0;
end
end
%% load cached data
persistent prevmatfile;
persistent supervoxeldata; %#ok<USENS>
persistent labels; %#ok<USENS>
persistent maskdata; %#ok<USENS>
doload = false;
if isempty(prevmatfile) || ~strcmp(prevmatfile,matfile) || ...
isempty(supervoxeldata) || isempty(labels) || isempty(maskdata),
doload = true;
load(matfile,'supervoxeldata');
prevmatfile = matfile;
end
res.matfile = matfile;
res.supervoxeldata = supervoxeldata;
%% compute behavior-anatomy index
res.baindex = ComputeBAIndex(normbehaviordata,supervoxeldata);
%% compute p-values
[res.pvalue] = ...
ComputeBehaviorAnatomyCorrPValues_asymm(normbehaviordata,...
supervoxeldata,res.baindex,...
nsamplestotal,...
'usecluster',usecluster,'nsamplesperbatch',nsamplesperbatch,...
'tmpdir',scriptdir,'timestamp',timestamp,'doclean',true);
%% correct for fdr
res.qvalue = nan(size(res.pvalue));
h_plus = false(size(res.pvalue));
for i = 1:size(res.pvalue,2),
[h,~,adj_p] = fdr_bh(res.pvalue(:,i),fdr_alpha,'pdep');
%adj_p(~h) = 1;
res.qvalue(:,i) = adj_p;
h_plus(:,i) = h;
end
res.pvalue_fdr = res.pvalue;
res.pvalue_fdr(~h_plus) = 1;
if plotadjusted,
pvalue_plot = res.qvalue;
if isempty(maxpvalue),
maxpvalue = fdr_alpha+.001;
end
else
pvalue_plot = res.pvalue_fdr;
if isempty(maxpvalue),
maxpvalue = .051;
end
end
%% reproject
if doplot,
if doload,
load(matfile,'labels','maskdata');
end
res.behaviormaps = cell(numel(behaviorlabels),1);
clims = cell(numel(behaviorlabels),1);
res.imouts = cell(numel(behaviorlabels),1);
res.imoutxs = cell(numel(behaviorlabels),1);
maxprojslices = cell(numel(behaviorlabels),1);
maxprojslicesx = cell(numel(behaviorlabels),1);
for stati = 1:numel(behaviorlabels),
if numel(hfigs) >= 2*stati,
hfigscurr = hfigs(2*stati-1:2*stati);
else
hfigscurr = [];
end
behaviorname = behaviorlabels{stati};
behaviorname(1) = upper(behaviorname(1));
figtitle = behaviorname;
[hfigs(2*stati-1:2*stati),res.behaviormaps{stati,1},clims{stati,1},...
res.imouts{stati,1},res.imoutxs{stati,1},maxprojslices{stati,1},maxprojslicesx{stati,1}] = ...
PlotBehaviorAnatomyMap(pvalue_plot(:,stati),labels,...
'figtitle',figtitle,'minpvalue',minpvalue,...
'maxpvalue',maxpvalue','dologcmap',dologcmap,...
'hfigs',hfigscurr,'maskdata',maskdata,'nslices',nslices);
end
res.hfigs = hfigs;
end