Skip to content

Commit

Permalink
adding preference option for annot timestamp format
Browse files Browse the repository at this point in the history
  • Loading branch information
annkennedy committed Jun 24, 2021
1 parent 4590c68 commit b228777
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 117 deletions.
20 changes: 20 additions & 0 deletions bento/annotations/setAnnotSaveType.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function setAnnotSaveType(source)
%
% (C) Ann Kennedy, 2019
% California Institute of Technology
% Licensing: https://github.com/annkennedy/bento/blob/master/LICENSE.txt



gui=guidata(source);
answer = questdlg('Units for saved annotations:', ...
'Set annotation save format', ...
'Frames','Time (seconds)','Frames');

switch answer
case 'Frames'
gui.annot.saveAsTime = false;
otherwise
gui.annot.saveAsTime = true;
end
guidata(gui.h0,gui);
2 changes: 1 addition & 1 deletion bento/gui/setActiveMouse.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
case 'Yes'
gui.allData(mOld).(sessOld)(trOld).annot = gui.data.annot;
suggestedName = ['mouse' num2str(mOld) '_' sessOld '_' num2str(trOld,'%03d') '.annot'];
saveAnnotSheetTxt(gui.data.io.movie.fid,gui.data,suggestedName);
saveAnnotSheetTxt(gui.data.io.movie.fid,gui.data,suggestedName,0,gui.annot.saveAsTime);
gui.annot.modified = 0;
case 'No'
gui.allData(mOld).(sessOld)(trOld).annot = gui.data.annot;
Expand Down
2 changes: 1 addition & 1 deletion bento/popups/edit annotations/Manager_applyLabelChanges.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Manager_applyLabelChanges(source,~)

dat = data(m).(sess)(trial);
suggestedName = ['mouse' num2str(m) '_' sess '_' num2str(trial,'%03d') '.annot'];
saveAnnotSheetTxt(gui.data.io.movie.fid,dat,suggestedName);
saveAnnotSheetTxt(gui.data.io.movie.fid,dat,suggestedName,0,gui.annot.saveAsTime);
end
gui = setActiveMouse(gui,m,sess,trial,0);
guidata(gui.h0,gui);
16 changes: 8 additions & 8 deletions bento/saving data/makeBehaviorSummary.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function [M,channelSummary] = makeBehaviorSummary(channel,tmin,tmax,FR,frameFlag)
function [M,channelSummary] = makeBehaviorSummary(channel,tmin,tmax,FR,saveAsTime)
%
% (C) Ann Kennedy, 2019
% California Institute of Technology
% Licensing: https://github.com/annkennedy/bento/blob/master/LICENSE.txt

% set a default value of frameFlag
if(~exist('frameFlag','var'))
frameFlag = false;
% set a default value of saveAsTime
if(~exist('saveAsTime','var'))
saveAsTime = false;
end

M = {};
Expand All @@ -20,12 +20,12 @@
M{1,count*3-2} = fields{f};
M(2,(count-1)*3+(1:3)) = {'Start','Stop','Duration'};

if(frameFlag) % save in frames
M(2+(1:size(channel.(fields{f}),1)),count*3-[2 1]) = num2cell(channel.(fields{f}));
delta = 1;
else % save in seconds (default)
if(saveAsTime) % save in seconds
M(2+(1:size(channel.(fields{f}),1)),count*3-[2 1]) = num2cell(channel.(fields{f})/FR);
delta = 1/FR;
else % save in frames (default)
M(2+(1:size(channel.(fields{f}),1)),count*3-[2 1]) = num2cell(channel.(fields{f}));
delta = 1;
end
delta = delta + channel.(fields{f})(:,2) - channel.(fields{f})(:,1);
M(2+(1:size(channel.(fields{f}),1)),count*3) = num2cell(delta);
Expand Down
4 changes: 2 additions & 2 deletions bento/saving data/quickSave.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ function quickSave(source,~)
suggestedName = ['mouse' num2str(m) '_' sess '_' num2str(tr,'%03d') '.annot'];
end
if(isfield(trial.io.movie,'fid')) %save the file too
fname = saveAnnotSheetTxt(trial.io.movie.fid,gui.data,suggestedName,0,0);
fname = saveAnnotSheetTxt(trial.io.movie.fid,gui.data,suggestedName,0,gui.annot.saveAsTime);
else
fname = saveAnnotSheetTxt([],gui.data,suggestedName,0,0);
fname = saveAnnotSheetTxt([],gui.data,suggestedName,0,gui.annot.saveAsTime);
end

gui.annot.modified = 0;
Expand Down
18 changes: 9 additions & 9 deletions bento/saving data/saveAnnot.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function saveAnnot(filename,annot,tmin,tmax,FR,movieNames,stim,frameFlag)
function saveAnnot(filename,annot,tmin,tmax,FR,movieNames,stim,saveAsTime)
%
% (C) Ann Kennedy, 2019
% California Institute of Technology
% Licensing: https://github.com/annkennedy/bento/blob/master/LICENSE.txt

