Skip to content

Commit 6a9b584

Browse files
committed
concat position, veloc, viewangle and similar vectors for all trials
1 parent 198cf1f commit 6a9b584

File tree

7 files changed

+54
-17
lines changed

7 files changed

+54
-17
lines changed

diamond-maze-behavior/calcDiamondMetricsBySess.m

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@
1111
disp(['Calculating session metrics for ' animalID num2str(index(1)) ' ' num2str(index(2)) ' ' num2str(index(3))]);
1212

1313
if ~exist(filename) || makenewfiles
14+
%% concatenate trial position, velocity, and viewAngle data
15+
concatTrialData = concatTrialBehavior(trialdata,sessdata.params.trainingtype)
16+
fnamesBehavior = fieldnames(concatTrialData);
17+
for fieldIdx = 1:length(fnamesBehavior)
18+
behaviorDataDiamondBySess.(fnamesBehavior{fieldIdx}) = concatTrialData.(fnamesBehavior{fieldIdx});
19+
end
20+
1421
%% concatenate trial outputs
15-
concatTrialData = concatTrialOutcomes(trialdata,sessdata.params.trainingtype);
16-
fnamesOutcomes = fieldnames(concatTrialData);
22+
concatTrialResults = concatTrialOutcomes(trialdata,sessdata.params.trainingtype);
23+
fnamesOutcomes = fieldnames(concatTrialResults);
1724
for fieldIdx = 1:length(fnamesOutcomes)
18-
behaviorDataDiamondBySess.(fnamesOutcomes{fieldIdx}) = concatTrialData.(fnamesOutcomes{fieldIdx});
25+
behaviorDataDiamondBySess.(fnamesOutcomes{fieldIdx}) = concatTrialResults.(fnamesOutcomes{fieldIdx});
1926
end
2027

2128
%% get percent correct

diamond-maze-behavior/calcSessionPerformance.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@
4545
for typeIdx = 1:length(trialTypes)
4646
trialsSinceCorrect = [];
4747
correctTrials = find(output.(['sessOutcomes' trialTypes{typeIdx}]) == 1);
48-
incorrectIntervals = [correctTrials, [correctTrials(2:end)-1; length(output.(['sessOutcomes' trialTypes{typeIdx}]))]];
4948
if ~isempty(correctTrials)
49+
incorrectIntervals = [correctTrials, [correctTrials(2:end)-1; length(output.(['sessOutcomes' trialTypes{typeIdx}]))]];
50+
if incorrectIntervals(1,1) ~= 1 %if the intervals don't start at the first trial
51+
incorrectIntervals = [1, incorrectIntervals(1,1)-1; incorrectIntervals];
52+
end
5053
for i = 1:size(incorrectIntervals,1)
5154
startToEnd = incorrectIntervals(i,:);
5255
countsSinceLast = [startToEnd(1):startToEnd(2)]-startToEnd(1);

diamond-maze-behavior/concatDiamondMazeSessions.m

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,38 @@
1616
for fieldIdx = 1:length(fnamesAll)
1717
allsessdata(animals(anIdx)).(track).(fnamesAll{fieldIdx}) = [];
1818
end
19-
19+
2020
%loop through sessions and concatenate data
2121
sesscounter = 1; %keep track of how many sessions on each track there are
2222
for sessIdx = 1:size(inclsess,1)
2323
%initialize variabls
2424
sessindex = indices.behaviorindex(inclsess(sessIdx),:);
2525
sessdata = behaviordata.bySession{sessindex(1)}{sessindex(2)}{sessindex(3)};
2626
trialdata = behaviordata.byTrial{sessindex(1)}{sessindex(2)}{sessindex(3)};
27-
27+
2828
%hacky way to get choice 1 side for now bc I was dumb and forgot to include it in the raw data structure
2929
if sessindex(2) > 190922 && sessindex(2) < 191030
3030
sessdata.trainingtype = 'choice1side_short';
3131
end
3232

