Skip to content

Demographics1D

Single population demographic models.

bottlegrowth_1d(params, ns, pts)

Instantaneous size change followed by exponential growth.

Parameters:

Name Type Description Default
params tuple[float, float, float]

(nuB, nuF, T) where:

  • nuB (float): Ratio of population size after instantaneous change to ancient population size.

  • nuF (float): Ratio of contemporary to ancient population size.

  • T (float): Time in the past at which instantaneous change happened and growth began (in units of 2*Na generations).

required
ns tuple[int]

Number of samples in resulting Spectrum (n1,).

required
pts int

Number of grid points to use in integration.

required

Returns:

Name Type Description
fs Spectrum

The resulting frequency spectrum.

Raises:

Type Description
ValueError

If params does not contain the expected number of elements.

Source code in dadi/Demographics1D.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
def bottlegrowth_1d(params, ns, pts):
    """
    Instantaneous size change followed by exponential growth.

    Parameters:
        params (tuple[float, float, float]): (nuB, nuF, T) where:

            - nuB (float): Ratio of population size after instantaneous change 
              to ancient population size.

            - nuF (float): Ratio of contemporary to ancient population size.

            - T (float): Time in the past at which instantaneous change happened 
              and growth began (in units of 2*Na generations).
        ns (tuple[int]): Number of samples in resulting Spectrum (n1,).
        pts (int): Number of grid points to use in integration.

    Returns:
        fs (Spectrum): The resulting frequency spectrum.

    Raises:
        ValueError: If `params` does not contain the expected number of elements.
    """
    nuB,nuF,T = params

    xx = Numerics.default_grid(pts)
    phi = PhiManip.phi_1D(xx)

    nu_func = lambda t: nuB*numpy.exp(numpy.log(nuF/nuB) * t/T)
    phi = Integration.one_pop(phi, xx, T, nu_func)

    fs = Spectrum.from_phi(phi, ns, (xx,))
    return fs

growth(params, ns, pts)

Exponential growth beginning some time ago.

Parameters:

Name Type Description Default
params tuple[float, float]

(nu, T) where:

  • nu (float): Ratio of contemporary to ancient population size.

  • T (float): Time in the past at which growth began (in units of 2*Na generations).

required
ns tuple[int]

Number of samples in resulting Spectrum (n1,).

required
pts int

Number of grid points to use in integration.

required

Returns:

Name Type Description
fs Spectrum

The resulting frequency spectrum.

Raises:

Type Description
ValueError

If params does not contain the expected number of elements.

Source code in dadi/Demographics1D.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def growth(params, ns, pts):
    """
    Exponential growth beginning some time ago.

    Parameters:
        params (tuple[float, float]): (nu, T) where:

            - nu (float): Ratio of contemporary to ancient population size.

            - T (float): Time in the past at which growth began
              (in units of 2*Na generations).
        ns (tuple[int]): Number of samples in resulting Spectrum (n1,).
        pts (int): Number of grid points to use in integration.

    Returns:
        fs (Spectrum): The resulting frequency spectrum.

    Raises:
        ValueError: If `params` does not contain the expected number of elements.
    """
    nu,T = params

    xx = Numerics.default_grid(pts)
    phi = PhiManip.phi_1D(xx)

    nu_func = lambda t: numpy.exp(numpy.log(nu) * t/T)
    phi = Integration.one_pop(phi, xx, T, nu_func)

    fs = Spectrum.from_phi(phi, ns, (xx,))
    return fs

snm_1d(notused, ns, pts)

Standard neutral model.

Parameters:

Name Type Description Default
notused None

Placeholder parameter, not used in the function.

required
ns tuple[int]

Number of samples in resulting Spectrum (n1,).

required
pts int

Number of grid points to use in integration.

required

Returns:

Name Type Description
fs Spectrum

The resulting frequency spectrum.

Source code in dadi/Demographics1D.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def snm_1d(notused, ns, pts):
    """
    Standard neutral model.

    Parameters:
        notused (None): Placeholder parameter, not used in the function.
        ns (tuple[int]): Number of samples in resulting Spectrum (n1,).
        pts (int): Number of grid points to use in integration.

    Returns:
        fs (Spectrum): The resulting frequency spectrum.
    """
    xx = Numerics.default_grid(pts)
    phi = PhiManip.phi_1D(xx)

    fs = Spectrum.from_phi(phi, ns, (xx,))
    return fs

three_epoch(params, ns, pts)

Three-epoch demographic model.

Parameters:

Name Type Description Default
params tuple[float, float, float, float]

(nuB, nuF, TB, TF) where:

  • nuB (float): Ratio of bottleneck population size to ancient pop size.

  • nuF (float): Ratio of contemporary to ancient pop size.

  • TB (float): Length of bottleneck (in units of 2*Na generations).

  • TF (float): Time since bottleneck recovery (in units of 2*Na generations).

required
ns tuple[int]

Number of samples in resulting Spectrum (n1,).

