0001 function transfered = bml_annot_transfer(cfg, annot, transfer)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 if nargin == 2
0022 overlap = 0;
0023 transfer = bml_annot_table(annot,[],inputname(2));
0024 annot = bml_annot_table(cfg,[],inputname(1));
0025 cfg=[];
0026 elseif nargin == 3
0027 if isstruct(cfg)
0028 overlap = bml_getopt(cfg,'overlap',0);
0029 else
0030 overlap = 0;
0031 cfg=struct('select',cfg);
0032 end
0033 annot = bml_annot_table(annot,[],inputname(2));
0034 transfer = bml_annot_table(transfer,[],inputname(3));
0035 else
0036 error('use as bml_annot_transfer(annot, filter_annot)');
0037 end
0038
0039 if isempty(annot)
0040 return
0041 end
0042
0043 description = bml_getopt(cfg,'description',[]);
0044 if isempty(description)
0045 if isempty(annot.Properties.Description)
0046 annot.Properties.Description = 'annot';
0047 description = 'annot';
0048 else
0049 description = annot.Properties.Description;
0050 end
0051 end
0052
0053 intersect = bml_annot_intersect(annot,transfer);
0054 intersect.intersect_duration = intersect.duration;
0055 intersect=intersect(:,setdiff(intersect.Properties.VariableNames,annot.Properties.VariableNames));
0056 intersect.id = intersect.([description '_id']);
0057 intersect.([description '_id']) = [];
0058
0059 if length(unique(intersect.id)) < length(intersect.id)
0060 error("can't transfer variables. Inconsistent mapping");
0061 end
0062
0063 select = bml_getopt(cfg,'select',[]);
0064 if ~isempty(select)
0065 select_members = ismember(select,intersect.Properties.VariableNames);
0066 if ~all(select_members)
0067 warning('%s variables not found. Available vars are %s',...
0068 strjoin(select(~select_members)),strjoin(intersect.Properties.VariableNames));
0069 end
0070 intersect = intersect(:,[{'id'},select(select_members)]);
0071 end
0072
0073 annot_intersect=innerjoin(annot,intersect,'Keys','id');
0074
0075 transfered = bml_annot_table(annot_intersect,description);