private long GetOverlap(BedItem bi, CNVItem ci)
        {
            if (bi.End < ci.Start)
            {
                return(0);
            }

            if (ci.End < bi.Start)
            {
                return(0);
            }

            return(Math.Min(ci.End, bi.End) - Math.Max(ci.Start, bi.Start));
        }
        private BedItem FindMaxOverlap(IGrouping <string, BedItem> bg, CNVItem ci)
        {
            BedItem result     = null;
            long    maxoverlap = 0;

            foreach (var bi in bg)
            {
                var overlapped = GetOverlap(bi, ci);
                if (overlapped > maxoverlap)
                {
                    result     = bi;
                    maxoverlap = overlapped;
                }
            }
            return(result);
        }