Skip to content

DemogSelModels

Input models of demography + selection.

IM_pre_sel(params, ns, pts)

Isolation-with-migration model with exponential population growth, a size change prior to split, and selection.

Parameters:

Name Type Description Default
params list

[nuPre, TPre, s, nu1, nu2, T, m12, m21, gamma1, gamma2]

  • nuPre (float): Size after first size change

  • TPre (float): Time before split of first size change

  • s (float): Fraction of nuPre that goes to pop1 (Pop 2 has size nuPre*(1-s))

  • nu1 (float): Final size of pop 1

  • nu2 (float): Final size of pop 2

  • T (float): Time in the past of split (in units of 2*Na generations)

  • m12 (float): Migration from pop 2 to pop 1 (2Nam12)

  • m21 (float): Migration from pop 1 to pop 2

  • gamma1 (float): Scaled selection coefficient in pop 1 and ancestral pop

  • gamma2 (float): Scaled selection coefficient in pop 2

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

Note
  • DFE methods internally apply make_extrap_func, so there is no need to make it extrapolate again.
  • Selection in contemporary population 1 is assumed to equal that in the ancestral population.
Source code in dadi/DFE/DemogSelModels.py
 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
 90
 91
 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
def IM_pre_sel(params, ns, pts):
    """
    Isolation-with-migration model with exponential population growth, 
    a size change prior to split, and selection.

    Args:
        params (list): [nuPre, TPre, s, nu1, nu2, T, m12, m21, gamma1, gamma2]

            - nuPre (float): Size after first size change

            - TPre (float): Time before split of first size change

            - s (float): Fraction of nuPre that goes to pop1 (Pop 2 has size nuPre*(1-s))

            - nu1 (float): Final size of pop 1

            - nu2 (float): Final size of pop 2

            - T (float): Time in the past of split (in units of 2*Na generations)

            - m12 (float): Migration from pop 2 to pop 1 (2*Na*m12)

            - m21 (float): Migration from pop 1 to pop 2

            - gamma1 (float): Scaled selection coefficient in pop 1 and ancestral pop

            - gamma2 (float): Scaled selection coefficient in pop 2

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum

    Note:
        - DFE methods internally apply make_extrap_func, so there is no need to make it extrapolate again.
        - Selection in contemporary population 1 is assumed to equal that in the ancestral population.
    """
    nuPre,TPre,s,nu1,nu2,T,m12,m21,gamma1,gamma2 = params

    xx = Numerics.default_grid(pts)

    phi = PhiManip.phi_1D(xx, gamma=gamma1)
    phi = Integration.one_pop(phi, xx, TPre, nu=nuPre, gamma=gamma1)
    phi = PhiManip.phi_1D_to_2D(xx, phi)

    nu1_0 = nuPre*s
    nu2_0 = nuPre*(1-s)
    nu1_func = lambda t: nu1_0 * (nu1/nu1_0)**(t/T)
    nu2_func = lambda t: nu2_0 * (nu2/nu2_0)**(t/T)
    phi = Integration.two_pops(phi, xx, T, nu1_func, nu2_func,
                               m12=m12, m21=m21, 
                               gamma1=gamma1, gamma2=gamma2)

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

IM_pre_sel_single_gamma(params, ns, pts)

IM_pre_sel model with selection assumed to be equal in all populations.

Parameters:

Name Type Description Default
params list

[nuPre, TPre, s, nu1, nu2, T, m12, m21, gamma]

  • nuPre (float): Size after first size change

  • TPre (float): Time before split of first size change

  • s (float): Fraction of nuPre that goes to pop1 (Pop 2 has size nuPre*(1-s))

  • nu1 (float): Final size of pop 1

  • nu2 (float): Final size of pop 2

  • T (float): Time in the past of split (in units of 2*Na generations)

  • m12 (float): Migration from pop 2 to pop 1 (2Nam12)

  • m21 (float): Migration from pop 1 to pop 2

  • gamma (float): Scaled selection coefficient

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

See Also

IM_pre_sel for argument definitions, but only a single gamma in params.

