Home > bml > annot > bml_annot_overlap.m

bml_annot_overlap

PURPOSE ^

BML_ANNOT_OVERLAP calculates overlapping segments between annotations

SYNOPSIS ^

function overlap=bml_annot_overlap(cfg, annot)

DESCRIPTION ^

 BML_ANNOT_OVERLAP calculates overlapping segments between annotations

 Use as
   overlap=bml_annot_overlap(cfg, annot)
   overlap=bml_annot_overlap(annot)

 cfg is a configuration structure
 cfg.timetol = time tolerance in seconds. Defaults to 1e-5.
               useful to avoid detecting contiguity as overlaps due to
               numeric issues.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function overlap=bml_annot_overlap(cfg, annot)
0002 
0003 % BML_ANNOT_OVERLAP calculates overlapping segments between annotations
0004 %
0005 % Use as
0006 %   overlap=bml_annot_overlap(cfg, annot)
0007 %   overlap=bml_annot_overlap(annot)
0008 %
0009 % cfg is a configuration structure
0010 % cfg.timetol = time tolerance in seconds. Defaults to 1e-5.
0011 %               useful to avoid detecting contiguity as overlaps due to
0012 %               numeric issues.
0013 
0014 if nargin == 1
0015   annot = cfg;
0016   cfg=[];
0017 elseif nargin ~= 2
0018   error('incorrect number of arguments');
0019 end
0020 
0021 timetol = bml_getopt(cfg,'timetol',1e-5);
0022 annot = bml_annot_table(annot);
0023 
0024 i=1; j=2;
0025 overlap = cell2table(cell(0,4)); 
0026 overlap.Properties.VariableNames = {'starts','ends','id1','id2'};
0027 while i<=height(annot) && j<=height(annot)
0028   %if annot.starts(i) < annot.ends(j) && annot.ends(i) > annot.starts(j)
0029   if annot.ends(j) - annot.starts(i) > timetol && ...
0030      annot.ends(i) - annot.starts(j) > timetol
0031     overlap = [overlap;{...
0032       max(annot.starts(i),annot.starts(j)),...
0033       min(annot.ends(i),annot.ends(j)),...
0034       annot.id(i),...
0035       annot.id(j)}];
0036       j = j + 1;
0037   elseif annot.ends(i) - annot.starts(j) <= timetol
0038     i=i+1;
0039     j=i+1;
0040   elseif annot.ends(j) - annot.starts(i) <= timetol
0041     j=j+1;
0042   else
0043     annot([i j],:)
0044     error('Unsupported input annotations tables');
0045   end
0046 end

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