Calculate B

The Python API can be used to access core B calculation functions that take vectorized inputs.

Python functions

bvalcalc.get_params(params_path: str | None = None)[source]

Loads DFE parameters from the provided population genetic parameters file.

Parameters:

params_path (str) – Path to Params.py file

bvalcalc.calculateB_linear(distance_to_element: int, length_of_element: int, params: dict | None = None)[source]

Calculate B due to purifying selection acting on a linked selected element of arbitrary length, assuming a constant crossover and gene conversion rate (analytical solution).

Parameters:
  • distance_to_element (int) – Distance (bp) from the neutral site to the nearest edge of the selected element.

  • length_of_element (int) – Length (bp) of the selected element.

  • params (dict) – Required parameters from get_params(), only kept as default (None) when being called by CLI, in which case parameters are sourced from the params file directly.

bvalcalc.calculateB_unlinked(unlinked_L: int, params: dict | None = None)[source]

Calculate B due to purifying selection at unlinked sites (numerical integration over DFE).

Parameters:
  • unlinked_L (float) – Cumulative count of selected sites in unlinked regions.

  • params (dict) – Required parameters from get_params(), only kept as default (None) when being called by CLI, in which case parameters are sourced from the params file directly.

Example

from bvalcalc import get_params, calculateB_unlinked, calculateB_linear

params = get_params("bvalcalc/templates/DrosophilaParams.py")

calculateB_unlinked(unlinked_L = 200000, params = params)

calculateB_linear(distance_to_element = 500, length_of_element = 10000, params = params)

This will import the relevant functions, get the popgen parameters from a relevant params file, see Generate Parameters. Then B will be calculated from 200kb of unlinked sites using calculateB_unlinked, and B from a linked selected element of length 10kb, 500bp away is calculated using calculateB_linear.

Notes

Note that calculateB_linear assumes a consistent crossover and gene conversion rate across both the length of and distance to the selected element, in the CLI, variable recombination rates are accounted for with the more complex function calculateB_recmap; if accessing this function is important for your work feel free to raise it as an issue on GitHub as I could add it as a public API.