Source code in dadi/DFE/DemogSelModels.py
123
124
125
126
127
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
def IM_pre_sel_single_gamma(params, ns, pts):
    """
    IM_pre_sel model with selection assumed to be equal in all populations.

    Args:
        params (list): [nuPre, TPre, s, nu1, nu2, T, m12, m21, gamma]

            - nuPre (float): Size after first size change

            - TPre (float): Time before split of first size change

            - s (float): Fraction of nuPre that goes to pop1 (Pop 2 has size nuPre*(1-s))

            - nu1 (float): Final size of pop 1

            - nu2 (float): Final size of pop 2

            - T (float): Time in the past of split (in units of 2*Na generations)

            - m12 (float): Migration from pop 2 to pop 1 (2*Na*m12)

            - m21 (float): Migration from pop 1 to pop 2

            - gamma (float): Scaled selection coefficient

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum

    See Also:
        [IM_pre_sel][dadi.DFE.DemogSelModels.IM_pre_sel] for argument definitions, but only a single gamma in params.
    """
    nuPre,TPre,s,nu1,nu2,T,m12,m21,gamma = params
    return IM_pre_sel((nuPre,TPre,s,nu1,nu2,T,m12,m21,gamma,gamma), ns, pts)

IM_sel(params, ns, pts)

Isolation-with-migration model with exponential population growth and selection.

Parameters:

Name Type Description Default
params list

[s, nu1, nu2, T, m12, m21, gamma1, gamma2]

  • s (float): Fraction of the ancestral population size (Na) that goes to pop1 (Pop 2 has size Na*(1-s))

  • nu1 (float): Final size of pop 1

  • nu2 (float): Final size of pop 2

  • T (float): Time in the past of split (in units of 2*Na generations)

  • m12 (float): Migration from pop 2 to pop 1 (2Nam12)

  • m21 (float): Migration from pop 1 to pop 2

  • gamma1 (float): Scaled selection coefficient in pop 1 and ancestral pop

  • gamma2 (float): Scaled selection coefficient in pop 2

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

Note
  • This function is defined using a decorator with make_extrap_func, so there is no need to make it extrapolate again.
  • Selection in contemporary population 1 is assumed to equal that in the ancestral population.
Source code in dadi/DFE/DemogSelModels.py
162
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
def IM_sel(params, ns, pts):
    """
    Isolation-with-migration model with exponential population growth and selection.

    Args:
        params (list): [s, nu1, nu2, T, m12, m21, gamma1, gamma2]

            - s (float): Fraction of the ancestral population size (Na) that goes to pop1 (Pop 2 has size Na*(1-s))

            - nu1 (float): Final size of pop 1

            - nu2 (float): Final size of pop 2

            - T (float): Time in the past of split (in units of 2*Na generations)

            - m12 (float): Migration from pop 2 to pop 1 (2*Na*m12)

            - m21 (float): Migration from pop 1 to pop 2

            - gamma1 (float): Scaled selection coefficient in pop 1 and ancestral pop

            - gamma2 (float): Scaled selection coefficient in pop 2

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum

    Note:
        - This function is defined using a decorator with make_extrap_func, so there is no need to make it extrapolate again.
        - Selection in contemporary population 1 is assumed to equal that in the ancestral population.
    """
    s,nu1,nu2,T,m12,m21,gamma1,gamma2 = params
    return IM_pre_sel((1,0,s,nu1,nu2,T,m12,m21,gamma1,gamma2), ns, pts)

IM_sel_single_gamma(params, ns, pts)

IM_sel model with selection assumed to be equal in all populations.

Parameters:

Name Type Description Default
params list

[s, nu1, nu2, T, m12, m21, gamma]

  • s (float): Fraction of the ancestral population size (Na) that goes to pop1 (Pop 2 has size Na*(1-s))

  • nu1 (float): Final size of pop 1

  • nu2 (float): Final size of pop 2

  • T (float): Time in the past of split (in units of 2*Na generations)

  • m12 (float): Migration from pop 2 to pop 1 (2Nam12)

  • m21 (float): Migration from pop 1 to pop 2

  • gamma (float): Scaled selection coefficient

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

