torchcell.sequence.calculate_window_bounds_symmetric

calculate_window_bounds_symmetric(start: int, end: int, window_size: int, chromosome_length: int) → tuple[int, int][source]

Calculate symmetric window bounds considering chromosome limits.

This function calculates symmetric window bounds for genomic sequences, taking the chromosome length into account to avoid exceeding it, and also ensuring that the window size, start and end positions are valid within these limits.

Parameters:
  • start (int) – The start point of the sequence on the genome.

  • end (int) – The end point of the sequence on the genome.

  • window_size (int) – The desired window size.

  • chromosome_length (int) – The total length of the chromosome.

Returns:

The calculated start and end points of the symmetric window.

Return type:

tuple[int, int]

Raises:

ValueError – If the end position is out of chromosome bounds, start position is not less than end position, or window size is greater than chromosome length.

Examples

>>> calculate_window_bounds_symmetric(5, 15, 30, 100)
(0, 20)
>>> calculate_window_bounds_symmetric(80, 95, 30, 100)
(75, 100)
>>> calculate_window_bounds_symmetric(45, 55, 30, 100)
(35, 65)

Note

The function also asserts that the calculated window is within the desired limits, symmetric around the middle of the sequence, and the start and end of the window are appropriately bounded within the sequence limits.