Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moriel #12

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 0 additions & 158 deletions bento/annotations\color_profiles.txt

This file was deleted.

3 changes: 2 additions & 1 deletion bento/data_builder/util/loadAnnotFileObserver.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function [annot, maxTime] = loadAnnotFileObserver(cleantext, fr)


cleantext = cellfun(@(x) regexprep(x,{'\"','(',')'},''), cleantext, 'uniformoutput',false);

headers = split(cleantext{1},';');
Expand All @@ -24,7 +25,7 @@
flag = 1;
elseif strcmpi(event,'state stop')
flag = 2;
elseif strcmpi(event,'state point') % not sure what this means.
elseif strcmpi(event,'state point') % start==stop
continue
else % does this ever happen??
flag = 0;
Expand Down
41 changes: 41 additions & 0 deletions bento/data_builder/util/loadAnnotFileXls.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function [annot,maxTime,hotkeys,FR] = loadAnnotFileXls(fname,defaultFR, tmin,tmax)
%
% (C) Ann Kennedy, 2019
% California Institute of Technology
% Licensing: https://github.com/annkennedy/bento/blob/master/LICENSE.txt

if(nargin<2)
defaultFR = 1000;
elseif(nargin<3)
tmin = 1;
tmax = inf;
elseif(isstr(tmin))
tmin = str2num(tmin);
tmax = str2num(tmax);
end
FR = nan; %framerate not usually specified in these kinds of files, return nan to let the gui decide.

fid = fopen(fname);
if(fid==-1)
keyboard
end

[~,sheetlist] = xlsfinfo(fname);
fid = sheetlist{1}; % let's assume there's just one sheet for now- go back and fix this later
[~,~,M] = xlsread(fname,fid);

hotkeys=struct();

if(any(strcmpi(M(1,:),'Event_type'))) % it's probably an Ethovision Observer log
[annot,maxTime] = loadAnnotSheetObserver(M, defaultFR); % need to add tmin/tmax support
FR = defaultFR;
elseif(any(strcmpi(M(1,:), 'Sinuosity'))) % it's probably DeepSqueak
if defaultFR<1024
defaultFR = 1024;
end
[annot,maxTime] = loadAnnotSheetDeepSqueak(M, defaultFR); % need to add tmin/tmax support
FR = defaultFR;
else
annot=[];maxTime=[];hotkeys=struct();
end
end
47 changes: 47 additions & 0 deletions bento/data_builder/util/loadAnnotSheetDeepSqueak.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function [annot, maxTime] = loadAnnotSheetDeepSqueak(M, defaultFR)

headers = M(1,:);
label_index = find(strcmpi(headers,'Label'));
accepted_index = find(strcmpi(headers,'Accepted'));
time_start = find(strcmpi(headers,'Begin Time (s)')|strcmpi(headers,'BeginTime_s_'));
time_stop = find(strcmpi(headers,'End Time (s)')|strcmpi(headers,'EndTime_s_'));
cluster_index = find(strcmpi(headers,'cluster'));

if length([label_index accepted_index time_start time_stop])~=4
disp('something went wrong- I couldn''t find fields Label, Accepted, Begin Time, and/or End Time.');
return
end

annot.Ch1 = [];
tstop = 0;
for i=2:length(M)
if (isstr(M{i,accepted_index}) && ~strcmpi(M{i,accepted_index},'TRUE')) || ~M{i,accepted_index}
continue;
end

if isempty(cluster_index)
beh = strrep(M{i, label_index},' ','_');
else
beh = strrep(M{i, label_index},' ','_');
beh = [beh '_' num2str(M{i,cluster_index})];
end
beh = regexprep(beh, '[^\w]', ''); % remove bad characters
if ~isfield(annot.Ch1,beh)
annot.Ch1.(beh) = [];
end
tstart = ceil(M{i, time_start}*defaultFR);
tstop = ceil(M{i, time_stop}*defaultFR);
annot.Ch1.(beh)(end+1,:) = [tstart tstop];
end
maxTime = tstop;











54 changes: 54 additions & 0 deletions bento/data_builder/util/loadAnnotSheetObserver.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function [annot, maxTime] = loadAnnotSheetObserver(M, defaultFR)

headers = M(1,:);
behavior_name_index = find(strcmpi(headers,'behavior'));
event_type_index = find(strcmpi(headers,'event_type'));
timestamp_index = find(strcmpi(headers,'Time_Relative_sf'));

if length([behavior_name_index event_type_index timestamp_index])~=3
disp('something went wrong- I couldn''t find fields Behavior, Event_Type, and/or Time_Relative_sf.');
return
end

annot.Ch1 = [];
counts=[];
for i=2:length(M)
event = M{i,event_type_index};
if isnan(event)
continue;
end
if strcmpi(event,'state start')
flag = 1;
elseif strcmpi(event,'state stop')
flag = 2;
elseif strcmpi(event,'state point') % start==stop
continue
else % does this ever happen??
flag = 0;
keyboard
end

beh = strrep(M{i, behavior_name_index},' ','_');
beh = regexprep(beh, '[^\w]', ''); % remove bad characters
time = ceil(M{i, timestamp_index}*defaultFR);
if ~isfield(annot.Ch1,beh)
annot.Ch1.(beh) = [];
counts.(beh) = 0;
end
if flag==1
counts.(beh) = counts.(beh)+1;
end
annot.Ch1.(beh)(counts.(beh),flag) = time;
end
maxTime = time;











2 changes: 1 addition & 1 deletion bento/data_builder/util/loadAnnotSheetTxt.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
end
end
if((vals(2)+tmin)>=winStart && (vals(1)+tmax)<=winStop) %if this annotation is within the range we're loading
annot.(ch).(beh)(end+1,:) = min(max(vals(1:2)-winStart,1),winStop-winStart+1);
annot.(ch).(beh)(end+1,:) = min(max(vals(1:2)-winStart+1-tmin+1,0),winStop-winStart+1);
if(vals(2)-tmin+1 > tmax)
tmax = vals(2)-tmin+2;
end
Expand Down
Loading