% set a default value of frameFlag
if(~exist('frameFlag','var'))
frameFlag = false;
if(~exist('saveAsTime','var'))
saveAsTime = false;
end

fid = fopen(filename,'w');
Expand Down Expand Up @@ -49,17 +49,17 @@ function saveAnnot(filename,annot,tmin,tmax,FR,movieNames,stim,frameFlag)
for c = 1:length(channels)
Ch = channels{c};

[M,summaries.(Ch)] = makeBehaviorSummary(annot.(Ch),tmin,tmax,FR,frameFlag);
[M,summaries.(Ch)] = makeBehaviorSummary(annot.(Ch),tmin,tmax,FR,saveAsTime);
if(isempty(M))
M{1,1} = '';
continue;
end
%convert from frames to times, to avoid future tragedies
if(frameFlag)
if(~any(cellfun(@any,cellfun(@(x)rem(x,1),{M{:}},'uniformOutput',false))))
M(cellfun(@isnumeric,M)) = cellfun(@(x) x/FR,M(cellfun(@isnumeric,M)),'uniformoutput',false);
end
end
% if(saveAsTime)
% if(~any(cellfun(@any,cellfun(@(x)rem(x,1),{M{:}},'uniformOutput',false))))
% M(cellfun(@isnumeric,M)) = cellfun(@(x) x/FR,M(cellfun(@isnumeric,M)),'uniformoutput',false);
% end
% end

fprintf(fid,'%s----------\n',channels{c});
for beh = 1:3:size(M,2)
Expand Down
90 changes: 0 additions & 90 deletions bento/saving data/saveAnnotSheet.m

This file was deleted.

8 changes: 4 additions & 4 deletions bento/saving data/saveAnnotSheetTxt.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function filename = saveAnnotSheetTxt(movieNames,trial,suggestedName,promptOverride,frameFlag)
function filename = saveAnnotSheetTxt(movieNames,trial,suggestedName,promptOverride,saveAsTime)
%
% (C) Ann Kennedy, 2019
% California Institute of Technology
Expand Down Expand Up @@ -33,8 +33,8 @@
end

% set a default value of frameFlag
if(~exist('frameFlag','var'))
frameFlag = false;
if(~exist('saveAsTime','var'))
saveAsTime = false;
end


Expand All @@ -49,7 +49,7 @@

annot = trial.annot;
stim = trial.stim;
saveAnnot(filename,annot,tmin,tmax,FR,movieNames,stim,frameFlag);
saveAnnot(filename,annot,tmin,tmax,FR,movieNames,stim,saveAsTime);



2 changes: 1 addition & 1 deletion bento/scripts/fixAnnotFromFront.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function fixAnnotFromFront(pth)
disp(' saving...');
fname = strrep(fname,'.annot','_TS.annot');
fname = strrep(fname,'.txt','_TS.annot');
saveAnnot(fname,annot,tmin,tmax,FR,{movieNames},stim,0);
saveAnnot(fname,annot,tmin,tmax,FR,{movieNames},stim,0,1);
disp(' done!');
end

Expand Down
2 changes: 1 addition & 1 deletion bento/scripts/fixAnnotFromTop.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function fixAnnotFromTop(pth)
disp(' saving...');
fname = strrep(fname,'.annot','_TS.annot');
fname = strrep(fname,'.txt','_TS.annot');
saveAnnot(fname,annot,tmin,tmax,FR,{movieNames},stim,0);
saveAnnot(fname,annot,tmin,tmax,FR,{movieNames},stim,0, 1);
disp(' done!');
end

Expand Down
1 change: 1 addition & 0 deletions bento/startup/drawAnnot.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
annot.activeBeh = '';
annot.modified = 0;
annot.highlighting = 0;
annot.saveAsTime = false;
annot.prev = [];
annot.bhv = struct();
annot.show = struct();
Expand Down
2 changes: 2 additions & 0 deletions bento/startup/menu_setup.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'>Set annotation &hotkeys^h',...
'>Fix annot timing',...
'>Change annot framerate',...
'>Preferences...',...
'&Display',...
'>Select &traces to show^t',...
'>Select a&nnotations to show^n',...
Expand Down Expand Up @@ -58,6 +59,7 @@
'setAnnotHotkeys(gcf,[])',...
'bumpAnnot(gcf)',...
'launchAnnoChanger(gcf)',...
'setAnnotSaveType(gcf)',...
'','pickUnits(gcf)','pickAnnot(gcf)',...
'','setScatterDims(gcf)',...
'clearScatterDims(gcf)',...
Expand Down

0 comments on commit b228777

Please sign in to comment.