See Also

IM_sel for argument definitions, but only a single gamma in params.

Source code in dadi/DFE/DemogSelModels.py
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
def IM_sel_single_gamma(params, ns, pts):
    """
    IM_sel model with selection assumed to be equal in all populations.

    Args:
        params (list): [s, nu1, nu2, T, m12, m21, gamma]

            - s (float): Fraction of the ancestral population size (Na) that goes to pop1 (Pop 2 has size Na*(1-s))

            - nu1 (float): Final size of pop 1

            - nu2 (float): Final size of pop 2

            - T (float): Time in the past of split (in units of 2*Na generations)

            - m12 (float): Migration from pop 2 to pop 1 (2*Na*m12)

            - m21 (float): Migration from pop 1 to pop 2

            - gamma (float): Scaled selection coefficient

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum

    See Also:
        IM_sel for argument definitions, but only a single gamma in params.
    """
    s,nu1,nu2,T,m12,m21,gamma = params
    return IM_sel((s,nu1,nu2,T,m12,m21,gamma,gamma), ns, pts)

bottlegrowth_1d_sel(params, ns, pts)

Instantaneous size change followed by exponential growth.

Parameters:

Name Type Description Default
params list

[nuB, nuF, T, gamma]

  • 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)

  • gamma (float): Scaled selection coefficient

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

Source code in dadi/DFE/DemogSelModels.py
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
def bottlegrowth_1d_sel(params, ns, pts):
    """
    Instantaneous size change followed by exponential growth.

    Args:
        params (list): [nuB, nuF, T, gamma]

            - 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)

            - gamma (float): Scaled selection coefficient

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum
    """
    nuB,nuF,T,gamma = params

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

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

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

bottlegrowth_2d_sel(params, ns, pts)

Instantaneous size change followed by exponential growth with no population split.

Parameters:

Name Type Description Default
params list

[nuB, nuF, T, gamma1, gamma2]

  • 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)

  • gamma1 (float): Scaled selection coefficient in pop 1 and ancestral pop

  • gamma2 (float): Scaled selection coefficient in pop 2

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

Source code in dadi/DFE/DemogSelModels.py
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
def bottlegrowth_2d_sel(params, ns, pts):
    """
    Instantaneous size change followed by exponential growth with no population split.

    Args:
        params (list): [nuB, nuF, T, gamma1, gamma2]

            - 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)

            - gamma1 (float): Scaled selection coefficient in pop 1 and ancestral pop

            - gamma2 (float): Scaled selection coefficient in pop 2

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum
    """
    nuB,nuF,T,gamma1,gamma2 = params
    return bottlegrowth_split_mig_sel((nuB,nuF,0,T,0,gamma1,gamma2), ns, pts)

bottlegrowth_2d_sel_single_gamma(params, ns, pts)

bottlegrowth_2d_sel model with selection assumed to be equal in all populations.

Parameters:

Name Type Description Default
params list

[nuB, nuF, T, gamma]

  • 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)

  • gamma (float): Scaled selection coefficient

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

See Also

bottlegrowth_2d_sel for argument definitions, but only a single gamma in params.

Source code in dadi/DFE/DemogSelModels.py
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
def bottlegrowth_2d_sel_single_gamma(params, ns, pts):
    """
    bottlegrowth_2d_sel model with selection assumed to be equal in all populations.

    Args:
        params (list): [nuB, nuF, T, gamma]

            - 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)

            - gamma (float): Scaled selection coefficient

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum

    See Also:
        bottlegrowth_2d_sel for argument definitions, but only a single gamma in params.
    """
    nuB,nuF,T,gamma = params
    return bottlegrowth_split_mig_sel((nuB,nuF,0,T,0,gamma,gamma), ns, pts)

bottlegrowth_split_mig_sel(params, ns, pts)

Instantaneous size change followed by exponential growth then split with migration.

Parameters:

Name Type Description Default
params list

