Skip to content

Commit

Permalink
New event import functionality: You can now either load new event mar…
Browse files Browse the repository at this point in the history
…kers from a text file and (1) delete the existing ones, (2) keep the existing ones, (3) recode the existing ones.
  • Loading branch information
MatBenedek authored and tstenner committed Sep 6, 2015
1 parent a945c4e commit d897ca6
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Ledalab.m
Expand Up @@ -7,7 +7,7 @@ function Ledalab(varargin)
global leda2

leda2.intern.name = 'Ledalab';
leda2.intern.version = 3.46;
leda2.intern.version = 3.47;
versiontxt = num2str(leda2.intern.version,'%3.2f');
leda2.intern.versiontxt = ['V',versiontxt(1:3),'.',versiontxt(4:end)];
leda2.intern.version_datestr = '2014-05-20';
Expand Down
64 changes: 58 additions & 6 deletions What's new.txt
@@ -1,7 +1,59 @@
What's new in Ledalab V.3.4.6?
What's new in Ledalab V.3.4.7?

- Biotrace import function now supports UK format in addition to DE version.
- Butterworth-filter function extended (lower cutoff and order can be set to create a low-pass filter)
- Filter function now included to batchmode analysis
- PhasicMax score (i.e., maximum phasic driver value within response window) added to event-related activation scores
- Minor debugging of graphic functions

--------------------------------------------------------------------------
NEW EVENT IMPORT FUNCTIONS

Changed files:
- import_eventdata.m (infotype switch modified)
- import_eventinfo.m (infotype switch modified)
- ledagui.m (now refers to getevents.m by default)

Added files:
- getevents.m (new event marker read function for import_eventdata.m and import_eventinfo.m)
- import_addeventdata.m (new function to add newly imported event markers while keeping the old ones)



Changed functionality for importing event markers:


Option 1; File -> Import Events -> Load New Event Markers (and DELETE exisiting ones):
To load new markers from a text file and and DELETE the already existing ones.

You need a text-file with tab-separated columns and titles in the first row. You can use additional user-specified columns if you like and give them arbitrary titles.
You need at least the columns 'time' and 'nid', the rest is optional.
- 'time' --> time of event relative to first sample point in seconds (numeric)
- 'nid' --> numeric ID of the marker indicating the experimental condition (integer)
- 'name' --> name of the marker (string)


Option 2; File -> Import Events -> Load New Event Markers (and KEEP exisiting ones):
To load new markers from a text file and KEEP the already existing ones.

You need a text-file with tab-separated columns and titles in the first row. You can use additional user-specified columns if you like and give them arbitrary titles.
You need at least the columns 'time' and 'nid', the rest is optional.
- 'time' --> time of event relative to first sample point in seconds (numeric)
- 'nid' --> numeric ID of the marker indicating the experimental condition (integer)
- 'name' --> name of the marker (string)


Oprtion 3: File -> Import Events -> Recode Existing Events Markers
To recode existing markers from a text file with the same number of rows as there are existing markers.

You need a text-file with tab-separated columns and titles in the first row. You can use additional user-specified columns if you like and give them arbitrary titles.
You need at least one of these columns.
- 'time' --> time of event relative to first sample point in seconds (numeric)
- 'nid' --> ID of the marker indicating the experimental condition (integer)
- 'name' --> name of the marker (string)



--------------------------------------------------------------------------
BUG IN DATA IMPORT FUNCTION

Changed files:
- import_data.m (infotype switch modified)

line54
% timeoffset = data.timeoff; %JG 27.9.2012
38 changes: 38 additions & 0 deletions main/import/getevents.m
@@ -0,0 +1,38 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% new event marker read function for import_eventdata.m and import_eventinfo.m
% by Til Ole Bergmann, bergmann@psychologie.uni-kiel.de
% last edit 2014-06-13 by TOB
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function event = getevents(fullpath)

% read in text file with unknown number of columns into cell array
fid = fopen(fullpath);
firstLine = fgetl(fid);
fclose(fid);
numFields = length(strfind(firstLine,sprintf('\t'))) + 1;
formatString = repmat('%s',1,numFields);
fid = fopen(fullpath);
C = textscan(fid, formatString,'\t');
fclose(fid);

for ev = 1:size(C{1},1)-1 % starts in line 2 as first line contians header
for nf = 1:numFields
event(ev).userdata = [];
switch C{nf}{1}
case 'time'
event(ev).time = str2num(C{nf}{1+ev});
case 'nid'
event(ev).nid = str2num(C{nf}{1+ev});
if ~isfield(event(ev),'name')
event(ev).name = num2str(event(ev).nid);
end
case 'name'
event(ev).name = C{nf}{1+ev};
otherwise % user specific data will be stored in cell array
event(ev).userdata.(C{nf}{1}) = C{nf}{1+ev};
end
end
end


76 changes: 76 additions & 0 deletions main/import/import_addeventdata.m
@@ -0,0 +1,76 @@
function import_addeventdata(infotype)
global leda2

if ~leda2.file.open
add2log(0,'No open file',1,1,0,1,0,1)
return;
end

[filename, pathname] = uigetfile({'*.txt';'*.dat'},'Choose an event-data file');

if all(filename == 0) || all(pathname == 0) %Cancel
return
end


switch infotype
case 'default',
event = getevents([pathname, filename]);
case 'userdef',
event = getuserdefeventdata([pathname, filename]);
end


if ~isempty(event)
old_event = leda2.data.events.event; % copy old events
old_events_N = leda2.data.events.N; % copy number of old events
leda2.data.events.event = []; % clear events structure

N = length(event);
event_fields = fieldnames(event);

