Home > bml > annot > bml_annot_transfer.m

bml_annot_transfer

PURPOSE ^

BML_ANNOT_TRANSFER copies information of transfer to annot

SYNOPSIS ^

function transfered = bml_annot_transfer(cfg, annot, transfer)

DESCRIPTION ^

 BML_ANNOT_TRANSFER copies information of transfer to annot

 Use as
   transfered = bml_annot_transfer(cfg, annot, transfer)
   transfered = bml_annot_transfer(cfg.select, annot, transfer)
   transfered = bml_annot_transfer(annot, transfer)  

 The first argument cfg is a optional configuration structure, which can contain
 the following optional fields:
 cfg.overlap - double: fraction of overlap required for filter. Defauls 0
           (touch)
 cfg.description - string: description of output annotation
 cfg.select - cellstr. Names of variables to transfer (after name
           modification)

 annot, transfer - annot tables with fields 'starts' and 'ends'.
        'transfer' should have no overlapping annotations

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function transfered = bml_annot_transfer(cfg, annot, transfer)
0002 
0003 % BML_ANNOT_TRANSFER copies information of transfer to annot
0004 %
0005 % Use as
0006 %   transfered = bml_annot_transfer(cfg, annot, transfer)
0007 %   transfered = bml_annot_transfer(cfg.select, annot, transfer)
0008 %   transfered = bml_annot_transfer(annot, transfer)
0009 %
0010 % The first argument cfg is a optional configuration structure, which can contain
0011 % the following optional fields:
0012 % cfg.overlap - double: fraction of overlap required for filter. Defauls 0
0013 %           (touch)
0014 % cfg.description - string: description of output annotation
0015 % cfg.select - cellstr. Names of variables to transfer (after name
0016 %           modification)
0017 %
0018 % annot, transfer - annot tables with fields 'starts' and 'ends'.
0019 %        'transfer' should have no overlapping annotations
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 %case cfg.select is first argument
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);

Generated on Tue 25-Sep-2018 10:08:19 by m2html © 2005