[nuB, nuF, m, T, Ts, gamma1, gamma2]

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

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

  • m (float): Migration rate between the two populations (2Nam)

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

  • Ts (float): Time in the past at which the two populations split

  • gamma1 (float): Scaled selection coefficient in pop 1 and ancestral pop

  • gamma2 (float): Scaled selection coefficient in pop 2

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

Source code in dadi/DFE/DemogSelModels.py
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
def bottlegrowth_split_mig_sel(params, ns, pts):
    """
    Instantaneous size change followed by exponential growth then split with migration.

    Args:
        params (list): [nuB, nuF, m, T, Ts, gamma1, gamma2]

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

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

            - m (float): Migration rate between the two populations (2*Na*m)

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

            - Ts (float): Time in the past at which the two populations split

            - gamma1 (float): Scaled selection coefficient in pop 1 and ancestral pop

            - gamma2 (float): Scaled selection coefficient in pop 2

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum
    """
    nuB,nuF,m,T,Ts,gamma1,gamma2 = params

    xx = Numerics.default_grid(pts)
    phi = PhiManip.phi_1D(xx, gamma=gamma1)

    if T >= Ts:
        nu_func = lambda t: nuB*numpy.exp(numpy.log(nuF/nuB) * t/T)
        phi = Integration.one_pop(phi, xx, T-Ts, nu_func, gamma=gamma1)

        phi = PhiManip.phi_1D_to_2D(xx, phi)
        nu0 = nu_func(T-Ts)
        nu_func = lambda t: nu0*numpy.exp(numpy.log(nuF/nu0) * t/Ts)
        phi = Integration.two_pops(phi, xx, Ts, nu_func, nu_func, m12=m, m21=m,
                                   gamma1=gamma1, gamma2=gamma2)
    else:
        phi = PhiManip.phi_1D_to_2D(xx, phi)
        phi = Integration.two_pops(phi, xx, Ts-T, 1, 1, m12=m, m21=m,
                                   gamma1=gamma1, gamma2=gamma2)
        nu_func = lambda t: nuB*numpy.exp(numpy.log(nuF/nuB) * t/T)
        phi = Integration.two_pops(phi, xx, T, nu_func, nu_func, m12=m, m21=m,
                                   gamma1=gamma1, gamma2=gamma2)

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

bottlegrowth_split_mig_sel_single_gamma(params, ns, pts)

bottlegrowth_split_mig_sel model with selection assumed to be equal in all populations.

Parameters:

Name Type Description Default
params list

[nuB, nuF, m, T, Ts, gamma]

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

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

  • m (float): Migration rate between the two populations (2Nam)

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

  • Ts (float): Time in the past at which the two populations split

  • gamma (float): Scaled selection coefficient

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

See Also

bottlegrowth_split_mig_sel for argument definitions, but only a single gamma in params.

Source code in dadi/DFE/DemogSelModels.py
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
def bottlegrowth_split_mig_sel_single_gamma(params, ns, pts):
    """
    bottlegrowth_split_mig_sel model with selection assumed to be equal in all populations.

    Args:
        params (list): [nuB, nuF, m, T, Ts, gamma]

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

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

            - m (float): Migration rate between the two populations (2*Na*m)

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

            - Ts (float): Time in the past at which the two populations split

            - gamma (float): Scaled selection coefficient

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum

    See Also:
        bottlegrowth_split_mig_sel for argument definitions, but only a single gamma in params.
    """
    nuB,nuF,m,T,Ts,gamma = params
    return bottlegrowth_split_mig_sel((nuB,nuF,m,T,Ts,gamma,gamma), ns, pts)

bottlegrowth_split_sel(params, ns, pts)

Instantaneous size change followed by exponential growth then split.

Parameters:

Name Type Description Default
params list

[nuB, nuF, T, Ts, gamma1, gamma2]

  • 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)

  • Ts (float): Time in the past at which the two populations split

  • gamma1 (float): Scaled selection coefficient in pop 1 and ancestral pop

  • gamma2 (float): Scaled selection coefficient in pop 2

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

