SFS Simulation#
- class Simulation(params: dict = None, model: Parametrization | str = 'GammaExpParametrization', sfs_neut: Spectrum = None, eps: float = 0, intervals_del: Tuple[float, float, int] = (-100000000.0, -1e-05, 1000), intervals_ben: Tuple[float, float, int] = (1e-05, 10000.0, 1000), integration_mode: Literal['midpoint', 'quad'] = 'midpoint', linearized: bool = True, discretization: Discretization = None, parallelize: bool = True)[source]#
Bases:
objectSimulate an SFS under selection given a DFE and a neutral SFS.
Example usage:
import fastdfe as fd # create simulation object by specifying neutral SFS and DFE sim = fd.Simulation( sfs_neut=fd.Simulation.get_neutral_sfs(n=20, n_sites=1e8, theta=1e-4), params=dict(S_d=-300, b=0.3, p_b=0.1, S_b=0.1), model=fd.GammaExpParametrization() ) # perform the simulation sfs_sel = sim.run() # plot SFS sfs_sel.plot()
- __init__(params: dict = None, model: Parametrization | str = 'GammaExpParametrization', sfs_neut: Spectrum = None, eps: float = 0, intervals_del: Tuple[float, float, int] = (-100000000.0, -1e-05, 1000), intervals_ben: Tuple[float, float, int] = (1e-05, 10000.0, 1000), integration_mode: Literal['midpoint', 'quad'] = 'midpoint', linearized: bool = True, discretization: Discretization = None, parallelize: bool = True)[source]#
Create a simulation object.
- Parameters:
params (
dict) – Parameters for the DFE parametrization (see model). By default, the default parameters ofmodelwill be used.model (
Parametrization|str) – DFE parametrization modelsfs_neut (
Spectrum) – Neutral SFS. This sfs is informative on the population sample size, population mutation rate, the number of sites, and demography.get_neutral_sfs()can be used to obtain a neutral SFS.eps (
float) – Ancestral misidentification errorintervals_del (
Tuple[float,float,int]) –(start, stop, n_interval)for deleterious population-scaled selection coefficients. The intervals will be log10-spaced.intervals_ben (
Tuple[float,float,int]) – Same asintervals_delbut for positive selection coefficientsintegration_mode (
Literal['midpoint','quad']) – Integration mode for the DFE,quadnot recommendedlinearized (
bool) – Whether to use the linearized DFE,Falsenot recommendedparallelize (
bool) – Whether to parallelize computations
-
model:
Parametrization# The DFE parametrization
-
params:
dict# Parameters for the DFE parametrization
-
n:
int# SFS sample size
-
theta:
float# Population mutation rate
-
n_sites:
float# Number of sites
-
eps:
float# Ancestral misidentification error
-
discretization:
Discretization# Discretization instance
- static get_neutral_sfs(theta: float, n_sites: float, n: int, r: Sequence[float] = None)[source]#
Obtain a standard neutral SFS for a given theta and number of sites.
- Parameters:
theta (
float) – Population mutation raten_sites (
float) – Number of sites in the simulated SFSn (
int) – Number of frequency classes in the simulated SFSr (
Sequence[float]) – Nuisance parameters that account for demography. An array of lengthn-1whose elements are multiplied element-wise with the polymorphic counts of the Kingman SFS. By default, no demography effects are considered which is equivalent tor = [1] * (n-1). Note that non-default values ofrwill also affect estimates of the population mutation rate.
- Return type:
- Returns:
Neutral SFS