SelNeTime: Estimate demography and selection from genetic time series
The selnetime python package implements methods for statistical
analysis of genetic data collected for a same population at different times.
This type of data is typically encountered in experimental evolution studies, cohorts of
wild or domestic populations or ancient DNA studies.
The statistical approaches implemented in selnetime are based on
Hidden Markov Models (HMMs) of the evolution of allele frequencies of
biallelic loci through time. The methods
build on approximating this evolution using the "Beta with Spikes" distribution
(a continuous Beta distribution with point masses at 0 and 1),
which significantly improves computational efficiency compared to the standard Wright-Fisher model while offering better accuracy than other usual fully continuous approximations (e.g. Beta, Gaussian). For more details on the methods see Paris et
al. (2019).
Table of Contents
Installing the package
The package is available on the python package index (https://pypi.org/project/selnetime). It can be installed with pip: pip install selnetime, possibly inside a python or conda environment
For latest (under development) version:
- Clone the repository
- Create a conda environment using the selnetime_env.yml file e.g.
mamba env create -f selnetime_env.yml - Install the package by typing
pip install .
Analysing a dataset
The selnetime package comes with a command line program to analyze a
time series dataset: snt. The usage is simply:
snt <prefix> -S
where <prefix> gives the prefix of input files. Two input files are expected,
named <prefix>.genobaypass and <prefix>.times.
The genobaypass file is in the format used by the BayPass software:
one line per (biallelic) locus. On each row, successive pairs of
counts give the number of alleles observed at a given sampling time. For example:
12 19 0 36 0 32 0 26 0 33
6 3 0 3 5 0 11 0 4 0
25 9 39 2 37 14 21 10 17 5
indicates at the first locus, for the first sampling time of the time series 12 (resp. 19) copies of the first (resp. second) alleles were observed.
the times file is a simple csv file indicating the times (in
generations) at which the data were collected. For example:
11,27,45,58,70
will indicate 5 sampling times, corresponding to sampling at generations 11, 27 etc.
The snt program will output two files:
<prefix>.snt.Nwith the results of the estimation of effective population size: for each Ne considered by the program, the corresponding loglikelihood is returned.<prefix>.snt.Swith the results of the estimation of selection coefficients for each locus:- loc : locus index
- mle : Maximum likelihood estimate of s
- pmean : posterior mean for s
- psd : posterior standard deviation for s
- lo : lower bound of the 95% credible interval for s
- hi : upper bound of the 95% credible interval for s
- lfsr: local false-sign rate, i.e. the posterior probability that the MLE is of the wrong sign
Omitting the -S flag skips the estimation of selection, if the only focus of the analysis is the estimation of effective population size. In contrast, if effective population size is aleady known, one can provide it and focus on the estimation of selection using the command:
snt <prefix> -S -N <value>
Analyzing a dataset using the Wright-Fisher model
If effective population size is expected to be small (i.e. a few hundreds or less), it is possible to analyze the data using the exact Wright-Fisher model (instead of the Beta with Spikes). This approach should provide (slightly) more accurate results but is not computationnaly feasible for large populations.
For technical reasons, this analysis cannot be run using a single program. To estimate the effective population (if unknown), the command is:
ntwf <prefix>
It produces a file named <prefix>.snt.wf.N that has the format as that for the standard snt analysis. To estimate selection, the command is then:
snt <prefix> -S -N <value> -M WF
It produces a file named <prefix>.snt.wf.S that again has the format as that for the standard snt analysis.
Simulating datasets
To evaluate the expected performance of snt under a specific sampling design (number and size of samples, time intervals between samples ...), it is generally useful to simulate genetic data and compare the estimations provided by the program with the known true values. For this purpose, we developed the snt_sim, which generates simulated allele trajectories under the Wright-Fisher model and outputs them in the BayPass format used by snt.
This program is simply run by the command:
snt_sim -yaml <prefix>.yaml
where the only input is a yaml file describing the parameters of the simulation. For example :
ID_simu: trajectory
N: 100
depth_vect: [10, 10, 20, 30, 40, 50, 60, 70, 80, 90]
h: 0.5
s: 0.0
sampling_time: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
seed: 3184375
x0: 0.5
nrep: 1000
proportion_sel: 0.2
where N is the effective population size, proportion_sel the proportion of loci under selection, s the selection coefficient at these loci, h the dominance coefficient and seed the random number used to initiate the seed for the simulations. Sampling times and sampling depths (number of alleles observed at each sampling time) are respectively described by the two vectors sampling_time and depth_vect. Finally, x0 is the initial frequency of the refence allele at the first sampling time of the simulations; it takes either a fixed float value in (0,1) or can be drawn in an uniform distribution in (0,1) with string uniform.
snt_sim outputs the two input files expected by the snt program, i.e. a <prefix>.genobaypass and <prefix>.times files.
Note that the simulation program currently assumes fixed selection parameters s and h for the simulated trajectories at all adaptive loci (while allowing a proportion of neutral loci). Simulating a genome with several loci characterized by different selection constraints thus requires to run snt_sim independently with different input files and concatenate the obtained .genobaypass files.
Creating a yaml file
The simulator also comes with a command line program allowing to easily generate the required yaml file. It can be run for instance by:
snt_sim_param -times 1,10,20,30 -N 100 -S 0 -H 0.5 -x0 0.5 -depth 50,50,60,70 -nrep 100 -working_directory path/of/the/directory/ -p 0.2
The working_directory option allows to specify the directory where to save the simulation files. By default the files will be saved in the current working directory. The other different options are as described in the previous section.
References
- Cyriel Paris, Bertrand Servin, Simon Boitard, Inference of Selection from Genetic Time Series Using Various Parametric Approximations to the Wright-Fisher Model, G3 Genes|Genomes|Genetics, Volume 9, Issue 12, 1 December 2019, Pages 4073–4086
Release files for selnetime 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| selnetime-0.3.3.tar.gz | 23.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| selnetime-0.3.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.9 kB
Release files / selnetime-0.3.3.tar.gz
| Download URL | selnetime-0.3.3.tar.gz |
|---|---|
| Size | 23.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
154752df2860bb0b00598e02152cc2447074972bdb0ef5ce7f19d1f2ae5019e6
|
|
BLAKE2b-256 checksum How to use checksums |
2d07434c2fe07cf27fbc8c8832d88a7e4df5f672e2adf26cce6687a7c2ded1d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.7
|
Release files / selnetime-0.3.3-py3-none-any.whl
| Download URL | selnetime-0.3.3-py3-none-any.whl |
|---|---|
| Size | 23.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ed287a328da1e22d8d8ffa3462a889485a463dd69af0773bfec20663cad83939
|
|
BLAKE2b-256 checksum How to use checksums |
c594e890065c377ea0a4e32d0ab8f84d78ab82c8ce9f661eea6f44ba07d2301b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.7
|