Source code in dadi/DFE/DemogSelModels.py
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
def bottlegrowth_split_sel(params, ns, pts):
    """
    Instantaneous size change followed by exponential growth then split.

    Args:
        params (list): [nuB, nuF, T, Ts, gamma1, gamma2]

            - 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)

            - Ts (float): Time in the past at which the two populations split

            - gamma1 (float): Scaled selection coefficient in pop 1 and ancestral pop

            - gamma2 (float): Scaled selection coefficient in pop 2

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum
    """
    nuB,nuF,T,Ts,gamma1,gamma2 = params
    return bottlegrowth_split_mig_sel((nuB,nuF,0,T,Ts,gamma1,gamma2), ns, pts)

bottlegrowth_split_sel_single_gamma(params, ns, pts)

bottlegrowth_split_sel model with selection assumed to be equal in all populations.

Parameters:

Name Type Description Default
params list

[nuB, nuF, T, Ts, gamma]

  • 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)

  • Ts (float): Time in the past at which the two populations split

  • gamma (float): Scaled selection coefficient

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

See Also

bottlegrowth_split_sel for argument definitions, but only a single gamma in params.

Source code in dadi/DFE/DemogSelModels.py
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
def bottlegrowth_split_sel_single_gamma(params, ns, pts):
    """
    bottlegrowth_split_sel model with selection assumed to be equal in all populations.

    Args:
        params (list): [nuB, nuF, T, Ts, gamma]

            - 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)

            - Ts (float): Time in the past at which the two populations split

            - gamma (float): Scaled selection coefficient

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum

    See Also:
        bottlegrowth_split_sel for argument definitions, but only a single gamma in params.
    """
    nuB,nuF,T,Ts,gamma = params
    return bottlegrowth_split_mig_sel((nuB,nuF,0,T,Ts,gamma,gamma), ns, pts)

equil(params, ns, pts)

Equilibrium demography, plus selection.

Parameters:

Name Type Description Default
params list

[gamma]

  • gamma (float): Scaled selection coefficient
required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

Note

DFE methods internally apply make_extrap_func, so there is no need to make it extrapolate again.

Source code in dadi/DFE/DemogSelModels.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def equil(params, ns, pts):
    """
    Equilibrium demography, plus selection.

    Args:
        params (list): [gamma]

            - gamma (float): Scaled selection coefficient

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum

    Note:
        DFE methods internally apply make_extrap_func, so there is no need to make it extrapolate again.
    """
    gamma = params[0]

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

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

growth_sel(params, ns, pts)

Exponential growth beginning some time ago.

Parameters:

Name Type Description Default
params list

[nu, T, gamma]

  • 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)

  • gamma (float): Scaled selection coefficient

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

Source code in dadi/DFE/DemogSelModels.py
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
def growth_sel(params, ns, pts):
    """
    Exponential growth beginning some time ago.

    Args:
        params (list): [nu, T, gamma]

            - 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)

            - gamma (float): Scaled selection coefficient

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum
    """
    nu,T,gamma = params

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

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

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

split_asym_mig_sel(params, ns, pts)

Instantaneous split into two populations of specified size, with asymmetric migration.

Parameters:

Name Type Description Default
params list

[nu1, nu2, T, m12, m21, gamma1, gamma2]

  • nu1 (float): Size of population 1 after split

  • nu2 (float): Size of population 2 after split

  • T (float): Time in the past of split (in units of 2*Na generations)

  • m12 (float): Migration rate from population 2 to population 1 (2Nam12)

  • m21 (float): Migration rate from population 1 to population 2 (2Nam21)

  • gamma1 (float): Scaled selection coefficient in pop 1 and ancestral pop

  • gamma2 (float): Scaled selection coefficient in pop 2

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

Note
  • DFE methods internally apply make_extrap_func, so there is no need to make it extrapolate again.
  • Selection in contemporary population 1 is assumed to equal that in the ancestral population.
