cell2net.preprocessing.calculate_depth#
- cell2net.preprocessing.calculate_depth(chrom_size, starts, ends)#
Calculate genome depth for a given chromosome.
This function computes the depth (coverage) at each base pair of a chromosome based on start and end positions of genomic fragments.
- Parameters:
chrom_size (
int
) – The size of the chromosome (total number of base pairs).starts (
ndarray
) – An array of start positions for the genomic fragments. Each value specifies the zero-based position where a fragment begins.ends (
ndarray
) – An array of end positions for the genomic fragments. Each value specifies the zero-based position where a fragment ends (exclusive).
- Return type:
- Returns:
A one-dimensional array of length chrom_size, where each position contains the depth (coverage) at that base pair.
Notes
The starts and ends arrays must have the same length, as each pair defines a single fragment.
The depth is calculated as the count of overlapping fragments for each base pair.
This function uses Numba’s Just-In-Time (JIT) compilation to optimize performance, making it suitable for processing large datasets.
Examples
>>> import numpy as np >>> import cell2net as cn >>> chrom_size = 10 >>> starts = np.array([0, 2, 4]) >>> ends = np.array([3, 6, 8]) >>> depth = cn.pp.calculate_depth(chrom_size, starts, ends) >>> print(depth) array([1, 1, 2, 1, 2, 2, 1, 1, 0, 0], dtype=uint32)