This commit is contained in:
Jan-Bernard Marsman
2018-06-12 14:49:55 +02:00
parent 1edacb997d
commit d2cf032fab
230 changed files with 3192360 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
classdef PDSubject
properties
index
sessions
settings
name
date
time
covariates
end
methods
function[obj] = PDSubject(varargin)
if nargin ==0
display('Select data for this subject:');
files = cellstr(uigetfile({'*.ASC;*.asc', 'Converted Eyelink text files (*.ASC)';...
'*.EDF;*.edf', 'Original Eyelink data files (*.EDF)'}, ...
'Select data for this subject', 'MultiSelect', 'on'));
for i = 1:length(files)
session = PDSession(files{i});
obj.sessions = session;
end
end
if nargin == 1
display(sprintf('Selecting sessions based on all files in: %s', varargin{1}));
obj.sessions = obj.findAllfiles(varargin{1});
if ~isempty(obj.index)
obj.name = sprintf('Subject %d', obj.index );
else
[folder topmostfolder] = fileparts(varargin{1});
obj.name = topmostfolder;
end
end
end
end
end

View File

@@ -0,0 +1,53 @@
function[sessions] = findAllfiles(obj, folder)
cd(folder);
files = dir;
i=1;
sessions = PDSession(''); % create empty session
for s =1:length(files)
if (strcmp(files(s).name, '.') || strcmp(files(s).name, '..'))
continue;
end
if files(s).isdir
new_sessions = obj.findAllfiles([folder filesep files(s).name]);
for i = 1:length(new_sessions)
if ((length(sessions) ==1) && isempty(sessions(1).datafile))
sessions(length(sessions)) = new_sessions(i);
else
sessions(i + length(sessions)) = new_sessions(i);
end
end
else
[base file ext] = fileparts(files(s).name);
if strcmp(lower(ext), '.asc')
display(sprintf('\tFile found for Subject: %s', file));
if ((length(sessions) ==1) && isempty(sessions(1).datafile))
sessions(1) = PDSession([folder filesep files(s).name]);
else
sessions(end+1) = PDSession([folder filesep files(s).name]);
end
i=i+1;
end
if strcmp(lower(ext), '.gazedata')
display(sprintf('\tFile found for Subject: %s', file));
if ((length(sessions) ==1) && isempty(sessions(1).datafile))
sessions(1) = PDSession([folder filesep files(s).name]);
else
sessions(end+1) = PDSession([folder filesep files(s).name]);
end
i=i+1;
end
end
end
%% do not return empty objects
if ((length(sessions) ==1) && isempty(sessions(1).datafile))
sessions = [];
end

View File

@@ -0,0 +1,10 @@
function[mats trial_ind] = getTrialMatrices(objs, varargin)
%% for all subjects, get all trials
for i = 1:length(objs)
for s = 1:length(objs(i).sessions);
[mats{i,s} trial_ind{i,s}] = objs(i).sessions(s).getTrialMatrix(varargin);
end
end

View File

@@ -0,0 +1,9 @@
function[objs] = loadData(objs)
for i = 1:length(objs)
for s = 1:length(objs(i).sessions)
objs(i).sessions(s) = objs(i).sessions(s).loadData();
end
end

View File

@@ -0,0 +1,6 @@
function[obj] = preprocess(obj, settings)
for s = 1:length(obj.sessions)
obj.sessions(s) = obj.sessions(s).preprocess(settings);
end
end

View File

@@ -0,0 +1,14 @@
function[objs] = rebuild(objs, varargin)
p = inputParser;
addOptional(p, 'ForcePrecursorLabels',0);
p.parse(varargin);
params = p.Results;
for o = 1:length(objs)
for s = 1:length(objs(o).sessions);
objs(o).sessions(s) = objs(o).sessions(s).rebuild(params);
end
end

View File

@@ -0,0 +1,5 @@
function[obj] = removeDuplicateLabels(obj)
for s = 1:length(obj.sessions)
obj.sessions(s) = obj.sessions(s).removeDuplicateLabels;
end

View File

@@ -0,0 +1,8 @@
function[objs] = setFailSafePatternRelativeToPattern(objs, relativeTotype,type, timing)
%% more info should be written here
for o = 1:length(objs)
for s = 1:length(objs(o).sessions)
objs(o).sessions(s) = objs(o).sessions(s).setFailSafePatternRelativeToPattern(relativeTotype,type,timing);
end
end

View File

@@ -0,0 +1,12 @@
function[objs] = setLabel(objs, type, pattern)
if nargin ==2
pattern = type;
end
for o = 1:length(objs)
for s = 1:length(objs(o).sessions)
% ignore type for now
objs(o).sessions(s) = objs(o).sessions(s).setLabel(pattern);
end
end

View File

@@ -0,0 +1,12 @@
function[objs] = setLabelRelativeToLabel(objs, target, pattern, time)
if nargin ==2
pattern = type;
end
for o = 1:length(objs)
for s = 1:length(objs(o).sessions)
% ignore type for now
objs(o).sessions(s) = objs(o).sessions(s).setLabelRelativeToLabel(type, pattern);
end
end

View File

@@ -0,0 +1,8 @@
function[objs] = setPattern(objs, type, pattern)
for o = 1:length(objs)
for s = 1:length(objs(o).sessions)
objs(o).sessions(s) = objs(o).sessions(s).setPattern(type, pattern);
end
end

View File

@@ -0,0 +1,8 @@
function[objs] = setPatternMulti(objs, type, pattern)
for o = 1:length(objs)
for s = 1:length(objs(o).sessions)
objs(o).sessions(s) = objs(o).sessions(s).setPatternMulti(type, pattern);
end
end

View File

@@ -0,0 +1,8 @@
function[objs] = setPatternRelativeToPattern(objs, relativeTotype,type, timing)
%% more info should be written here
for o = 1:length(objs)
for s = 1:length(objs(o).sessions)
objs(o).sessions(s) = objs(o).sessions(s).setPatternRelativeToPattern(relativeTotype,type,timing);
end
end

View File

@@ -0,0 +1,7 @@
function[obj] = setSettings(obj, settings)
obj.settings = settings;
for s = 1:length(obj.sessions)
obj.sessions(s) = obj.sessions(s).setSettings(settings);
end

View File

@@ -0,0 +1,30 @@
function[] = summary(obj, level)
%% summary of PDSubject at a certain level
%% level 0 : global info
%% level 1 : more detail
if nargin ==1
level =0;
end
display(sprintf('Summary for %d subjects:', length(obj)));
display(repmat('_',1,50));
for s = 1:length(obj)
display(sprintf('Subject: %s (%d sessions)', obj(s).name, length(obj(s).sessions)));
for p = 1:length(obj(s).sessions)
display(sprintf('\to) Session %d: %d trial(s)', p, length(obj(s).sessions(p).trials)));
if (level > 0)
for t = 1:length(obj(s).sessions(p).trials)
display(sprintf('\t\t*) trial %3d :\t%10d samples', t, length(obj(s).sessions(p).trials(t).data.uncorrected.raw)));
end
end
end
end

View File

@@ -0,0 +1,16 @@
function[] = summary(obj)
display(sprintf('Summary for %d subjects:', length(obj)));
display(repmat('_',1,50));
for s = 1:length(obj)
display(sprintf('\tSubject: %s', obj(s).name));
display(sprintf('\t%d sessions:', length(obj(s).sessions)));
for p = 1:length(obj(s).sessions)
display(sprintf('\tSession %d: %d trial(s)', p, length(obj(s).sessions(p).trials)));
end
end