Source code in dadi/DFE/DemogSelModels.py
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
def split_asym_mig_sel(params, ns, pts):
    """
    Instantaneous split into two populations of specified size, with asymmetric migration.

    Args:
        params (list): [nu1, nu2, T, m12, m21, gamma1, gamma2]

            - nu1 (float): Size of population 1 after split

            - nu2 (float): Size of population 2 after split

            - T (float): Time in the past of split (in units of 2*Na generations)

            - m12 (float): Migration rate from population 2 to population 1 (2*Na*m12)

            - m21 (float): Migration rate from population 1 to population 2 (2*Na*m21)

            - gamma1 (float): Scaled selection coefficient in pop 1 and ancestral pop

            - gamma2 (float): Scaled selection coefficient in pop 2

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum

    Note:
        - DFE methods internally apply make_extrap_func, so there is no need to make it extrapolate again.
        - Selection in contemporary population 1 is assumed to equal that in the ancestral population.
    """
    nu1,nu2,T,m12,m21,gamma1,gamma2 = params

    xx = Numerics.default_grid(pts)

    phi = PhiManip.phi_1D(xx, gamma=gamma1)
    phi = PhiManip.phi_1D_to_2D(xx, phi)

    phi = Integration.two_pops(phi, xx, T, nu1, nu2, m12=m12, m21=m21, gamma1=gamma1,
                               gamma2=gamma2)

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

split_asym_mig_sel_single_gamma(params, ns, pts)

split_asym_mig_sel model with selection assumed to be equal in all populations.

Parameters:

Name Type Description Default
params list

[nu1, nu2, T, m12, m21, gamma]

  • nu1 (float): Size of population 1 after split

  • nu2 (float): Size of population 2 after split

  • T (float): Time in the past of split (in units of 2*Na generations)

  • m12 (float): Migration rate from population 2 to population 1 (2Nam12)

  • m21 (float): Migration rate from population 1 to population 2 (2Nam21)

  • gamma (float): Scaled selection coefficient

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

See Also

split_asym_mig_sel for argument definitions, but only a single gamma in params.

Source code in dadi/DFE/DemogSelModels.py
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
def split_asym_mig_sel_single_gamma(params, ns, pts):
    """
    split_asym_mig_sel model with selection assumed to be equal in all populations.

    Args:
        params (list): [nu1, nu2, T, m12, m21, gamma]

            - nu1 (float): Size of population 1 after split

            - nu2 (float): Size of population 2 after split

            - T (float): Time in the past of split (in units of 2*Na generations)

            - m12 (float): Migration rate from population 2 to population 1 (2*Na*m12)

            - m21 (float): Migration rate from population 1 to population 2 (2*Na*m21)

            - gamma (float): Scaled selection coefficient

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum

    See Also:
        split_asym_mig_sel for argument definitions, but only a single gamma in params.
    """
    nu1,nu2,T,m12,m21,gamma = params
    return split_asym_mig_sel([nu1,nu2,T,m12,m21,gamma,gamma], ns, pts)

split_delay_mig_sel(params, ns, pts)

Split into two populations of specified size, with migration after some time has passed post split.

Parameters:

Name Type Description Default
params list

[nu1, nu2, Tpre, Tmig, m12, m21, gamma1, gamma2]

  • nu1 (float): Size of population 1 after split

  • nu2 (float): Size of population 2 after split

  • Tpre (float): Time in the past after split but before migration (in units of 2*Na generations)

  • Tmig (float): Time in the past after migration starts (in units of 2*Na generations)

  • m12 (float): Migration from pop 2 to pop 1 (2Nam12)

  • m21 (float): Migration from pop 1 to pop 2 (2Nam21)

  • gamma1 (float): Scaled selection coefficient in pop 1 and ancestral pop

  • gamma2 (float): Scaled selection coefficient in pop 2

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