for ev = 1:N
if any(strcmp(event_fields, 'time'))
leda2.data.events.event(ev).time = event(ev).time;
end
if any(strcmp(event_fields, 'name'))
leda2.data.events.event(ev).name = event(ev).name;
end
if any(strcmp(event_fields, 'nid'))
leda2.data.events.event(ev).nid = event(ev).nid;
end
if any(strcmp(event_fields, 'userdata'))
leda2.data.events.event(ev).userdata = event(ev).userdata;
end
leda2.data.events.N = N; % get number of new events
end

new_event = leda2.data.events.event; % copy new events
leda2.data.events.event = []; % clear events structure


%% merge old and new events
% merge old and new marker structure array
M = [old_event, new_event];

% convert structure array to cell array
Mfields = fieldnames(M);
Mcell = struct2cell(M);
sz = size(Mcell);
Mcell = reshape(Mcell, sz(1), []); % convert to a matrix
Mcell = Mcell'; % Make each field a column

% sort
Mcell = sortrows(Mcell, 1); % Sort by first field "time"

% convert it back to a structure array:
Mcell = reshape(Mcell', sz); % put back into original cell array format
Msorted = cell2struct(Mcell, Mfields, 1); % convert to struct

% pass over new values to leda2.data.events
leda2.data.events.event = Msorted;
leda2.data.events.N = leda2.data.events.N + old_events_N;

plot_data;

end
2 changes: 1 addition & 1 deletion main/import/import_data.m
Expand Up @@ -52,7 +52,7 @@ function import_data(datatype, pathname, filename)
conductance = data.conductance;
time = data.time;
event = data.event;
timeoffset = data.timeoff; %JG 27.9.2012
% timeoffset = data.timeoff; %JG 27.9.2012

case 'text'
[time, conductance, event] = gettextdata(file);
Expand Down
4 changes: 3 additions & 1 deletion main/import/import_eventdata.m
Expand Up @@ -6,14 +6,16 @@ function import_eventdata(infotype)
return;
end

[filename, pathname] = uigetfile({'*.txt';'*.dat'},'Choose a Event-file');
[filename, pathname] = uigetfile({'*.txt';'*.dat'},'Choose an event-data file');

if all(filename == 0) || all(pathname == 0) %Cancel
return
end


switch infotype
case 'default',
event = getevents([pathname, filename]);
case 'userdef',
event = getuserdefeventdata([pathname, filename]);
end
Expand Down
6 changes: 4 additions & 2 deletions main/import/import_eventinfo.m
Expand Up @@ -2,14 +2,16 @@ function import_eventinfo(infotype)
global leda2


[filename, pathname] = uigetfile({'*.txt';'*.dat'},'Choose a Eventinfo-file');
[filename, pathname] = uigetfile({'*.txt';'*.dat'},'Choose an event-info file');

if all(filename == 0) || all(pathname == 0) %Cancel
return
end


switch infotype
case 'default',
event = getevents([pathname, filename]);
case 'userdef',
event = getuserdefeventinfo([pathname, filename]);
end
Expand Down Expand Up @@ -38,7 +40,7 @@ function import_eventinfo(infotype)

%plot updated event-names
for ev = 1:N
set(leda2.gui.rangeview.eventtxt(ev),'String',sprintf('%.1f: %s (%s)',leda2.data.events.event(ev).time, leda2.data.events.event(ev).name), num2str(leda2.data.events.event(ev).nid));
set(leda2.gui.rangeview.eventtxt(ev),'String',sprintf('%.1f: %s (%s)',leda2.data.events.event(ev).time, leda2.data.events.event(ev).name, num2str(leda2.data.events.event(ev).nid)));
end

end
5 changes: 3 additions & 2 deletions main/ledagui.m
Expand Up @@ -26,8 +26,9 @@
leda2.gui.menu.menu_1b14 = uimenu(leda2.gui.menu.menu_1b,'Label','User-defined Data','Callback','import_data(''userdef'');','Enable','off');

leda2.gui.menu.menu_1c = uimenu(leda2.gui.menu.menu_1,'Label','Import Events...'); %,'Accelerator','i'
leda2.gui.menu.menu_1c1 = uimenu(leda2.gui.menu.menu_1c,'Label','Event-Data [Time (Marker)]','Callback','import_eventdata(''userdef'')');
leda2.gui.menu.menu_1c2 = uimenu(leda2.gui.menu.menu_1c,'Label','User-defined Event-Labels','Callback','import_eventinfo(''userdef'')');
leda2.gui.menu.menu_1c1 = uimenu(leda2.gui.menu.menu_1c,'Label','Load New Event Markers (and DELETE exisiting ones)','Callback','import_eventdata(''default'')');
leda2.gui.menu.menu_1c1 = uimenu(leda2.gui.menu.menu_1c,'Label','Load New Event Markers (and KEEP exisiting ones)','Callback','import_addeventdata(''default'')');
leda2.gui.menu.menu_1c2 = uimenu(leda2.gui.menu.menu_1c,'Label','Recode Existing Event Markers','Callback','import_eventinfo(''default'')');
leda2.gui.menu.menu_1d = uimenu(leda2.gui.menu.menu_1,'Label','Export Data...');
leda2.gui.menu.menu_1d1 = uimenu(leda2.gui.menu.menu_1d,'Label','ASCII File','Callback','exportTextData');
leda2.gui.menu.menu_1e = uimenu(leda2.gui.menu.menu_1,'Label','Save','Callback','save_ledafile','Accelerator','s','Separator','on');
Expand Down

0 comments on commit d897ca6

Please sign in to comment.