Date: Mon, 24 Oct 2022 18:06:13 -0400
Subject: [PATCH 11/11] Improve docs
---
docs/src/concepts/conditions.md | 10 +-
docs/src/concepts/sources.md | 2 +-
matlab/TrialConditions.m | 197 ++++++++++++++++----------------
3 files changed, 107 insertions(+), 102 deletions(-)
diff --git a/docs/src/concepts/conditions.md b/docs/src/concepts/conditions.md
index 6c1c374..b1222f4 100644
--- a/docs/src/concepts/conditions.md
+++ b/docs/src/concepts/conditions.md
@@ -1,8 +1,8 @@
# TrialConditions
A `TrialConditions` is a [type
-[Julia]](../../julia-reference#DatasetManager.TrialConditions) or [class
-[MATLAB]](../../matlab-reference#TrialConditions) that describes the names and possible
+[Julia]](../../../julia-reference/#DatasetManager.TrialConditions) or [class
+[MATLAB]](../../../matlab-reference/#TrialConditions) that describes the names and possible
values for the experimental conditions (aka factors) and other characteristics (e.g. subject
ID, etc) which are needed to describe and recognize multiple sources as being
associated with a single, unique `Trial`.
@@ -21,7 +21,7 @@ Therefore `TrialConditions` is designed to be capable of describing such complex
**label**:
- 1. A value of a condition
+ 1. A value of a condition, aka a level of a factor
Example: `"control"` is a valid label for the condition "*group*"
@@ -40,6 +40,10 @@ The simplest datasets can be described by listing all valid labels for each cond
```
+```@setup conditions
+using DatasetManager
+```
+
```@repl conditions
labels = Dict(
:subject => ["1", "2", "3", "4", "5"],
diff --git a/docs/src/concepts/sources.md b/docs/src/concepts/sources.md
index 6e4b2b2..1b353eb 100644
--- a/docs/src/concepts/sources.md
+++ b/docs/src/concepts/sources.md
@@ -3,7 +3,7 @@
A `Source` is a [type [Julia]](/julia-reference.html#DatasetManager.Source) or [class
[MATLAB]](/matlab-reference.html#Source) that refers to the location of a source of data
(typically a path to a file). DatasetManager normally assumes that sources contain
-time-series data (e.g. in [`readsegment`](@ref), however this is not a requirement.
+time-series data (e.g. in [`readsegment`](@ref), however this is not a requirement).
Datasets often have more than one kind of source (e.g. if multiple systems were
used to collect different kinds of data, such as EMG and motion capture). These different
diff --git a/matlab/TrialConditions.m b/matlab/TrialConditions.m
index cc05eb7..7726f30 100644
--- a/matlab/TrialConditions.m
+++ b/matlab/TrialConditions.m
@@ -1,118 +1,119 @@
classdef TrialConditions
- % TRIALCONDITIONS Defines the names and levels of experimental conditions.
- %
- % See also TrialConditions.generate
+ % TRIALCONDITIONS Defines the names and levels of experimental conditions.
+ %
+ % See also TrialConditions.generate
- properties
- condnames(1,:)
- required(1,:)
- labels_rg
- subst(:,2)
- end
+ properties
+ condnames(1,:)
+ required(1,:)
+ labels_rg
+ subst(:,2)
+ end
- methods
- function obj = TrialConditions(condnames, required, labels_rg, subst)
- if nargin > 0
- obj.condnames = condnames;
- obj.required = required;
- obj.labels_rg = labels_rg;
- obj.subst = subst;
- end
- end
+ methods
+ function obj = TrialConditions(condnames, required, labels_rg, subst)
+ if nargin > 0
+ obj.condnames = condnames;
+ obj.required = required;
+ obj.labels_rg = labels_rg;
+ obj.subst = subst;
+ end
end
+ end
- methods(Static)
- function obj = generate(conditions, labels, varargin)
- % GENERATE Define the names of experimental `conditions` (aka factors) and the
- % possible `labels` within each condition. Conditions are determined from the
- % absolute path of potential sources.
- %
- % trialconds = generate(conditions, labels)
- % trialconds = generate(conditions, labels, Name, Value)
- %
- % # Input arguments
- %
- % - `conditions` is a cell array of condition names (eg `{'medication', 'dose'}`)
- % in the order they must appear in the file paths of trial sources
- % - `labels` is a struct with a field for each condition name (eg `isfield(labels,
- % 'medication')`). Each condition field must have 'to' and 'from' fields which
- % contain the final names and all the name possibilities, respectively. The 'from'
- % field is optional if the terminology in the filenames is the desired terminology.
- %
- % # Name-value arguments
- %
- % - `'Required'` (defaults to all conditions): The conditions which every trial must
- % have (in the case of some trials having optional/additional conditions).
- % - `'Separator'` (defaults to `'[_-]'`): The character separating condition labels
- %
- % # Examples
- %
- % ```matlab
- % labels.session(1).to = '\d';
- % labels.stim(1).to = 'stim';
- % labels.stim(2).to = 'placebo';
- % % or equivalently:
- % labels.session.to = '\d';
- % labels.stim = struct('to', { 'stim'; 'placebo' });
- %
- % conds = TrialConditions.generate({'session';'stim'}, labels)
- % ```
+ methods(Static)
+ function obj = generate(conditions, labels, varargin)
+ % GENERATE Define the names of experimental `conditions` (aka factors) and the
+ % possible `labels` (aka levels) within each condition. Conditions are determined from the
+ % absolute path of potential sources.
+ %
+ % trialconds = generate(conditions, labels)
+ % trialconds = generate(conditions, labels, Name, Value)
+ %
+ % # Input arguments
+ %
+ % - `conditions` is a cell array of condition names (eg `{'medication', 'dose'}`)
+ % in the order they must appear in the file paths of trial sources
+ % - `labels` is a struct with a field for each condition name (eg `isfield(labels,
+ % 'medication')`). Each condition must be a a struct with a 'to' field which
+ % contains a cell array of the acceptable labels. A 'from' field in the struct is used
+ % to match non-standard labels and convert to the standard form (e.g. typos,
+ % inconsistent capitalization, etc).
+ %
+ % # Name-value arguments
+ %
+ % - `'Required'` (defaults to all conditions): The conditions which every trial must
+ % have (in the case of some trials having optional/additional conditions).
+ % - `'Separator'` (defaults to `'[_-]'`): The character separating condition labels
+ %
+ % # Examples
+ %
+ % ```matlab
+ % labels.session(1).to = '\d';
+ % labels.stim(1).to = 'stim';
+ % labels.stim(2).to = 'placebo';
+ % % or equivalently:
+ % labels.session.to = '\d';
+ % labels.stim = struct('to', { 'stim'; 'placebo' });
+ %
+ % conds = TrialConditions.generate({'session';'stim'}, labels)
+ % ```
- p = inputParser;
- addRequired(p, 'conditions', @iscell)
- addRequired(p, 'labels', @isstruct)
- addParameter(p, 'Required', conditions, @iscell)
- addParameter(p, 'Separator', '[_-]', @ischar)
+ p = inputParser;
+ addRequired(p, 'conditions', @iscell)
+ addRequired(p, 'labels', @isstruct)
+ addParameter(p, 'Required', conditions, @iscell)
+ addParameter(p, 'Separator', '[_-]', @ischar)
- parse(p, conditions, labels, varargin{:})
- required = p.Results.Required;
- sep = strcat(p.Results.Separator, '?');
+ parse(p, conditions, labels, varargin{:})
+ required = p.Results.Required;
+ sep = strcat(p.Results.Separator, '?');
- labels_rg = '';
- subst = cell(0,2);
+ labels_rg = '';
+ subst = cell(0,2);
- for condi = 1:length(conditions)
- cond = conditions{condi};
+ for condi = 1:length(conditions)
+ cond = conditions{condi};
- labels_rg = strcat(labels_rg, '(?<', cond, '>');
+ labels_rg = strcat(labels_rg, '(?<', cond, '>');
- if ~isfield(labels, cond)
- error('Error: ''%s'' was not found in ''labels''', cond)
- end
- if ~isfield(labels.(cond), 'to')
- error('Error: ''to'' was not found in ''labels.%s''', cond)
- end
+ if ~isfield(labels, cond)
+ error('Error: ''%s'' was not found in ''labels''', cond)
+ end
+ if ~isfield(labels.(cond), 'to')
+ error('Error: ''to'' was not found in ''labels.%s''', cond)
+ end
- labels_rg = strcat(labels_rg, strjoin({ labels.(cond).('to') }, '|'));
+ labels_rg = strcat(labels_rg, strjoin({ labels.(cond).('to') }, '|'));
- optchar = '?';
+ optchar = '?';
- if condi == length(conditions)
- SEP = '';
- else
- SEP = sep;
- end
+ if condi == length(conditions)
+ SEP = '';
+ else
+ SEP = sep;
+ end
- labels_rg = strcat(labels_rg, ')', optchar, SEP);
+ labels_rg = strcat(labels_rg, ')', optchar, SEP);
- for i = 1:length(labels.(cond))
- condpair = labels.(cond);
- if isfield(condpair(i), 'from')
- condlabel = condpair(i).('from');
- if ~isempty(condlabel)
- if isa(condlabel, 'char')
- altlabels = {condlabel};
- else
- altlabels = condlabel;
- end
- subst = [ subst; { strcat('(?:', strjoin(altlabels, '|'), ')'), ...
- condpair(i).('to') } ];
- end
- end
- end
+ for i = 1:length(labels.(cond))
+ condpair = labels.(cond);
+ if isfield(condpair(i), 'from')
+ condlabel = condpair(i).('from');
+ if ~isempty(condlabel)
+ if isa(condlabel, 'char')
+ altlabels = {condlabel};
+ else
+ altlabels = condlabel;
+ end
+ subst = [ subst; { strcat('(?:', strjoin(altlabels, '|'), ')'), ...
+ condpair(i).('to') } ];
end
-
- obj = TrialConditions(conditions, required, labels_rg, subst);
+ end
end
+ end
+
+ obj = TrialConditions(conditions, required, labels_rg, subst);
end
+ end
end