Source code in dadi/DFE/DemogSelModels.py
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
def split_delay_mig_sel(params, ns, pts):
    """
    Split into two populations of specified size, with migration after some time has passed post split.

    Args:
        params (list): [nu1, nu2, Tpre, Tmig, m12, m21, gamma1, gamma2]

            - nu1 (float): Size of population 1 after split

            - nu2 (float): Size of population 2 after split

            - Tpre (float): Time in the past after split but before migration (in units of 2*Na generations)

            - Tmig (float): Time in the past after migration starts (in units of 2*Na generations)

            - m12 (float): Migration from pop 2 to pop 1 (2*Na*m12)

            - m21 (float): Migration from pop 1 to pop 2 (2*Na*m21)

            - gamma1 (float): Scaled selection coefficient in pop 1 and ancestral pop

            - gamma2 (float): Scaled selection coefficient in pop 2

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum
    """
    nu1,nu2,Tpre,Tmig,m12,m21,gamma1,gamma2 = params

    xx = Numerics.default_grid(pts)

    phi = PhiManip.phi_1D(xx, gamma=gamma1)
    phi = PhiManip.phi_1D_to_2D(xx, phi)
    phi = Integration.two_pops(phi, xx, Tpre, nu1, nu2, m12=0, m21=0, 
                               gamma1=gamma1, gamma2=gamma2)
    phi = Integration.two_pops(phi, xx, Tmig, nu1, nu2, m12=m12, m21=m21, 
                               gamma1=gamma1, gamma2=gamma2)

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

split_delay_mig_sel_single_gamma(params, ns, pts)

split_delay_mig_sel model with selection assumed to be equal in all populations.

Parameters:

Name Type Description Default
params list

[nu1, nu2, Tpre, Tmig, m12, m21, gamma]

  • nu1 (float): Size of population 1 after split

  • nu2 (float): Size of population 2 after split

  • Tpre (float): Time in the past after split but before migration (in units of 2*Na generations)

  • Tmig (float): Time in the past after migration starts (in units of 2*Na generations)

  • m12 (float): Migration from pop 2 to pop 1 (2Nam12)

  • m21 (float): Migration from pop 1 to pop 2 (2Nam21)

  • gamma (float): Scaled selection coefficient

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

See Also

split_delay_mig_sel for argument definitions, but only a single gamma in params.

Source code in dadi/DFE/DemogSelModels.py
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
def split_delay_mig_sel_single_gamma(params, ns, pts):
    """
    split_delay_mig_sel model with selection assumed to be equal in all populations.

    Args:
        params (list): [nu1, nu2, Tpre, Tmig, m12, m21, gamma]

            - nu1 (float): Size of population 1 after split

            - nu2 (float): Size of population 2 after split

            - Tpre (float): Time in the past after split but before migration (in units of 2*Na generations)

            - Tmig (float): Time in the past after migration starts (in units of 2*Na generations)

            - m12 (float): Migration from pop 2 to pop 1 (2*Na*m12)

            - m21 (float): Migration from pop 1 to pop 2 (2*Na*m21)

            - gamma (float): Scaled selection coefficient

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum

    See Also:
        split_delay_mig_sel for argument definitions, but only a single gamma in params.
    """
    nu1,nu2,Tpre,Tmig,m12,m21,gamma = params
    return split_delay_mig_sel([nu1,nu2,Tpre,Tmig,m12,m21,gamma,gamma], ns, pts)

split_mig_sel(params, ns, pts)

Instantaneous split into two populations of specified size, with symmetric migration.

Parameters:

Name Type Description Default
params list

[nu1, nu2, T, m, gamma1, gamma2]

  • nu1 (float): Size of population 1 after split

  • nu2 (float): Size of population 2 after split

  • T (float): Time in the past of split (in units of 2*Na generations)

  • m (float): Migration rate between populations (2Nam)

  • gamma1 (float): Scaled selection coefficient in pop 1 and ancestral pop

  • gamma2 (float): Scaled selection coefficient in pop 2

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

Note
  • DFE methods internally apply make_extrap_func, so there is no need to make it extrapolate again.
  • Selection in contemporary population 1 is assumed to equal that in the ancestral population.
