coverage

coverage#

Interval.coverage(intervals, *, bin_size=1)[source]#

Computes coverage track from sequence of intervals overlapping interval.

This method calculates the coverage of this interval by a set of other intervals. The coverage is defined as the number of intervals that overlap each position within this interval.

The bin_size parameter allows you to bin the coverage into equal-sized windows. This can be useful for summarizing coverage over larger regions. If bin_size is 1, the coverage is calculated at single-base resolution.

Parameters:
  • intervals (Sequence[Self]) – A sequence of Interval objects that may overlap this interval.

  • bin_size (int (default: 1)) – The size of the bins used to calculate coverage. Must be a positive integer that divides the width of the interval.

Return type:

ndarray

Returns:

A 1D numpy array representing the coverage track. The length of the array is self.width // bin_size. Each element in the array represents the summed coverage within the corresponding bin.

Raises:

ValueError – If bin_size is not a positive integer or if the interval width is not divisible by bin_size.