-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKP_2PVR_find_preAndPert_significantSegments_forShuffles.m
More file actions
executable file
·160 lines (156 loc) · 11.5 KB
/
Copy pathKP_2PVR_find_preAndPert_significantSegments_forShuffles.m
File metadata and controls
executable file
·160 lines (156 loc) · 11.5 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
function [prePertAbove,pertAbove,prePertSegments,pertSegments,prePertLeftBorders,prePertRightBorders,pertLeftBorders,pertRightBorders] = KP_2PVR_find_preAndPert_significantSegments_forShuffles(rootInpath,numNeurons,numBins,neuHistInputStruct,fineQuantInputStruct,pertAnaInputStruct,prePerturbZScores,perturbZScores,group,prePert_triggerShuffles)
prePertAbove = zeros(numNeurons,numBins,length(pertAnaInputStruct.pertAcqs));
prePertSegments = zeros(numNeurons,length(pertAnaInputStruct.pertAcqs));
pertAbove = zeros(numNeurons,numBins,length(pertAnaInputStruct.pertAcqs),pertAnaInputStruct.numControls);
pertSegments = zeros(numNeurons,length(pertAnaInputStruct.pertAcqs),pertAnaInputStruct.numControls);
for a = 1:length(pertAnaInputStruct.pertAcqs)
acq = pertAnaInputStruct.pertAcqs(a);
acqFieldName = sprintf('twoPID_%s',acq);
disp(acqFieldName)
anaID = neuHistInputStruct.(acqFieldName);
neuHistID = fineQuantInputStruct.neuHistID;
fineQuantID = fineQuantInputStruct.fineQuantID;
filepath = sprintf('%s%s\\%s\\%s\\%s\\%s\\subAcqs\\SMAPsPerNeuron\\SMAPsPerNeuron',rootInpath,group,acq,anaID,neuHistID,fineQuantID);
load(filepath,'SMAPsPerNeuron')
prePertSMAPs = SMAPsPerNeuron.subAcq1;
pertSMAPs = SMAPsPerNeuron.subAcq2;
prePertNumTrials = size(prePertSMAPs,1);
pertNumTrials = size(pertSMAPs,1);
prePerturb = load(sprintf('%s%s\\%s\\%s\\%s\\%s\\subAcqs\\SMAPsPeaksPerNeuron\\subAcq1\\SMAPsPeaksPerNeuron',rootInpath,group,acq,anaID,neuHistID,fineQuantID));
for n = 1:numNeurons
if ismember(n,pertAnaInputStruct.selectNeurons)
if prePert_triggerShuffles(n,a)
neuron = sprintf('neuron_%i',n);
prePertLeftBorders.(neuron).(acqFieldName) = [];
prePertRightBorders.(neuron).(acqFieldName) = [];
if ~all(prePerturb.lowPassedBinMeanActivity(n,:)==0)
flag_prePertUp = false;
flag_hold_prePert = false;
for b = pertAnaInputStruct.firstCenter:pertAnaInputStruct.lastBin-pertAnaInputStruct.sizeSurround
if ~flag_prePertUp
if prePerturbZScores(n,b,a) > pertAnaInputStruct.zScoreThresh
xUp = b;
flag_prePertUp = true;
end
else
if prePerturbZScores(n,b,a) <= pertAnaInputStruct.zScoreThresh
xDown = b;
flag_prePertUp = false;
sizeAbove = xDown - xUp;
if sizeAbove >= pertAnaInputStruct.sizeAboveThresh
prePert_positive_t = 0;
for t_prePert = 1:prePertNumTrials
trialSMAP = prePertSMAPs(t_prePert,:,n);
[prePert_maxPeak,prePert_valleys,prePert_lowPassedBinMeanActivity] = KP_2PVR_find_candidatePlaceFields_singleTrialRes(trialSMAP, xUp, xDown-1, pertAnaInputStruct);
if ~isnan(prePert_maxPeak)
[prePert_baseCutoff, prePert_binaryTrialSMAP, prePert_baseTrialSMAP, prePert_baseTrialSMAP_mean, prePert_baseTrialSMAP_std, prePert_surroundBorders, prePert_peakZScore, prePert_placeField] = KP_2PVR_select_significantPlaceFields_singleTrialRes(prePert_maxPeak, prePert_valleys, trialSMAP, prePert_lowPassedBinMeanActivity, pertAnaInputStruct.placeSizeVRUnits, pertAnaInputStruct);
else
prePert_placeField = NaN;
end
if ~isnan(prePert_placeField)
prePert_positive_t = prePert_positive_t + 1;
end
end
if pertAnaInputStruct.treshType == "percent"
prePert_percPositive = (prePert_positive_t * 100) / prePertNumTrials;
end
if prePert_percPositive >= pertAnaInputStruct.filter_minTrials
if ~flag_hold_prePert
flag_hold_prePert = true;
end
slice = prePerturbZScores(n,xUp:xDown-1,a);
prePertAbove(n,xUp:xDown-1,a) = slice;
prePertLeftBorders.(neuron).(acqFieldName) = [prePertLeftBorders.(neuron).(acqFieldName);xUp];
prePertRightBorders.(neuron).(acqFieldName) = [prePertRightBorders.(neuron).(acqFieldName);xDown-1];
prePertSegments(n,a) = prePertSegments(n,a) + 1;
end
end
end
end
if b == pertAnaInputStruct.lastBin - pertAnaInputStruct.sizeSurround
if flag_prePertUp
if ~flag_hold_prePert
flag_hold_prePert = true;
end
xDown = b;
slice = prePerturbZScores(n,xUp:xDown,a);
prePertAbove(n,xUp:xDown,a) = slice;
prePertLeftBorders.(neuron).(acqFieldName) = [prePertLeftBorders.(neuron).(acqFieldName);xUp];
prePertRightBorders.(neuron).(acqFieldName) = [prePertRightBorders.(neuron).(acqFieldName);xDown-1];
prePertSegments(n,a) = prePertSegments(n,a) + 1;
flag_prePertUp = false;
end
end
end
if prePert_triggerShuffles(n,a)
for c = 1:pertAnaInputStruct.numControls
contString = sprintf('control_%i',c);
pertLeftBorders.(neuron).(contString).(acqFieldName) = [];
pertRightBorders.(neuron).(contString).(acqFieldName) = [];
flag_pertUp = false;
flag_hold_pert = false;
for b = pertAnaInputStruct.firstCenter:pertAnaInputStruct.lastBin-pertAnaInputStruct.sizeSurround
if ~flag_pertUp
if perturbZScores(n,b,a,c) > pertAnaInputStruct.zScoreThresh
xUp = b;
flag_pertUp = true;
end
else
if perturbZScores(n,b,a,c) <= pertAnaInputStruct.zScoreThresh
xDown = b;
flag_pertUp = false;
sizeAbove = xDown - xUp;
if sizeAbove >= pertAnaInputStruct.sizeAboveThresh
pert_positive_t = 0;
for t_pert = 1:pertNumTrials
trialSMAP = pertSMAPs(t_pert,:,n);
[pert_maxPeak,pert_valleys,pert_lowPassedBinMeanActivity] = KP_2PVR_find_candidatePlaceFields_singleTrialRes(trialSMAP, xUp, xDown-1, pertAnaInputStruct);
if ~isnan(pert_maxPeak)
[pert_baseCutoff, pert_binaryTrialSMAP, pert_baseTrialSMAP, pert_baseTrialSMAP_mean, pert_baseTrialSMAP_std, pert_surroundBorders, pert_peakZScore, pert_placeField] = KP_2PVR_select_significantPlaceFields_singleTrialRes(pert_maxPeak, pert_valleys, trialSMAP, pert_lowPassedBinMeanActivity, pertAnaInputStruct.placeSizeVRUnits, pertAnaInputStruct);
else
pert_placeField = NaN;
end
if ~isnan(pert_placeField)
pert_positive_t = pert_positive_t + 1;
end
end
if pertAnaInputStruct.treshType == "percent"
pert_percPositive = (pert_positive_t * 100) / pertNumTrials;
end
if pert_percPositive >= pertAnaInputStruct.filter_minTrials
if ~flag_hold_pert
flag_hold_pert = true;
end
slice = perturbZScores(n,xUp:xDown-1,a,c);
pertAbove(n,xUp:xDown-1,a,c) = slice;
pertLeftBorders.(neuron).(contString).(acqFieldName) = [pertLeftBorders.(neuron).(contString).(acqFieldName);xUp];
pertRightBorders.(neuron).(contString).(acqFieldName) = [pertRightBorders.(neuron).(contString).(acqFieldName);xDown-1];
pertSegments(n,a,c) = pertSegments(n,a,c) + 1;
end
end
end
end
if b == pertAnaInputStruct.lastBin - pertAnaInputStruct.sizeSurround
if flag_pertUp
if ~flag_hold_pert
flag_hold_pert = true;
end
xDown = b;
slice = perturbZScores(n,xUp:xDown,a,c);
pertAbove(n,xUp:xDown,a,c) = slice;
pertLeftBorders.(neuron).(contString).(acqFieldName) = [pertLeftBorders.(neuron).(contString).(acqFieldName);xUp];
pertRightBorders.(neuron).(contString).(acqFieldName) = [pertRightBorders.(neuron).(contString).(acqFieldName);xDown-1];
pertSegments(n,a,c) = pertSegments(n,a,c) + 1;
flag_pertUp = false;
end
end
end
end
end
end
end
end
end
end
filename = 'shuffles_significant_segments';
save([pertAnaInputStruct.outpath, filename],'prePertAbove','pertAbove','prePertSegments','pertSegments','prePertLeftBorders','prePertRightBorders','pertLeftBorders','pertRightBorders')