required
pts int

Number of grid points to use in integration.

required

Returns:

Name Type Description
fs Spectrum

The resulting frequency spectrum.

Raises:

Type Description
ValueError

If params does not contain the expected number of elements.

Source code in dadi/Demographics1D.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def three_epoch(params, ns, pts):
    """
    Three-epoch demographic model.

    Parameters:
        params (tuple[float, float, float, float]): (nuB, nuF, TB, TF) where:

            - nuB (float): Ratio of bottleneck population size to ancient pop size.

            - nuF (float): Ratio of contemporary to ancient pop size.

            - TB (float): Length of bottleneck (in units of 2*Na generations).

            - TF (float): Time since bottleneck recovery (in units of 2*Na generations).
        ns (tuple[int]): Number of samples in resulting Spectrum (n1,).
        pts (int): Number of grid points to use in integration.

    Returns:
        fs (Spectrum): The resulting frequency spectrum.

    Raises:
        ValueError: If `params` does not contain the expected number of elements.
    """
    nuB,nuF,TB,TF = params

    xx = Numerics.default_grid(pts)
    phi = PhiManip.phi_1D(xx)

    phi = Integration.one_pop(phi, xx, TB, nuB)
    phi = Integration.one_pop(phi, xx, TF, nuF)

    fs = Spectrum.from_phi(phi, ns, (xx,))
    return fs

three_epoch_inbreeding(params, ns, pts)

Three-epoch demographic model with inbreeding.

Parameters:

Name Type Description Default
params tuple[float, float, float, float, float]

(nuB, nuF, TB, TF, F) where:

  • nuB (float): Ratio of bottleneck population size to ancient pop size.

  • nuF (float): Ratio of contemporary to ancient pop size.

  • TB (float): Length of bottleneck (in units of 2*Na generations).

  • TF (float): Time since bottleneck recovery (in units of 2*Na generations).

  • F (float): Inbreeding coefficient.

required
ns tuple[int]

Number of samples in resulting Spectrum (n1,).

required
pts int

Number of grid points to use in integration.

required

Returns:

Name Type Description
fs Spectrum

The resulting frequency spectrum.

Raises:

Type Description
ValueError

If params does not contain the expected number of elements.

Source code in dadi/Demographics1D.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
def three_epoch_inbreeding(params, ns, pts):
    """
    Three-epoch demographic model with inbreeding.

    Parameters:
        params (tuple[float, float, float, float, float]): (nuB, nuF, TB, TF, F) where:

            - nuB (float): Ratio of bottleneck population size to ancient pop size.

            - nuF (float): Ratio of contemporary to ancient pop size.

            - TB (float): Length of bottleneck (in units of 2*Na generations).

            - TF (float): Time since bottleneck recovery (in units of 2*Na generations).

            - F (float): Inbreeding coefficient.
        ns (tuple[int]): Number of samples in resulting Spectrum (n1,).
        pts (int): Number of grid points to use in integration.

    Returns:
        fs (Spectrum): The resulting frequency spectrum.

    Raises:
        ValueError: If `params` does not contain the expected number of elements.
    """
    nuB,nuF,TB,TF,F = params

    xx = Numerics.default_grid(pts)
    phi = PhiManip.phi_1D(xx)

    phi = Integration.one_pop(phi, xx, TB, nuB)
    phi = Integration.one_pop(phi, xx, TF, nuF)

    fs = Spectrum.from_phi_inbreeding(phi, ns, (xx,), (F,), (2,))
    return fs

two_epoch(params, ns, pts)

Instantaneous size change some time ago.

Parameters:

Name Type Description Default
params tuple[float, float]

(nu, T) where:

  • nu (float): Ratio of contemporary to ancient population size.

  • T (float): Time in the past at which size change happened (in units of 2*Na generations).

required
ns tuple[int]

Number of samples in resulting Spectrum (n1,).

required
pts int

Number of grid points to use in integration.

required

Returns:

Name Type Description
fs Spectrum

The resulting frequency spectrum.

Raises:

Type Description
ValueError

If params does not contain the expected number of elements.

Source code in dadi/Demographics1D.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def two_epoch(params, ns, pts):
    """
    Instantaneous size change some time ago.

    Parameters:
        params (tuple[float, float]): (nu, T) where:

            - nu (float): Ratio of contemporary to ancient population size.

            - T (float): Time in the past at which size change happened 
              (in units of 2*Na generations).
        ns (tuple[int]): Number of samples in resulting Spectrum (n1,).
        pts (int): Number of grid points to use in integration.

    Returns:
        fs (Spectrum): The resulting frequency spectrum.

    Raises:
        ValueError: If `params` does not contain the expected number of elements.
    """
    nu,T = params

    xx = Numerics.default_grid(pts)
    phi = PhiManip.phi_1D(xx)

    phi = Integration.one_pop(phi, xx, T, nu)

    fs = Spectrum.from_phi(phi, ns, (xx,))
    return fs