Source code in dadi/DFE/DemogSelModels.py
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
def split_mig_sel(params, ns, pts):
    """
    Instantaneous split into two populations of specified size, with symmetric migration.

    Args:
        params (list): [nu1, nu2, T, m, gamma1, gamma2]

            - nu1 (float): Size of population 1 after split

            - nu2 (float): Size of population 2 after split

            - T (float): Time in the past of split (in units of 2*Na generations)

            - m (float): Migration rate between populations (2*Na*m)

            - gamma1 (float): Scaled selection coefficient in pop 1 and ancestral pop

            - gamma2 (float): Scaled selection coefficient in pop 2

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum

    Note:
        - DFE methods internally apply make_extrap_func, so there is no need to make it extrapolate again.
        - Selection in contemporary population 1 is assumed to equal that in the ancestral population.
    """
    nu1,nu2,T,m,gamma1,gamma2 = params

    xx = Numerics.default_grid(pts)

    phi = PhiManip.phi_1D(xx, gamma=gamma1)
    phi = PhiManip.phi_1D_to_2D(xx, phi)

    phi = Integration.two_pops(phi, xx, T, nu1, nu2, m12=m, m21=m, gamma1=gamma1,
                               gamma2=gamma2)

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

split_mig_sel_single_gamma(params, ns, pts)

split_mig_sel model with selection assumed to be equal in all populations.

Parameters:

Name Type Description Default
params list

[nu1, nu2, T, m, gamma]

  • nu1 (float): Size of population 1 after split

  • nu2 (float): Size of population 2 after split

  • T (float): Time in the past of split (in units of 2*Na generations)

  • m (float): Migration rate between populations (2Nam)

  • gamma (float): Scaled selection coefficient

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

See Also

split_mig_sel for argument definitions, but only a single gamma in params.

Source code in dadi/DFE/DemogSelModels.py
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
def split_mig_sel_single_gamma(params, ns, pts):
    """
    split_mig_sel model with selection assumed to be equal in all populations.

    Args:
        params (list): [nu1, nu2, T, m, gamma]

            - nu1 (float): Size of population 1 after split

            - nu2 (float): Size of population 2 after split

            - T (float): Time in the past of split (in units of 2*Na generations)

            - m (float): Migration rate between populations (2*Na*m)

            - gamma (float): Scaled selection coefficient

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum

    See Also:
        split_mig_sel for argument definitions, but only a single gamma in params.
    """
    nu1,nu2,T,m,gamma = params
    return split_mig_sel([nu1,nu2,T,m,gamma,gamma], ns, pts)

three_epoch_sel(params, ns, pts)

Three epoch model with selection.

Parameters:

Name Type Description Default
params list

[nuB, nuF, TB, TF, gamma]

  • 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)

  • gamma (float): Scaled selection coefficient

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

Source code in dadi/DFE/DemogSelModels.py
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
def three_epoch_sel(params, ns, pts):
    """
    Three epoch model with selection.

    Args:
        params (list): [nuB, nuF, TB, TF, gamma]

            - 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)

            - gamma (float): Scaled selection coefficient

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum
    """
    nuB,nuF,TB,TF,gamma = params

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

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

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

two_epoch_sel(params, ns, pts)

Instantaneous population size change, plus selection.

Parameters:

Name Type Description Default
params list

[nu, T, gamma]

  • nu (float): Final population size

  • T (float): Time of size change

  • gamma (float): Scaled selection coefficient

required
ns list

Sample sizes

required
pts int

Grid point settings for integration

required

Returns:

Name Type Description
fs Spectrum

Resulting frequency spectrum

Note

DFE methods internally apply make_extrap_func, so there is no need to make it extrapolate again.

Source code in dadi/DFE/DemogSelModels.py
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
58
59
60
def two_epoch_sel(params, ns, pts):
    """
    Instantaneous population size change, plus selection.

    Args:
        params (list): [nu, T, gamma]

            - nu (float): Final population size

            - T (float): Time of size change

            - gamma (float): Scaled selection coefficient

        ns (list): Sample sizes
        pts (int): Grid point settings for integration

    Returns:
        fs (Spectrum): Resulting frequency spectrum

    Note:
        DFE methods internally apply make_extrap_func, so there is no need to make it extrapolate again.
    """
    nu, T, gamma = params
    xx = Numerics.default_grid(pts)
    phi = PhiManip.phi_1D(xx, gamma=gamma)
    phi = Integration.one_pop(phi, xx, T, nu, gamma=gamma)
    fs = Spectrum.from_phi(phi, ns, (xx,))
    return fs