center

center#

Interval.center(use_strand=True)[source]#

Computes the center of the interval.

For intervals with an odd width, the center is rounded up for positive/unstranded intervals and rounded down for negative strand intervals.

If use_strand is True and the interval is on the negative strand, the center is calculated differently to maintain consistency when stacking sequences from different intervals oriented in the forward strand direction. This ensures that the relative distance between the interval’s upstream boundary and its center is preserved.

Parameters:

use_strand (bool (default: True)) – If True, the strand of the interval is considered when calculating the center.

Return type:

int

Returns:

The integer representing the center position of the interval.

Examples

>>> Interval('1', 1, 3, '+').center()
2
>>> Interval('1', 1, 3, '-').center()  # Strand doesn't matter.
2
>>> Interval('1', 1, 4, '+').center()
3
>>> Interval('1', 1, 4, '-').center()
2
>>> Interval('1', 1, 4, '-').center()
2
>>> Interval('1', 1, 4, '+').center(use_strand=False)
3
>>> Interval('1', 1, 2, '-').center()
1