3333
if strcmp(sessdata.trainingtype,track)
34+
35+
%combine all the fields where there is one value per trial/session
3436
for fieldIdx = 1:length(fnames)
3537
if isfield(sessdata, fnamesAll{fieldIdx})
3638
allsessdata(animals(anIdx)).(track).(fnamesAll{fieldIdx}) = [allsessdata(animals(anIdx)).(track).(fnamesAll{fieldIdx}); sessdata.(fnamesAll{fieldIdx})];
3739
end
3840
end
39-
41+
42+
%combine fields where there are multiple values per trial (ex. viewAngle, positionX, positionY)
43+
44+
45+
4046
%sessinfo structure so you can index into trials easily
4147
sessInfo = [repmat([sessindex(1:3), sesscounter],sessdata.numTrialsAll,1), [1:sessdata.numTrialsAll]'];
42-
allsessdata(animals(anIdx)).(track).sessInfo = [allsessdata(animals(anIdx)).(track).sessInfo; sessInfo];
48+
allsessdata(animals(anIdx)).(track).sessInfo = [allsessdata(animals(anIdx)).(track).sessInfo; sessInfo];
4349
sesscounter = sesscounter + 1;
4450
end
4551
end
4652
end
47-
end
53+
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function output = concatTrialBehavior(trialdata,tracktype)
2+
%SP 191121
3+
% this function concatenate data from trials like position, view angle, etc.
4+
5+
%% get variables to concatenate
6+
fnames = fieldnames(trialdata{1});
7+
counter = 1;
8+
for fieldIdx = 1:length(fnames)
9+
if size(trialdata{1}.(fnames{fieldIdx}),2) == size(trialdata{1}.time,2) %checking which fieldnames are behavior data vectors
10+
fnames2concat{counter} = fnames{fieldIdx};
11+
counter = counter + 1;
12+
end
13+
end
14+
15+
%% loop through trials to concatenate data
16+
trialcounter = 1; trialInfo = [];
17+
for trialIdx = 1:size(trialdata,2)
18+
for fieldIdx = 1:length(fnames2concat)
19+
output.(fnames{fieldIdx}){trialcounter} = trialdata{trialIdx}.(fnames{fieldIdx}); %change data structure so will be able to concat sessions
20+
end
21+
end

diamond-maze-behavior/concatTrialOutcomes.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
for trialIdx = 1:size(trialdata,2)
1212
%% get info from trialdata structure
1313
%trial duration
14-
dur = trialdata{trialIdx}.trialdur;
14+
dur = trialdata{trialIdx}.trialdurRaw;
1515

1616
% get start and reward locations
1717
%finds what the directions/locations are and map to number (ie,1 = north, 2 = east, 3 = south, 4 = west (like a compass lol))

diamond-maze-behavior/plotContinuousAltPerformance.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121

2222
%% plot percent correct trials for each session
2323
trackdata.trialsSinceCorrectAll
24-
plotDiamondTrackMetricsBySession(trackdata,animal,track,dirs,plotInfo,'perCorrect');
25-
plotDiamondTrackMetricsBySession(trackdata,animal,track,dirs,plotInfo,'perIncorrect');
26-
plotDiamondTrackMetricsBySession(trackdata,animal,track,dirs,plotInfo,'numCorrect');
27-
plotDiamondTrackMetricsBySession(trackdata,animal,track,dirs,plotInfo,'numTrials');
24+
% plotDiamondTrackMetricsBySession(trackdata,animal,track,dirs,plotInfo,'perCorrect');
25+
% plotDiamondTrackMetricsBySession(trackdata,animal,track,dirs,plotInfo,'perIncorrect');
26+
% plotDiamondTrackMetricsBySession(trackdata,animal,track,dirs,plotInfo,'numCorrect');
27+
% plotDiamondTrackMetricsBySession(trackdata,animal,track,dirs,plotInfo,'numTrials');
2828

2929
end
3030

diamond-maze-behavior/resampleDiamondMazeTrials.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
end
1515

1616
%sets time window for resampling to constant sampling rate (in time)
17-
newTrialSampSize = round(trialdata.trialdur/params.constSampRateTime); %find out how many samples should be in new vect
17+
newTrialSampSize = round(trialdata.trialdurRaw/params.constSampRateTime); %find out how many samples should be in new vect
1818
newTimes = trialdata.timeRaw(1):params.constSampRateTime:((newTrialSampSize*params.constSampRateTime)+trialdata.timeRaw(1)); %get times from start to end with const time window
1919
for i = 1:length(fnames2resample)
2020
resampledVect = interp1(trialdata.timeRaw,trialdata.([fnames2resample{i} 'Raw']),newTimes,'linear','extrap'); %added extrap to get rid of accidental nan values in the data
@@ -33,11 +33,11 @@
3333
startingValue = trialdata.([fnames2findsteppoints{i} 'Raw'])(1);
3434
endingValue = trialdata.([fnames2findsteppoints{i} 'Raw'])(end);
3535
oldValues = [startingValue; trialdata.([fnames2findsteppoints{i} 'Raw'])(oldInds); endingValue]; %gets values at each of the indices for stepping through
36-
36+
3737
%make new vector with step functions with step occurring at each ind
3838
output.(fnames2findsteppoints{i}) = zeros(size(output.(fnames2findsteppoints{i})))+startingValue;
3939
for stepIdx = 1:length(oldValues(2:end-1)) %only include value where switch occurred, starting value was already initialized
40-
40+
4141
if stepIdx == length(oldValues(2:end-1))
4242
inds2change = newInds(stepIdx):length(output.(fnames2findsteppoints{i})); %if last indics then go to end with final value
4343
else

0 commit comments

Comments
 (0)