crested.utils.read_bigwig_region

crested.utils.read_bigwig_region#

crested.utils.read_bigwig_region(bigwig_file, coordinates, bin_size=None, target='mean', missing=0.0, oob=0.0)#

Extract per-base or binned pair values from a bigWig file for a set of genomic region.

Parameters:
  • bigwig_file (PathLike) – Path to the bigWig file.

  • coordinates (tuple[str, int, int]) – A tuple looking like (chr, start, end).

  • bin_size (Optional[int] (default: None)) – If set, the returned values are mean-binned at this resolution.

  • target (str (default: 'mean')) – How to summarize the values per bin, when binning. Can be ‘mean’, ‘min’, or ‘max’.

  • missing (float (default: 0.0)) – Fill-in value for unreported data in valid regions. Default is 0.

  • oob (float (default: 0.0)) – Fill-in value for out-of-bounds regions. Default is 0.

Return type:

tuple[ndarray, ndarray]

Returns:

values

numpy array with the values from the bigwig for the requested coordinates. Shape: [n_bp], or [n_bp//bin_size] if bin_size is specified.

positions

numpy array with genomic positions as integers of the values in values. Shape: [n_bp], or [n_bp//bin_size] if bin_size is specified.

Example

>>> anndata = crested.read_bigwig_region(
...     bw_file="path/to/bigwig",
...     coordinates=("chr1", 0, 32000),
...     bin_size=32,
...     target="mean",
... )