Welcome to fwdpy11’s documentation!

fwdpy11

class fwdpy11.ConstantS(beg, end, weight, s, h=1.0, coupled=True, label=0, scaling=1)

Bases: fwdpy11._regions.Sregion

Constant/fixed selection coefficient

Attributes:
  • b: the beginning of the region
  • e: the end of the region
  • w: the “weight” assigned to the region
  • s: the selection coefficient
  • h: the dominance term
  • l: A label assigned to the region.
    Labels must be integers, and can be used to ‘tag’ mutations arising in different regions.
  • scaling: The scaling of the distrubution.

See fwdpy11.wright_fisher.evolve() for how this class may be used to parameterize a simulation

__init__(beg, end, weight, s, h=1.0, coupled=True, label=0, scaling=1)

Constructor

Parameters:
  • beg – the beginning of the region
  • end – the end of the region
  • weight – the weight to assign
  • s – the selection coefficient
  • h – the dominance
  • coupled – if True, the weight is converted to (end-beg)*weight
  • label – Not relevant to recombining regions. Otherwise, this value will be used to take mutations from this region.
  • scaling – The scaling of the DFE

When coupled is True, the “weight” may be interpreted as a “per base pair” (or per unit, generally speaking) term.

Example:

#A simple case
import fwdpy11
#s = -0.1 and h = 0
constantS = fwdpy11.ConstantS(0,1,1,-0.1,0)
b

Beginning of a region

c

If weight is coupled to end-beg. (boolean)

callback()

Return the C++ callback associated with this Sregion.

des

Distribution of effect sizes.

e

End of a region

h

Dominance (h)

l

Region label.

s

Effect size.

scaling

Scaling term for the DFE

w

Weight on a region.

class fwdpy11.DiploidGenotype

Bases: pybind11_builtins.pybind11_object

Diploid data type for a single (usually contiguous) genomic region

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11.fwdpy11_types.DiploidGenotype) -> None
  2. __init__(self: fwdpy11.fwdpy11_types.DiploidGenotype, arg0: int, arg1: int) -> None
first

Key to first gamete. (read-only)

second

Key to second gamete. (read-only)

class fwdpy11.DiploidMetadata

Bases: pybind11_builtins.pybind11_object

Diploid meta data.

__init__

Initialize self. See help(type(self)) for accurate signature.

deme

Deme.

e

Random component of trait value.

g

Genetic value.

geography

Array containing the geographic location of the individual.

label

Index of the individual in the population.

parents

Array containing the label fields of the parents.

sex

Sex.

w

Fitness.

class fwdpy11.ExpS(beg, end, weight, mean, h=1.0, coupled=True, label=0, scaling=1)

Bases: fwdpy11._regions.Sregion

Exponential distribution on selection coefficients

Attributes:
  • b: the beginning of the region
  • e: the end of the region
  • w: the “weight” assigned to the region
  • mean: the mean selection coefficient
  • h: the dominance term
  • l: A label assigned to the region.
    Labels must be integers, and can be used to ‘tag’ mutations arising in different regions.
  • scaling: The scaling of the distrubution.

See fwdpy11.wright_fisher.evolve() for how this class may be used to parameterize a simulation

__init__(beg, end, weight, mean, h=1.0, coupled=True, label=0, scaling=1)

Constructor

Parameters:
  • beg – the beginning of the region
  • end – the end of the region
  • weight – the weight to assign
  • mean – the mean selection coefficient
  • h – the dominance
  • coupled – if True, the weight is converted to (end-beg)*weight
  • label – Not relevant to recombining regions. Otherwise, this value will be used to take mutations from this region.
  • scaling – The scaling of the DFE

When coupled is True, the “weight” may be interpreted as a “per base pair” (or per unit, generally speaking) term.

Example:

#A simple case
import fwdpy11
#s is exp(-0.1) and recessive
expS = fwdpy11.ExpS(0,1,1,-0.1,0)
b

Beginning of a region

c

If weight is coupled to end-beg. (boolean)

callback()

Return the C++ callback associated with this Sregion.

des

Distribution of effect sizes.

e

End of a region

h

Dominance (h)

l

Region label.

mean

Mean of the distribution

scaling

Scaling term for the DFE

w

Weight on a region.

class fwdpy11.GSLrng

Bases: pybind11_builtins.pybind11_object

Random number generator based on GNU Scientific Library mersenne twister.

__init__(self: fwdpy11._gslrng.GSLrng, arg0: int) → None

Constructor takes unsigned integer as a seed

class fwdpy11.Gamete

Bases: pybind11_builtins.pybind11_object

A gamete. This object represents a haplotype in a contiguous genomic region.

__init__(self: fwdpy11.fwdpp_types.Gamete, arg0: Tuple[int, fwdpy11.fwdpp_types.VecUint32, fwdpy11.fwdpp_types.VecUint32]) → None

Construct gamete from tuple.

The tuple must be (n, mutations, smutations)

import fwdpy11
# Note the cast that is needed: 
g = fwdpy11.Gamete((1,
                    fwdpy11.VecUint32([2]),
                    fwdpy11.VecUint32([0])))
print(g.n)
print(list(g.mutations))
print(list(g.smutations))
1
[2]
[0]
as_dict(self: fwdpy11.fwdpp_types.Gamete) → dict

Return dictionary representaton of the gamete.

mutations

List of keys to neutral mutations. Contains unsigned 32-bit integers corresponding to mutations in the population. (read-only)

n

Number of occurrences in the population. This has little meaning beyond book-keeping used by the C++ back-end. (read-only)

smutations

List of keys to selected mutations. Contains unsigned 32-bit integers corresponding to mutations in the population. (read-only)

class fwdpy11.GammaS(beg, end, weight, mean, shape, h=1.0, coupled=True, label=0, scaling=1)

Bases: fwdpy11._regions.Sregion

Gamma distribution of fitness effects

Attributes:
  • b: the beginning of the region
  • e: the end of the region
  • w: the “weight” assigned to the region
  • mean: mean of the Gamma
  • shape: shape of the Gamma
  • h: the dominance term
  • l: A label assigned to the region.
    Labels must be integers, and can be used to ‘tag’ mutations arising in different regions.
  • scaling: The scaling of the distrubution.

See fwdpy11.wright_fisher.evolve() for how this class may be used to parameterize a simulation

__init__(beg, end, weight, mean, shape, h=1.0, coupled=True, label=0, scaling=1)

Constructor

Parameters:
  • beg – the beginning of the region
  • end – the end of the region
  • weight – the weight to assign
  • mean – the mean selection coefficient
  • shape – the shape parameter of the distribution
  • h – the dominance
  • coupled – if True, the weight is converted to (end-beg)*weight
  • label – Not relevant to recombining regions. Otherwise, this value will be used to take mutations from this region.
  • scaling – The scaling of the DFE

When coupled is True, the “weight” may be interpreted as a “per base pair” (or per unit, generally speaking) term.

Example:

#A simple case
import fwdpy11
gdist = fwdpy11.GammaS(0,1,1,-0.1,0.35)
b

Beginning of a region

c

If weight is coupled to end-beg. (boolean)

callback()

Return the C++ callback associated with this Sregion.

des

Distribution of effect sizes.

e

End of a region

h

Dominance (h)

l

Region label.

mean

Mean of the distribution.

scaling

Scaling term for the DFE

shape

Shape parameter.

w

Weight on a region.

class fwdpy11.GaussianS(beg, end, weight, sd, h=1.0, coupled=True, label=0, scaling=1)

Bases: fwdpy11._regions.Sregion

Gaussian distribution on selection coefficients (effect sizes for sims of quantitative traits)

Attributes:
  • b: the beginning of the region
  • e: the end of the region
  • w: the “weight” assigned to the region
  • sd: the standard deviation
  • h: the dominance term
  • l: A label assigned to the region.
    Labels must be integers, and can be used to ‘tag’ mutations arising in different regions.
  • scaling: The scaling of the distrubution.

The mean is zero.

See fwdpy11.wright_fisher.evolve() for how this class may be used to parameterize a simulation

__init__(beg, end, weight, sd, h=1.0, coupled=True, label=0, scaling=1)

Constructor

Parameters:
  • beg – the beginning of the region
  • end – the end of the region
  • weight – the weight to assign
  • sd – standard deviation of effect sizes
  • h – the dominance
  • coupled – if True, the weight is converted to (end-beg)*weight
  • label – Not relevant to recombining regions. Otherwise, this value will be used to take mutations from this region.
  • scaling – The scaling of the DFE

When coupled is True, the “weight” may be interpreted as a “per base pair” (or per unit, generally speaking) term.

Example:

#A simple case
import fwdpy11
#s N(0,0.1) and co-dominant
gaussianS = fwdpy11.GaussianS(0,1,1,0.1,1)
b

Beginning of a region

c

If weight is coupled to end-beg. (boolean)

callback()

Return the C++ callback associated with this Sregion.

des

Distribution of effect sizes.

e

End of a region

h

Dominance (h)

l

Region label.

scaling

Scaling term for the DFE

sd

Standard deviation of the distribution

w

Weight on a region.

class fwdpy11.MlocusPop

Bases: fwdpy11._Populations._MlocusPop

Representation of a multi-locus system.

N

Current population size.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11._Populations._MlocusPop, N: int, locus_boundaries: List[Tuple[float, float]], length: float=1.7976931348623157e+308) -> None

  2. __init__(self: fwdpy11._Populations._MlocusPop, diploids: fwdpy11._opaque_diploids.VecVecDiploid, gametes: fwdpy11._opaque_gametes.VecGamete, mutations: fwdpy11._opaque_mutations.VecMutation, locus_boundaries: List[Tuple[float, float]]) -> None

    Construct with tuple of (diploids, gametes, mutations).

    New in version 0.1.4.

  3. __init__(self: fwdpy11._Populations._MlocusPop, arg0: fwdpy11._Populations._MlocusPop) -> None

    Copy constructor.

    New in version 0.1.4.

add_mutations(self: fwdpy11._Populations._MlocusPop, arg0: fwdpy11._opaque_mutations.VecMutation, arg1: List[int], arg2: List[int]) → List[int]
ancient_sample_metadata

Container of metadata for ancient samples.

ancient_sample_records

Container of time and node data for ancient samples

clear(self: fwdpy11._Populations._MlocusPop) → None

Clears all population data.

static create(diploids, gametes, mutations, locus_boundaries, *args)

Create a new object from input data. Unlike the constructor method, this method results in no temporary copies of input data.

Parameters:
Return type:

fwdpy11.MlocusPop

See Construction of population objects from a predetermined state for example use.

When passing in extra args, they must be the following:

fixations: A fwdpy11.VecMutation fixation times: A fwdpy11.VecUint32 generation: A non-negative integer

It is required that len(fixations) == len(fixation times).

The result of passing in these extra args will be an object with its fixation data populated and its generation set to the input value.

New in version 0.1.4.

diploid_metadata

Container of diploid metadata.

diploids

A fwdpy11.VecVecDiploid.

dump_to_file(self: fwdpy11._Populations._MlocusPop, arg0: str) → None

Write a population to a file in binary format.

find_fixation_by_key(self: fwdpy11._Population.Population, pop: Tuple[float, float, int], offset: int=0) → int

Find a fixation by key.

Parameters:
  • key (tuple) – A mutation key. See fwdpy11.Mutation.key().
  • offset (int) – Offset to start search in fixation container.
Return type:

int

Returns:

Index of fixation if found, or -1 otherwise.

New in version 0.2.0.

find_mutation_by_key(self: fwdpy11._Population.Population, pop: Tuple[float, float, int], offset: int=0) → int

Find a mutation by key.

Parameters:
  • key (tuple) – A mutation key. See fwdpy11.Mutation.key().
  • offset (int) – Offset to start search in mutation container.
Return type:

int

Returns:

Index of mutation if found, or -1 otherwise.

New in version 0.2.0.

fixation_times

A list of fixation times corresponding to the elements in “fixations” for this type.

fixations

A fwdpy11.VecMutation of fixed variants.

gametes

A fwdpy11.VecGamete.

generation

Curent generation.

load_from_file(arg0: str) → fwdpy11._Populations._MlocusPop

Load a population from a binary file.

locus_boundaries

List of [start,stop) positions of each locus.

mcounts

List of number of occurrences of elements in a population objecst “mutations” container.

The values are unsigned 32-bit integers.

Note

Some values may be 0. These represent extinct variants. You will typically want to avoid processing such mutations.

mut_lookup

Mutation position lookup table. The format is a dict whose keys are mutation positions and values are lists of indexes. If no extant mutations are present in the population, the value of this property is None.

mutation_indexes(self: fwdpy11._Population.Population, pos: float) → object

Get indexes associated with a mutation position.

Parameters:pos (float) – A position
Returns:Indexes in mutation/mutation counts container associated with pos.
Return type:object

Returns None if pos does not refer to an extant variant. Otherwise, returns a list.

mutations

List of fwdpy11.Mutation.

Note

This list contains both extinct and extant mutations. To distinguish them, use the locations of nonzero values in “mcounts” for an instance of this type.”

sample(*args, **kwargs)

Overloaded function.

  1. sample(self: fwdpy11._Populations._MlocusPop, individuals: List[int], haplotype: bool=True, remove_fixed: bool=True) -> fwdpy11.sampling.DataMatrix

    Return a sample from a population.

    param individuals:
     Indexes of individuals in the sample
    type individuals:
     list
    param haplotype:
     (True) Determines the encoding of the return type
    type haplotype:bool
    param remove_fixed:
     (True) Remove fixed variants from the sample
    type remove_fixed:
     bool
    returns:A haplotype matrix if haplotype is True. Otherwise, a genotype matrix.
    rtype:fwdpy11.sampling.DataMatrix

    New in version 0.1.4.

    Changed in version 0.2.0: Change to an overloaded function returning a fwdpy11.sampling.DataMatrix instead of the “classic libsequence” layout.

  2. sample(self: fwdpy11._Populations._MlocusPop, rng: fwdpy11._gslrng.GSLrng, nsam: int, haplotype: bool=True, remove_fixed: bool=True) -> fwdpy11.sampling.DataMatrix

    Return a sample from a population.

    param rng:Random number generator
    type rng:fwdpy11.GSLrng
    param nsam:The sample size
    type nsam:int
    param haplotype:
     (True) Determines the encoding of the return type
    type haplotype:bool
    param remove_fixed:
     (True) Remove fixed variants from the sample
    type remove_fixed:
     bool
    returns:A haplotype matrix if haplotype is True. Otherwise, a genotype matrix.
    rtype:fwdpy11.sampling.DataMatrix

    New in version 0.1.4.

    Changed in version 0.2.0: Change to an overloaded function returning a fwdpy11.sampling.DataMatrix instead of the “classic libsequence” layout.

sample_by_locus(self: fwdpy11._Populations._MlocusPop, individuals: List[int], remove_fixed: bool=True) → List[fwdpy11.sampling.DataMatrix]

Return one data matrix per locus.

Parameters:
  • individuals (list) – Indexes of the individuals in the sample
  • remove_fixed (bool) – (True) Remove fixed variants from the sample
Returns:

A list of haplotype matrix

Return type:

list

This function differs from fwdpy11.MlocusPop.sample() in that a list of fwdpy11.sampling.DataMatrix are returned. The positional boundaries of each matrix are given by fwdpy11.MlocusPop.locus_boundaries.

New in version 0.2.0.

tables

Give access to the population’s fwdpy11.ts.TableCollection

class fwdpy11.Mutation

Bases: fwdpy11.fwdpp_types.MutationBase

Mutation with effect size and dominance

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11.fwdpy11_types.Mutation, pos: float, s: float, h: float, g: int, label: int) -> None

    Construct a mutations.

    param pos:Mutation position (float)
    param s:Effect size (float)
    param h:Dominance term (float)
    param g:Origin time (unsigned integer)
    param label:Label (16 bit integer)
    import fwdpy11
    m = fwdpy11.Mutation(1.0, -1.0, 0.25, 0, 0)
    print(m.pos)
    print(m.s)
    print(m.h)
    print(m.g)
    print(m.label)
    
    1.0
    -1.0
    0.25
    0
    0
    
  2. __init__(self: fwdpy11.fwdpy11_types.Mutation, pos: float, s: float, h: float, g: int, esizes: list, heffects: list, label: int) -> None

    Construct a mutation with both a constant effect and/or a vector of effects.

    param pos:Mutation position (float)
    param s:Effect size (float)
    param h:Dominance term (float)
    param g:Origin time (unsigned integer)
    param esizes:List of effect sizes (list of float)
    param heffects:List of heterozygous effects (list of float)
    param label:Label (16 bit integer)

    New in version 0.2.0.

  3. __init__(self: fwdpy11.fwdpy11_types.Mutation, arg0: Tuple[float, float, float, int, int]) -> None

    Construct mutation from a tuple.

    The tuple should contain (pos, s, h, g, label)

    import fwdpy11
    m = fwdpy11.Mutation((1.0, -1.0, 0.25, 0, 0))
    print(m.pos)
    print(m.s)
    print(m.h)
    print(m.g)
    print(m.label)
    
    1.0
    -1.0
    0.25
    0
    0
    
esizes

Vector of effect sizes.

New in version 0.2.0.

g

Generation when mutation arose (origination time). (read-only)

h

Dominance/effect in heterozygotes. (read-only)

heffects

Vector of heterozygous effects.

New in version 0.2.0.

key

It is often useful to have a unique key for tracking mutations. This property returns the tuple (pos, esize, origin).

New in version 0.1.3.a1.

label

A 16-bit unsigned integer that can be used for adding “meta-data” to mutations

neutral

Boolean

pos

Position (float).

s

Selection coefficient/effect size. (read-only)

class fwdpy11.MutationBase

Bases: pybind11_builtins.pybind11_object

Base class for mutations.

__init__(self: fwdpy11.fwdpp_types.MutationBase, arg0: float, arg1: bool, arg2: int) → None

Constructor

label

A 16-bit unsigned integer that can be used for adding “meta-data” to mutations

neutral

Boolean

pos

Position (float).

class fwdpy11.Population

Bases: pybind11_builtins.pybind11_object

Abstract base class for populations based on fwdpy11.Mutation

N

Current population size.

__init__

Initialize self. See help(type(self)) for accurate signature.

ancient_sample_metadata

Container of metadata for ancient samples.

ancient_sample_records

Container of time and node data for ancient samples

diploid_metadata

Container of diploid metadata.

find_fixation_by_key(self: fwdpy11._Population.Population, pop: Tuple[float, float, int], offset: int=0) → int

Find a fixation by key.

Parameters:
  • key (tuple) – A mutation key. See fwdpy11.Mutation.key().
  • offset (int) – Offset to start search in fixation container.
Return type:

int

Returns:

Index of fixation if found, or -1 otherwise.

New in version 0.2.0.

find_mutation_by_key(self: fwdpy11._Population.Population, pop: Tuple[float, float, int], offset: int=0) → int

Find a mutation by key.

Parameters:
  • key (tuple) – A mutation key. See fwdpy11.Mutation.key().
  • offset (int) – Offset to start search in mutation container.
Return type:

int

Returns:

Index of mutation if found, or -1 otherwise.

New in version 0.2.0.

fixation_times

A list of fixation times corresponding to the elements in “fixations” for this type.

fixations

A fwdpy11.VecMutation of fixed variants.

gametes

A fwdpy11.VecGamete.

generation

Curent generation.

mcounts

List of number of occurrences of elements in a population objecst “mutations” container.

The values are unsigned 32-bit integers.

Note

Some values may be 0. These represent extinct variants. You will typically want to avoid processing such mutations.

mut_lookup

Mutation position lookup table. The format is a dict whose keys are mutation positions and values are lists of indexes. If no extant mutations are present in the population, the value of this property is None.

mutation_indexes(self: fwdpy11._Population.Population, pos: float) → object

Get indexes associated with a mutation position.

Parameters:pos (float) – A position
Returns:Indexes in mutation/mutation counts container associated with pos.
Return type:object

Returns None if pos does not refer to an extant variant. Otherwise, returns a list.

mutations

List of fwdpy11.Mutation.

Note

This list contains both extinct and extant mutations. To distinguish them, use the locations of nonzero values in “mcounts” for an instance of this type.”

tables

Give access to the population’s fwdpy11.ts.TableCollection

class fwdpy11.Region(beg, end, weight, coupled=True, label=0)

Bases: object

Representation of a “region” in a simulation.

Attributes:
  • b: the beginning of the region
  • e: the end of the region
  • w: the “weight” assigned to the region
  • l: A label assigned to the region. Labels must be integers,
    and can be used to ‘tag’ mutations arising in different regions.
See fwdpy11.wright_fisher.evolve() for how this class may be used to
parameterize a simulation.
This class is extended by:
__init__(beg, end, weight, coupled=True, label=0)

Constructor

Parameters:
  • beg – the beginning of the region
  • end – the end of the region
  • weight – the weight to assign
  • coupled – if True, the weight is converted to (end-beg)*weight
  • label – Not relevant to recombining regions. Otherwise, this value will be used to take mutations from this region.

When coupled is True, the “weight” may be interpreted as a “per base pair” (or per unit, generally speaking) term.

Example:

#A simple case
import fwdpy11
r = fwdpy11.Region(0,1,1)
#A more "biological" case:
#  The region covers positions 1 through 1,000,
#  and the per-base pair "weight" is 1e-5:
r = fwdpy11.Region(1,1000,1e-5,True)
b

Beginning of a region

c

If weight is coupled to end-beg. (boolean)

e

End of a region

l

Region label.

w

Weight on a region.

class fwdpy11.SlocusPop

Bases: fwdpy11._Populations._SlocusPop

Population object representing a single locus.

N

Current population size.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11._Populations._SlocusPop, N: int, length: float=1.7976931348623157e+308) -> None

Construct with an unsigned integer representing the initial population size.

  1. __init__(self: fwdpy11._Populations._SlocusPop, diploids: fwdpy11._opaque_diploids.VecDiploid, gametes: fwdpy11._opaque_gametes.VecGamete, mutations: fwdpy11._opaque_mutations.VecMutation) -> None

    Construct with tuple of (diploids, gametes, mutations).

    New in version 0.1.4.

  2. __init__(self: fwdpy11._Populations._SlocusPop, arg0: fwdpy11._Populations._SlocusPop) -> None

    Copy constructor

    New in version 0.1.4.

add_mutations(self: fwdpy11._Populations._SlocusPop, arg0: fwdpy11._opaque_mutations.VecMutation, arg1: List[int], arg2: List[int]) → List[int]
ancient_sample_metadata

Container of metadata for ancient samples.

ancient_sample_records

Container of time and node data for ancient samples

clear(self: fwdpy11._Populations._SlocusPop) → None

Clears all population data.

static create(diploids, gametes, mutations, *args)

Create a new object from input data. Unlike the constructor method, this method results in no temporary copies of input data.

Parameters:
Return type:

fwdpy11.SlocusPop

See Construction of population objects from a predetermined state for example use.

When passing in extra args, they must be the following:

fixations: A fwdpy11.VecMutation fixation times: A fwdpy11.VecUint32 generation: A non-negative integer

It is required that len(fixations) == len(fixation times).

The result of passing in these extra args will be an object with its fixation data populated and its generation set to the input value.

New in version 0.1.4.

static create_from_msprime(ts)

Create a new object from an msprime.TreeSequence

Parameters:ts (msprime.TreeSequence) – A tree sequence from msprime
Return type:fwdpy11.SlocusPop
Returns:A population object with an initialized

fwdpy11.ts.TableCollection

New in version 0.2.0.

Note

In general, initializing a population using the output from a coalescent simulation is a tricky business. There are issues of parameter scaling and the appropriateness of the coalescent model itself. A key issue is that your input tree sequence must have node times in the correct time units! (Generations, for example.) See Tree sequence recording for more discussion

diploid_metadata

Container of diploid metadata.

diploids

A fwdpy11.VecDiploid.

dump_tables_to_msprime()

Dump the population’s TableCollection into an msprime TreeSequence

Return type:msprime.TreeSequence

Todo

Incorporate the various metadata values.

dump_to_file(self: fwdpy11._Populations._SlocusPop, arg0: str) → None

Write a population to a file in binary format.

find_fixation_by_key(self: fwdpy11._Population.Population, pop: Tuple[float, float, int], offset: int=0) → int

Find a fixation by key.

Parameters:
  • key (tuple) – A mutation key. See fwdpy11.Mutation.key().
  • offset (int) – Offset to start search in fixation container.
Return type:

int

Returns:

Index of fixation if found, or -1 otherwise.

New in version 0.2.0.

find_mutation_by_key(self: fwdpy11._Population.Population, pop: Tuple[float, float, int], offset: int=0) → int

Find a mutation by key.

Parameters:
  • key (tuple) – A mutation key. See fwdpy11.Mutation.key().
  • offset (int) – Offset to start search in mutation container.
Return type:

int

Returns:

Index of mutation if found, or -1 otherwise.

New in version 0.2.0.

fixation_times

A list of fixation times corresponding to the elements in “fixations” for this type.

fixations

A fwdpy11.VecMutation of fixed variants.

gametes

A fwdpy11.VecGamete.

generation

Curent generation.

load_from_file(arg0: str) → fwdpy11._Populations._SlocusPop

Load a population from a binary file.

mcounts

List of number of occurrences of elements in a population objecst “mutations” container.

The values are unsigned 32-bit integers.

Note

Some values may be 0. These represent extinct variants. You will typically want to avoid processing such mutations.

mut_lookup

Mutation position lookup table. The format is a dict whose keys are mutation positions and values are lists of indexes. If no extant mutations are present in the population, the value of this property is None.

mutation_indexes(self: fwdpy11._Population.Population, pos: float) → object

Get indexes associated with a mutation position.

Parameters:pos (float) – A position
Returns:Indexes in mutation/mutation counts container associated with pos.
Return type:object

Returns None if pos does not refer to an extant variant. Otherwise, returns a list.

mutations

List of fwdpy11.Mutation.

Note

This list contains both extinct and extant mutations. To distinguish them, use the locations of nonzero values in “mcounts” for an instance of this type.”

sample(*args, **kwargs)

Overloaded function.

  1. sample(self: fwdpy11._Populations._SlocusPop, individuals: List[int], haplotype: bool=True, remove_fixed: bool=True) -> fwdpy11.sampling.DataMatrix

    Return a sample from a population.

    param individuals:
     Indexes of individuals in the sample
    type individuals:
     list
    param haplotype:
     (True) Determines the encoding of the return type
    type haplotype:bool
    param remove_fixed:
     (True) Remove fixed variants from the sample
    type remove_fixed:
     bool
    returns:A haplotype matrix if haplotype is True. Otherwise, a genotype matrix.
    rtype:fwdpy11.sampling.DataMatrix

    New in version 0.1.4.

    Changed in version 0.2.0: Change to an overloaded function returning a fwdpy11.sampling.DataMatrix instead of the “classic libsequence” layout.

  2. sample(self: fwdpy11._Populations._SlocusPop, rng: fwdpy11._gslrng.GSLrng, nsam: int, haplotype: bool=True, remove_fixed: bool=True) -> fwdpy11.sampling.DataMatrix

    Return a sample from a population.

    param rng:Random number generator
    type rng:fwdpy11.GSLrng
    param nsam:The sample size
    type nsam:int
    param haplotype:
     (True) Determines the encoding of the return type
    type haplotype:bool
    param remove_fixed:
     (True) Remove fixed variants from the sample
    type remove_fixed:
     bool
    returns:A haplotype matrix if haplotype is True. Otherwise, a genotype matrix.
    rtype:fwdpy11.sampling.DataMatrix

    New in version 0.1.4.

    Changed in version 0.2.0: Change to an overloaded function returning a fwdpy11.sampling.DataMatrix instead of the “classic libsequence” layout.

tables

Give access to the population’s fwdpy11.ts.TableCollection

class fwdpy11.Sregion(beg, end, weight, h=1.0, coupled=True, label=0, scaling=1)

Bases: fwdpy11._regions.Region

Representation of a “region” in a simulation with a dominance term.

This class is the base class for a general set of objects representing distributions of fitness effects.

Attributes:
  • b: the beginning of the region
  • e: the end of the region
  • w: the “weight” assigned to the region
  • h: the dominance term
  • l: A label assigned to the region.
    Labels must be integers, and can be used to ‘tag’ mutations arising in different regions.
  • scaling: The scaling of the distrubution. See note below.

See fwdpy11.wright_fisher.evolve() for how this class may be used to parameterize a simulation.

Note

This class cannot be used directly to parameterize a simulation.
Rather, you must use a derived type that specifies a distribution of fitness effects. These types include:

fwdpy11.ConstantS, fwdpy11.UniformS, fwdpy11.ExpS, fwdpy11.GammaS, and fwdpy11.GaussianS

Note

The scaling of a distribution refers to the distribution of effect sizes. For example, if scaling = 1.0, then the DFE is on the effect size itself. If scaling = 2N (where N is the population size), then the DFE is on 2Ns. If N is not constant during a simulation, then the scaling is with respect to some “reference” population size.

Changed in version 0.13.a2: Added “scaling” attribute.

__init__(beg, end, weight, h=1.0, coupled=True, label=0, scaling=1)

Constructor

Parameters:
  • beg – the beginning of the region
  • end – the end of the region
  • weight – the weight to assign
  • h – the dominance
  • coupled – if True, the weight is converted to (end-beg)*weight
  • label – Not relevant to recombining regions. Otherwise, this value will be used to take mutations from this region.
  • scaling – The scaling of the DFE

When coupled is True, the “weight” may be interpreted as a “per base pair” (or per unit, generally speaking) term.

Example:

#A simple case
import fwdpy11
#Examples for models where the 3 genotype fitnesses are
#1, 1+sh, and 1+2s, respectively
recessive = fwdpy11.Sregion(0,1,1,0)
additive = fwdpy11.Sregion(0,1,1,1.0)
dominant = fwdpy11.Sregion(0,1,1,2.0)
b

Beginning of a region

c

If weight is coupled to end-beg. (boolean)

callback()

Return the C++ callback associated with this Sregion.

des

Distribution of effect sizes.

e

End of a region

h

Dominance (h)

l

Region label.

scaling

Scaling term for the DFE

w

Weight on a region.

class fwdpy11.UniformS(beg, end, weight, lo, hi, h=1.0, coupled=True, label=0, scaling=1)

Bases: fwdpy11._regions.Sregion

Uniform distribution on selection coefficients

Attributes:
  • b: the beginning of the region
  • e: the end of the region
  • w: the “weight” assigned to the region
  • lo: the lower bound on s
  • hi: the upper bound on s
  • h: the dominance term
  • l: A label assigned to the region.
    Labels must be integers, and can be used to ‘tag’ mutations arising in different regions.
  • scaling: The scaling of the distrubution.

See fwdpy11.wright_fisher.evolve() for how this class may be used to parameterize a simulation

__init__(beg, end, weight, lo, hi, h=1.0, coupled=True, label=0, scaling=1)

Constructor

Parameters:
  • beg – the beginning of the region
  • end – the end of the region
  • weight – the weight to assign
  • lo – lower bound on s
  • hi – upper bound on s
  • h – the dominance
  • coupled – if True, the weight is converted to (end-beg)*weight
  • label – Not relevant to recombining regions. Otherwise, this value will be used to take mutations from this region.
  • scaling – The scaling of the DFE

When coupled is True, the “weight” may be interpreted as a “per base pair” (or per unit, generally speaking) term.

Example:

#A simple case
import fwdpy11
#s is uniform on [-1, 0]
uniformS = fwdpy11.UniformS(0,1,1,-1,0,0)
b

Beginning of a region

c

If weight is coupled to end-beg. (boolean)

callback()

Return the C++ callback associated with this Sregion.

des

Distribution of effect sizes.

e

End of a region

h

Dominance (h)

hi

Hi value for effect size.

l

Region label.

lo

Lo value for effect size.

scaling

Scaling term for the DFE

w

Weight on a region.

class fwdpy11.VecAncientSampleRecords

Bases: pybind11_builtins.pybind11_object

Container of records for ancient samples.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11._opaque_diploids.VecAncientSampleRecords, arg0: buffer) -> None
  2. __init__(self: fwdpy11._opaque_diploids.VecAncientSampleRecords) -> None
  3. __init__(self: fwdpy11._opaque_diploids.VecAncientSampleRecords, arg0: fwdpy11._opaque_diploids.VecAncientSampleRecords) -> None

Copy constructor

  1. __init__(self: fwdpy11._opaque_diploids.VecAncientSampleRecords, arg0: iterable) -> None
append(self: fwdpy11._opaque_diploids.VecAncientSampleRecords, x: fwdpy11::ancient_sample_record) → None

Add an item to the end of the list

extend(self: fwdpy11._opaque_diploids.VecAncientSampleRecords, L: fwdpy11._opaque_diploids.VecAncientSampleRecords) → None

Extend the list by appending all the items in the given list

insert(self: fwdpy11._opaque_diploids.VecAncientSampleRecords, i: int, x: fwdpy11::ancient_sample_record) → None

Insert an item at a given position.

pop(*args, **kwargs)

Overloaded function.

  1. pop(self: fwdpy11._opaque_diploids.VecAncientSampleRecords) -> fwdpy11::ancient_sample_record

Remove and return the last item

  1. pop(self: fwdpy11._opaque_diploids.VecAncientSampleRecords, i: int) -> fwdpy11::ancient_sample_record

Remove and return the item at index i

class fwdpy11.VecDiploid

Bases: pybind11_builtins.pybind11_object

C++ representation of a list of fwdpy11.DiploidGenotype. Typically, access will be read-only.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11._opaque_diploids.VecDiploid, arg0: buffer) -> None
  2. __init__(self: fwdpy11._opaque_diploids.VecDiploid) -> None
  3. __init__(self: fwdpy11._opaque_diploids.VecDiploid, arg0: fwdpy11._opaque_diploids.VecDiploid) -> None

Copy constructor

  1. __init__(self: fwdpy11._opaque_diploids.VecDiploid, arg0: iterable) -> None
append(self: fwdpy11._opaque_diploids.VecDiploid, x: fwdpy11::DiploidGenotype) → None

Add an item to the end of the list

count(self: fwdpy11._opaque_diploids.VecDiploid, x: fwdpy11::DiploidGenotype) → int

Return the number of times x appears in the list

extend(self: fwdpy11._opaque_diploids.VecDiploid, L: fwdpy11._opaque_diploids.VecDiploid) → None

Extend the list by appending all the items in the given list

insert(self: fwdpy11._opaque_diploids.VecDiploid, i: int, x: fwdpy11::DiploidGenotype) → None

Insert an item at a given position.

pop(*args, **kwargs)

Overloaded function.

  1. pop(self: fwdpy11._opaque_diploids.VecDiploid) -> fwdpy11::DiploidGenotype

Remove and return the last item

  1. pop(self: fwdpy11._opaque_diploids.VecDiploid, i: int) -> fwdpy11::DiploidGenotype

Remove and return the item at index i

remove(self: fwdpy11._opaque_diploids.VecDiploid, x: fwdpy11::DiploidGenotype) → None

Remove the first item from the list whose value is x. It is an error if there is no such item.

class fwdpy11.VecDiploidMetaData

Bases: pybind11_builtins.pybind11_object

Container of diploid metadata.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11._opaque_diploids.VecDiploidMetaData, arg0: buffer) -> None
  2. __init__(self: fwdpy11._opaque_diploids.VecDiploidMetaData) -> None
  3. __init__(self: fwdpy11._opaque_diploids.VecDiploidMetaData, arg0: fwdpy11._opaque_diploids.VecDiploidMetaData) -> None

Copy constructor

  1. __init__(self: fwdpy11._opaque_diploids.VecDiploidMetaData, arg0: iterable) -> None
append(self: fwdpy11._opaque_diploids.VecDiploidMetaData, x: fwdpy11::DiploidMetadata) → None

Add an item to the end of the list

extend(self: fwdpy11._opaque_diploids.VecDiploidMetaData, L: fwdpy11._opaque_diploids.VecDiploidMetaData) → None

Extend the list by appending all the items in the given list

insert(self: fwdpy11._opaque_diploids.VecDiploidMetaData, i: int, x: fwdpy11::DiploidMetadata) → None

Insert an item at a given position.

pop(*args, **kwargs)

Overloaded function.

  1. pop(self: fwdpy11._opaque_diploids.VecDiploidMetaData) -> fwdpy11::DiploidMetadata

Remove and return the last item

  1. pop(self: fwdpy11._opaque_diploids.VecDiploidMetaData, i: int) -> fwdpy11::DiploidMetadata

Remove and return the item at index i

class fwdpy11.VecGamete

Bases: pybind11_builtins.pybind11_object

C++ representations of a list of fwdpy11.Gamete. Typically, access will be read-only.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11._opaque_gametes.VecGamete) -> None
  2. __init__(self: fwdpy11._opaque_gametes.VecGamete, arg0: fwdpy11._opaque_gametes.VecGamete) -> None

Copy constructor

  1. __init__(self: fwdpy11._opaque_gametes.VecGamete, arg0: iterable) -> None
append(self: fwdpy11._opaque_gametes.VecGamete, x: fwdpy11.fwdpp_types.Gamete) → None

Add an item to the end of the list

count(self: fwdpy11._opaque_gametes.VecGamete, x: fwdpy11.fwdpp_types.Gamete) → int

Return the number of times x appears in the list

extend(self: fwdpy11._opaque_gametes.VecGamete, L: fwdpy11._opaque_gametes.VecGamete) → None

Extend the list by appending all the items in the given list

insert(self: fwdpy11._opaque_gametes.VecGamete, i: int, x: fwdpy11.fwdpp_types.Gamete) → None

Insert an item at a given position.

pop(*args, **kwargs)

Overloaded function.

  1. pop(self: fwdpy11._opaque_gametes.VecGamete) -> fwdpy11.fwdpp_types.Gamete

Remove and return the last item

  1. pop(self: fwdpy11._opaque_gametes.VecGamete, i: int) -> fwdpy11.fwdpp_types.Gamete

Remove and return the item at index i

remove(self: fwdpy11._opaque_gametes.VecGamete, x: fwdpy11.fwdpp_types.Gamete) → None

Remove the first item from the list whose value is x. It is an error if there is no such item.

class fwdpy11.VecMutation

Bases: pybind11_builtins.pybind11_object

C++ representation of a list of fwdpy11.Mutation. Typically, access will be read-only.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11._opaque_mutations.VecMutation) -> None
  2. __init__(self: fwdpy11._opaque_mutations.VecMutation, arg0: fwdpy11._opaque_mutations.VecMutation) -> None

Copy constructor

  1. __init__(self: fwdpy11._opaque_mutations.VecMutation, arg0: iterable) -> None
append(self: fwdpy11._opaque_mutations.VecMutation, x: fwdpy11::Mutation) → None

Add an item to the end of the list

array(self: fwdpy11._opaque_mutations.VecMutation) → std::vector<flattened_Mutation, std::allocator<flattened_Mutation> >
Return type:fwdpy11.VecMutationDtype.

The return value should be coerced into a Numpy array for processing.

count(self: fwdpy11._opaque_mutations.VecMutation, x: fwdpy11::Mutation) → int

Return the number of times x appears in the list

extend(self: fwdpy11._opaque_mutations.VecMutation, L: fwdpy11._opaque_mutations.VecMutation) → None

Extend the list by appending all the items in the given list

insert(self: fwdpy11._opaque_mutations.VecMutation, i: int, x: fwdpy11::Mutation) → None

Insert an item at a given position.

pop(*args, **kwargs)

Overloaded function.

  1. pop(self: fwdpy11._opaque_mutations.VecMutation) -> fwdpy11::Mutation

Remove and return the last item

  1. pop(self: fwdpy11._opaque_mutations.VecMutation, i: int) -> fwdpy11::Mutation

Remove and return the item at index i

remove(self: fwdpy11._opaque_mutations.VecMutation, x: fwdpy11::Mutation) → None

Remove the first item from the list whose value is x. It is an error if there is no such item.

class fwdpy11.VecMutationDtype

Bases: pybind11_builtins.pybind11_object

Vector of the data fields in a ” “fwdpy11.Mutation.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11._opaque_mutations.VecMutationDtype, arg0: buffer) -> None
  2. __init__(self: fwdpy11._opaque_mutations.VecMutationDtype) -> None
  3. __init__(self: fwdpy11._opaque_mutations.VecMutationDtype, arg0: fwdpy11._opaque_mutations.VecMutationDtype) -> None

Copy constructor

  1. __init__(self: fwdpy11._opaque_mutations.VecMutationDtype, arg0: iterable) -> None
append(self: fwdpy11._opaque_mutations.VecMutationDtype, x: flattened_Mutation) → None

Add an item to the end of the list

extend(self: fwdpy11._opaque_mutations.VecMutationDtype, L: fwdpy11._opaque_mutations.VecMutationDtype) → None

Extend the list by appending all the items in the given list

insert(self: fwdpy11._opaque_mutations.VecMutationDtype, i: int, x: flattened_Mutation) → None

Insert an item at a given position.

pop(*args, **kwargs)

Overloaded function.

  1. pop(self: fwdpy11._opaque_mutations.VecMutationDtype) -> flattened_Mutation

Remove and return the last item

  1. pop(self: fwdpy11._opaque_mutations.VecMutationDtype, i: int) -> flattened_Mutation

Remove and return the item at index i

class fwdpy11.VecUint32

Bases: pybind11_builtins.pybind11_object

Vector of unsigned 32-bit integers.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11._Population.VecUint32, arg0: buffer) -> None
  2. __init__(self: fwdpy11._Population.VecUint32) -> None
  3. __init__(self: fwdpy11._Population.VecUint32, arg0: fwdpy11._Population.VecUint32) -> None

Copy constructor

  1. __init__(self: fwdpy11._Population.VecUint32, arg0: iterable) -> None
append(self: fwdpy11._Population.VecUint32, x: int) → None

Add an item to the end of the list

count(self: fwdpy11._Population.VecUint32, x: int) → int

Return the number of times x appears in the list

extend(self: fwdpy11._Population.VecUint32, L: fwdpy11._Population.VecUint32) → None

Extend the list by appending all the items in the given list

insert(self: fwdpy11._Population.VecUint32, i: int, x: int) → None

Insert an item at a given position.

pop(*args, **kwargs)

Overloaded function.

  1. pop(self: fwdpy11._Population.VecUint32) -> int

Remove and return the last item

  1. pop(self: fwdpy11._Population.VecUint32, i: int) -> int

Remove and return the item at index i

remove(self: fwdpy11._Population.VecUint32, x: int) → None

Remove the first item from the list whose value is x. It is an error if there is no such item.

class fwdpy11.VecVecDiploid

Bases: pybind11_builtins.pybind11_object

Vector of fwdpy11.DiploidGenotype.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11._opaque_diploids.VecVecDiploid) -> None
  2. __init__(self: fwdpy11._opaque_diploids.VecVecDiploid, arg0: fwdpy11._opaque_diploids.VecVecDiploid) -> None

Copy constructor

  1. __init__(self: fwdpy11._opaque_diploids.VecVecDiploid, arg0: iterable) -> None
append(self: fwdpy11._opaque_diploids.VecVecDiploid, x: fwdpy11._opaque_diploids.VecDiploid) → None

Add an item to the end of the list

count(self: fwdpy11._opaque_diploids.VecVecDiploid, x: fwdpy11._opaque_diploids.VecDiploid) → int

Return the number of times x appears in the list

extend(self: fwdpy11._opaque_diploids.VecVecDiploid, L: fwdpy11._opaque_diploids.VecVecDiploid) → None

Extend the list by appending all the items in the given list

insert(self: fwdpy11._opaque_diploids.VecVecDiploid, i: int, x: fwdpy11._opaque_diploids.VecDiploid) → None

Insert an item at a given position.

pop(*args, **kwargs)

Overloaded function.

  1. pop(self: fwdpy11._opaque_diploids.VecVecDiploid) -> fwdpy11._opaque_diploids.VecDiploid

Remove and return the last item

  1. pop(self: fwdpy11._opaque_diploids.VecVecDiploid, i: int) -> fwdpy11._opaque_diploids.VecDiploid

Remove and return the item at index i

remove(self: fwdpy11._opaque_diploids.VecVecDiploid, x: fwdpy11._opaque_diploids.VecDiploid) → None

Remove the first item from the list whose value is x. It is an error if there is no such item.

fwdpy11.get_fwdpp_includes()

Returns absolute path to location of the fwdpp headers installed along with fwdpy11.

fwdpy11.get_includes()

Returns absolute path to location of fwdpy11 headers

fwdpy11.minimal_mako()

Returns a minimal mako header for compiling plugins using cppimport

New in version 0.1.1.

fwdpy11._Population

Defines the ABC fwdpy11._Population

class fwdpy11._Population.Population

Bases: pybind11_builtins.pybind11_object

Abstract base class for populations based on fwdpy11.Mutation

N

Current population size.

__init__

Initialize self. See help(type(self)) for accurate signature.

ancient_sample_metadata

Container of metadata for ancient samples.

ancient_sample_records

Container of time and node data for ancient samples

diploid_metadata

Container of diploid metadata.

find_fixation_by_key(self: fwdpy11._Population.Population, pop: Tuple[float, float, int], offset: int=0) → int

Find a fixation by key.

Parameters:
  • key (tuple) – A mutation key. See fwdpy11.Mutation.key().
  • offset (int) – Offset to start search in fixation container.
Return type:

int

Returns:

Index of fixation if found, or -1 otherwise.

New in version 0.2.0.

find_mutation_by_key(self: fwdpy11._Population.Population, pop: Tuple[float, float, int], offset: int=0) → int

Find a mutation by key.

Parameters:
  • key (tuple) – A mutation key. See fwdpy11.Mutation.key().
  • offset (int) – Offset to start search in mutation container.
Return type:

int

Returns:

Index of mutation if found, or -1 otherwise.

New in version 0.2.0.

fixation_times

A list of fixation times corresponding to the elements in “fixations” for this type.

fixations

A fwdpy11.VecMutation of fixed variants.

gametes

A fwdpy11.VecGamete.

generation

Curent generation.

mcounts

List of number of occurrences of elements in a population objecst “mutations” container.

The values are unsigned 32-bit integers.

Note

Some values may be 0. These represent extinct variants. You will typically want to avoid processing such mutations.

mut_lookup

Mutation position lookup table. The format is a dict whose keys are mutation positions and values are lists of indexes. If no extant mutations are present in the population, the value of this property is None.

mutation_indexes(self: fwdpy11._Population.Population, pos: float) → object

Get indexes associated with a mutation position.

Parameters:pos (float) – A position
Returns:Indexes in mutation/mutation counts container associated with pos.
Return type:object

Returns None if pos does not refer to an extant variant. Otherwise, returns a list.

mutations

List of fwdpy11.Mutation.

Note

This list contains both extinct and extant mutations. To distinguish them, use the locations of nonzero values in “mcounts” for an instance of this type.”

tables

Give access to the population’s fwdpy11.ts.TableCollection

class fwdpy11._Population.VecUint32

Bases: pybind11_builtins.pybind11_object

Vector of unsigned 32-bit integers.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11._Population.VecUint32, arg0: buffer) -> None
  2. __init__(self: fwdpy11._Population.VecUint32) -> None
  3. __init__(self: fwdpy11._Population.VecUint32, arg0: fwdpy11._Population.VecUint32) -> None

Copy constructor

  1. __init__(self: fwdpy11._Population.VecUint32, arg0: iterable) -> None
append(self: fwdpy11._Population.VecUint32, x: int) → None

Add an item to the end of the list

count(self: fwdpy11._Population.VecUint32, x: int) → int

Return the number of times x appears in the list

extend(self: fwdpy11._Population.VecUint32, L: fwdpy11._Population.VecUint32) → None

Extend the list by appending all the items in the given list

insert(self: fwdpy11._Population.VecUint32, i: int, x: int) → None

Insert an item at a given position.

pop(*args, **kwargs)

Overloaded function.

  1. pop(self: fwdpy11._Population.VecUint32) -> int

Remove and return the last item

  1. pop(self: fwdpy11._Population.VecUint32, i: int) -> int

Remove and return the item at index i

remove(self: fwdpy11._Population.VecUint32, x: int) → None

Remove the first item from the list whose value is x. It is an error if there is no such item.

fwdpy11._Populations

class fwdpy11._Populations.VecUint32

Bases: pybind11_builtins.pybind11_object

Vector of unsigned 32-bit integers.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11._Populations.VecUint32, arg0: buffer) -> None
  2. __init__(self: fwdpy11._Populations.VecUint32) -> None
  3. __init__(self: fwdpy11._Populations.VecUint32, arg0: fwdpy11._Populations.VecUint32) -> None

Copy constructor

  1. __init__(self: fwdpy11._Populations.VecUint32, arg0: iterable) -> None
append(self: fwdpy11._Populations.VecUint32, x: int) → None

Add an item to the end of the list

count(self: fwdpy11._Populations.VecUint32, x: int) → int

Return the number of times x appears in the list

extend(self: fwdpy11._Populations.VecUint32, L: fwdpy11._Populations.VecUint32) → None

Extend the list by appending all the items in the given list

insert(self: fwdpy11._Populations.VecUint32, i: int, x: int) → None

Insert an item at a given position.

pop(*args, **kwargs)

Overloaded function.

  1. pop(self: fwdpy11._Populations.VecUint32) -> int

Remove and return the last item

  1. pop(self: fwdpy11._Populations.VecUint32, i: int) -> int

Remove and return the item at index i

remove(self: fwdpy11._Populations.VecUint32, x: int) → None

Remove the first item from the list whose value is x. It is an error if there is no such item.

fwdpy11.ts

class fwdpy11.ts.Edge

Bases: pybind11_builtins.pybind11_object

An edge in a tree sequence. An edge represents the transmission of the half-open genomic interval [left,right) from parent to child.

New in version 0.2.0.

__init__

Initialize self. See help(type(self)) for accurate signature.

child

Node id of child

left

Left edge of interval, inclusive.

parent

Node id of parent

right

Right edge of interval, exclusive.

class fwdpy11.ts.EdgeTable

Bases: pybind11_builtins.pybind11_object

An EdgeTable is a container of fwdpy11.ts.Edge.

An EdgeTable supports the Python buffer protocol, allowing data to be viewed in Python as a numpy record array. No copy is made when generating such views.

New in version 0.2.0.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11.ts.EdgeTable, arg0: buffer) -> None
  2. __init__(self: fwdpy11.ts.EdgeTable) -> None
  3. __init__(self: fwdpy11.ts.EdgeTable, arg0: fwdpy11.ts.EdgeTable) -> None

Copy constructor

  1. __init__(self: fwdpy11.ts.EdgeTable, arg0: iterable) -> None
append(self: fwdpy11.ts.EdgeTable, x: fwdpy11.ts.Edge) → None

Add an item to the end of the list

count(self: fwdpy11.ts.EdgeTable, x: fwdpy11.ts.Edge) → int

Return the number of times x appears in the list

extend(self: fwdpy11.ts.EdgeTable, L: fwdpy11.ts.EdgeTable) → None

Extend the list by appending all the items in the given list

insert(self: fwdpy11.ts.EdgeTable, i: int, x: fwdpy11.ts.Edge) → None

Insert an item at a given position.

pop(*args, **kwargs)

Overloaded function.

  1. pop(self: fwdpy11.ts.EdgeTable) -> fwdpy11.ts.Edge

Remove and return the last item

  1. pop(self: fwdpy11.ts.EdgeTable, i: int) -> fwdpy11.ts.Edge

Remove and return the item at index i

remove(self: fwdpy11.ts.EdgeTable, x: fwdpy11.ts.Edge) → None

Remove the first item from the list whose value is x. It is an error if there is no such item.

class fwdpy11.ts.IndexedEdge

Bases: pybind11_builtins.pybind11_object

An edge keyed for efficient traversal of tree sequences.

__init__

Initialize self. See help(type(self)) for accurate signature.

class fwdpy11.ts.MarginalTree

Bases: pybind11_builtins.pybind11_object

A sparse tree representation of a non-recombining genomic segment. See Data structures related to tree sequences for details.

__init__

Initialize self. See help(type(self)) for accurate signature.

leaf_counts

Leaf counts for each node

left

Left edge of genomic interval (inclusive)

left_child

Mapping of current node id to its left child

left_sib

Return the left sibling of the current node

parents

Vector of child -> parent relationships

preserved_leaf_counts

Ancient sample leaf counts for each node

right

Right edge of genomic interval (exclusive

right_child

Mapping of current node id to its right child

right_sib

Return the right sibling of the current node

total_time(self: fwdpy11.ts.MarginalTree, arg0: fwdpy11.ts.NodeTable) → float

Return the sum of branch lengths

class fwdpy11.ts.MutationRecord

Bases: pybind11_builtins.pybind11_object

A mutation entry in a tree sequence. A MutationRecord stores the node ID of the mutation and the index (“key”) of the mutation in the population.

New in version 0.2.0.

__init__

Initialize self. See help(type(self)) for accurate signature.

key

Index of the mutation in the population

node

Node id of the mutation

class fwdpy11.ts.MutationTable

Bases: pybind11_builtins.pybind11_object

An MutationTable is a container of fwdpy11.ts.MutationRecord.

An MutationTable supports the Python buffer protocol, allowing data to be viewed in Python as a numpy record array. No copy is made when generating such views.

New in version 0.2.0.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11.ts.MutationTable, arg0: buffer) -> None
  2. __init__(self: fwdpy11.ts.MutationTable) -> None
  3. __init__(self: fwdpy11.ts.MutationTable, arg0: fwdpy11.ts.MutationTable) -> None

Copy constructor

  1. __init__(self: fwdpy11.ts.MutationTable, arg0: iterable) -> None
append(self: fwdpy11.ts.MutationTable, x: fwdpy11.ts.MutationRecord) → None

Add an item to the end of the list

count(self: fwdpy11.ts.MutationTable, x: fwdpy11.ts.MutationRecord) → int

Return the number of times x appears in the list

extend(self: fwdpy11.ts.MutationTable, L: fwdpy11.ts.MutationTable) → None

Extend the list by appending all the items in the given list

insert(self: fwdpy11.ts.MutationTable, i: int, x: fwdpy11.ts.MutationRecord) → None

Insert an item at a given position.

pop(*args, **kwargs)

Overloaded function.

  1. pop(self: fwdpy11.ts.MutationTable) -> fwdpy11.ts.MutationRecord

Remove and return the last item

  1. pop(self: fwdpy11.ts.MutationTable, i: int) -> fwdpy11.ts.MutationRecord

Remove and return the item at index i

remove(self: fwdpy11.ts.MutationTable, x: fwdpy11.ts.MutationRecord) → None

Remove the first item from the list whose value is x. It is an error if there is no such item.

class fwdpy11.ts.Node

Bases: pybind11_builtins.pybind11_object

A node in a tree sequence.

New in version 0.2.0.

__init__

Initialize self. See help(type(self)) for accurate signature.

population

For models of discrete population structure, this field is the population of the node.

time

Birth time of the node, recorded forwards in time.

class fwdpy11.ts.NodeTable

Bases: pybind11_builtins.pybind11_object

An NodeTable is a container of fwdpy11.ts.Node.

An NodeTable supports the Python buffer protocol, allowing data to be viewed in Python as a numpy record array. No copy is made when generating such views.

New in version 0.2.0.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11.ts.NodeTable, arg0: buffer) -> None
  2. __init__(self: fwdpy11.ts.NodeTable) -> None
  3. __init__(self: fwdpy11.ts.NodeTable, arg0: fwdpy11.ts.NodeTable) -> None

Copy constructor

  1. __init__(self: fwdpy11.ts.NodeTable, arg0: iterable) -> None
append(self: fwdpy11.ts.NodeTable, x: fwdpy11.ts.Node) → None

Add an item to the end of the list

count(self: fwdpy11.ts.NodeTable, x: fwdpy11.ts.Node) → int

Return the number of times x appears in the list

extend(self: fwdpy11.ts.NodeTable, L: fwdpy11.ts.NodeTable) → None

Extend the list by appending all the items in the given list

insert(self: fwdpy11.ts.NodeTable, i: int, x: fwdpy11.ts.Node) → None

Insert an item at a given position.

pop(*args, **kwargs)

Overloaded function.

  1. pop(self: fwdpy11.ts.NodeTable) -> fwdpy11.ts.Node

Remove and return the last item

  1. pop(self: fwdpy11.ts.NodeTable, i: int) -> fwdpy11.ts.Node

Remove and return the item at index i

remove(self: fwdpy11.ts.NodeTable, x: fwdpy11.ts.Node) → None

Remove the first item from the list whose value is x. It is an error if there is no such item.

class fwdpy11.ts.TableCollection

Bases: pybind11_builtins.pybind11_object

A table collection representing a succinct tree sequence.

L

Genome length

__init__

Initialize self. See help(type(self)) for accurate signature.

edges

The fwdpy11.ts.EdgeTable.

genome_length(self: fwdpy11.ts.TableCollection) → float

Return the genome/sequence length.

mutations

The fwdpy11.ts.MutationTable.

nodes

The fwdpy11.ts.NodeTable.

preserved_nodes

List of nodes corresponding to ancient samples.

class fwdpy11.ts.TreeVisitor

Bases: pybind11_builtins.pybind11_object

Allows left-to-right visiting of the marginal trees embedded in a fwdpy11.ts.TableCollection

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11.ts.TreeVisitor, tables: fwdpy11.ts.TableCollection, samples: List[int]) -> None
  2. __init__(self: fwdpy11.ts.TreeVisitor, tables: fwdpy11.ts.TableCollection, samples: List[int], ancient_samples: List[int]) -> None
tree(self: fwdpy11.ts.TreeVisitor) → fwdpy11.ts.MarginalTree

Obtain the current marginal tree as an instance of :class:`fwdpy11.ts.MarginalTree

class fwdpy11.ts.VariantIterator

Bases: pybind11_builtins.pybind11_object

An iterable class for traversing genotypes in a tree sequence.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11.ts.VariantIterator, tables: fwdpy11.ts.TableCollection, mutations: List[fwdpy11::Mutation], samples: List[int]) -> None

    param tables:The table collection
    type tables:fwdpy11.ts.TableCollection
    param mutations:
     Mutation container
    type mutations:fwdpy11.VecMutation
    param samples:Samples list
    type samples:list
  2. __init__(self: fwdpy11.ts.VariantIterator, pop: fwdpy11::PyPopulation<fwdpy11::Mutation, std::vector<fwdpy11::Mutation, std::allocator<fwdpy11::Mutation> >, std::vector<fwdpp::gamete_base<fwdpp::tags::standard_gamete>, std::allocator<fwdpp::gamete_base<fwdpp::tags::standard_gamete> > >, std::vector<fwdpy11::Mutation, std::allocator<fwdpy11::Mutation> >, std::vector<unsigned int, std::allocator<unsigned int> >, std::unordered_multimap<double, unsigned int, std::hash<double>, std::equal_to<double>, std::allocator<std::pair<double const, unsigned int> > > >, include_preserved_nodes: bool=False) -> None

genotypes

Genotype array. Index order is same as sample input

fwdpy11.ts.infinite_sites(arg0: fwdpp::GSLrng_t<fwdpp::sugar::GSL_RNG_TYPE_TAG<(fwdpp::sugar::GSL_RNG_TYPE)0> >, arg1: fwdpy11::PyPopulation<fwdpy11::Mutation, std::vector<fwdpy11::Mutation, std::allocator<fwdpy11::Mutation> >, std::vector<fwdpp::gamete_base<fwdpp::tags::standard_gamete>, std::allocator<fwdpp::gamete_base<fwdpp::tags::standard_gamete> > >, std::vector<fwdpy11::Mutation, std::allocator<fwdpy11::Mutation> >, std::vector<unsigned int, std::allocator<unsigned int> >, std::unordered_multimap<double, unsigned int, std::hash<double>, std::equal_to<double>, std::allocator<std::pair<double const, unsigned int> > > >, arg2: float) → int
fwdpy11.ts.make_data_matrix(pop: fwdpy11::PyPopulation<fwdpy11::Mutation, std::vector<fwdpy11::Mutation, std::allocator<fwdpy11::Mutation> >, std::vector<fwdpp::gamete_base<fwdpp::tags::standard_gamete>, std::allocator<fwdpp::gamete_base<fwdpp::tags::standard_gamete> > >, std::vector<fwdpy11::Mutation, std::allocator<fwdpy11::Mutation> >, std::vector<unsigned int, std::allocator<unsigned int> >, std::unordered_multimap<double, unsigned int, std::hash<double>, std::equal_to<double>, std::allocator<std::pair<double const, unsigned int> > > >, samples: List[int], record_neutral: bool, record_selected: bool) → fwdpp::data_matrix

Create a fwdpy11.sampling.DataMatrix from a table collection.

Parameters:
  • pop (fwdpy11.Population) – A population
  • samples (list) – A list of sample nodes
  • record_neutral (boolean) – If True, generate data for neutral variants
  • record_selected (boolean) – If True, generate data for selected variants
fwdpy11.ts.simplify(pop: fwdpy11::PyPopulation<fwdpy11::Mutation, std::vector<fwdpy11::Mutation, std::allocator<fwdpy11::Mutation> >, std::vector<fwdpp::gamete_base<fwdpp::tags::standard_gamete>, std::allocator<fwdpp::gamete_base<fwdpp::tags::standard_gamete> > >, std::vector<fwdpy11::Mutation, std::allocator<fwdpy11::Mutation> >, std::vector<unsigned int, std::allocator<unsigned int> >, std::unordered_multimap<double, unsigned int, std::hash<double>, std::equal_to<double>, std::allocator<std::pair<double const, unsigned int> > > >, samples: List[int]) → tuple

Simplify a TableCollection.

Parameters:
Returns:

The simplified tables and list mapping input sample IDs to output IDS

Return type:

fwdpy11.ts.TableCollection

Note that the samples argument is agnostic with respect to the time of the nodes in the input tables. Thus, you may do things like simplify to a set of “currently-alive” nodes plus some or all ancient samples by including some node IDs from fwdpy11.ts.TableCollection.preserved_nodes.

fwdpy11.tsrecorders

Classes for recording ancient samples.

class fwdpy11.tsrecorders.NoAncientSamples

Bases: pybind11_builtins.pybind11_object

A recorder for tree sequence simulations that does nothing.

__init__(self: fwdpy11.tsrecorders.NoAncientSamples) → None
class fwdpy11.tsrecorders.RandomAncientSamples

Bases: pybind11_builtins.pybind11_object

Preserve random samples of individuals at predetermined time points.

__init__(self: fwdpy11.tsrecorders.RandomAncientSamples, seed: int, samplesize: int, timepoints: List[int]) → None
class fwdpy11.tsrecorders.SampleRecorder

Bases: pybind11_builtins.pybind11_object

Allow recording of ancient samples during simulations with tree sequences.

__init__(self: fwdpy11.tsrecorders.SampleRecorder) → None
add_sample(self: fwdpy11.tsrecorders.SampleRecorder, individual: int) → None

Add the index of an individual to the list of samples

assign(self: fwdpy11.tsrecorders.SampleRecorder, samples: numpy.ndarray[uint32]) → None

Add a list of individuals to the list of samples. Input is a numpy array with dtype np.uint32

samples

Access to samples. For unit-testing purposes

fwdpy11.ts_from_msprime

Converts node and edge data from tree sequences generated in msprime

fwdpy11.genetic_values

class fwdpy11.genetic_values.GSS

Bases: fwdpy11.genetic_values.GeneticValueIsTrait

Gaussian stabilizing selection.

VS

Read-only access to VS

__getstate__(self: fwdpy11.genetic_values.GSS) → object
__init__(self: fwdpy11.genetic_values.GSS, opt: float, VS: float) → None
Parameters:
  • opt (float) – Optimal trait value.
  • VS (float) – Strength of stabilizing selection
__setstate__(self: fwdpy11.genetic_values.GSS, arg0: object) → None
opt

Read-only access to optimal trait value.

class fwdpy11.genetic_values.GSSmo

Bases: fwdpy11.genetic_values.GeneticValueIsTrait

Gaussian stabilizing selection with a moving optimum.

__getstate__(self: fwdpy11.genetic_values.GSSmo) → object
__init__(self: fwdpy11.genetic_values.GSSmo, optima: List[Tuple[int, float, float]]) → None
Parameters:optima (list) – Model parameters over time

Each element of optima must be a tuple of (generation, optimal trait value, VS)

__setstate__(self: fwdpy11.genetic_values.GSSmo, arg0: object) → None
class fwdpy11.genetic_values.GeneticValueIsFitness

Bases: fwdpy11.genetic_values.GeneticValueToFitnessMap

Type implying the the genetic value is fitness.

__getstate__(self: fwdpy11.genetic_values.GeneticValueIsFitness) → object
__init__(self: fwdpy11.genetic_values.GeneticValueIsFitness) → None
__setstate__(self: fwdpy11.genetic_values.GeneticValueIsFitness, arg0: object) → None
class fwdpy11.genetic_values.GeneticValueIsTrait

Bases: fwdpy11.genetic_values.GeneticValueToFitnessMap

ABC for functions mapping genetic values representing traits to fitness.

__init__

Initialize self. See help(type(self)) for accurate signature.

class fwdpy11.genetic_values.GeneticValueToFitnessMap

Bases: pybind11_builtins.pybind11_object

ABC for functions translating genetic values into fitness.

__init__

Initialize self. See help(type(self)) for accurate signature.

class fwdpy11.genetic_values.MlocusAdditive

Bases: fwdpy11.genetic_values.MlocusPopGeneticValueWithMapping

Additive effects on trait values.

__getstate__(self: fwdpy11.genetic_values.MlocusAdditive) → tuple
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11.genetic_values.MlocusAdditive, scaling: float) -> None

Additive effects on fitness.

Parameters:scaling (float) – How to treat mutant homozygotes.

For a model of fitness, the genetic value is 1, 1+e*h, 1+scaling*e for genotypes AA, Aa, and aa, respectively.

  1. __init__(self: fwdpy11.genetic_values.MlocusAdditive, scaling: float, gv2w: fwdpy11::GeneticValueIsTrait) -> None

Construct an object of additive effects on a trait with a specific functional mapping from genetic value to fitness.

Parameters:
  1. __init__(self: fwdpy11.genetic_values.MlocusAdditive, scaling: float, gv2w: fwdpy11::GeneticValueIsTrait, noise: fwdpy11.genetic_value_noise.GeneticValueNoise) -> None

Additive effects on a trait with a specific mapping from genetic value to fitness and random effects (“noise”).

Parameters:
__setstate__(self: fwdpy11.genetic_values.MlocusAdditive, arg0: tuple) → None
is_fitness

Returns True if instance calculates fitness as the genetic value and False if the genetic value is a trait value.

scaling

Access to the scaling parameter.

class fwdpy11.genetic_values.MlocusGBR

Bases: fwdpy11.genetic_values.MlocusPopGeneticValueWithMapping

The “gene-based recessive” trait model described in Thornton et al. 2013 http://dx.doi.org/10.1371/journal.pgen.1003258 and Sanjak et al. 2017 http://dx.doi.org/10.1371/journal.pgen.1006573.

The trait value is the geometric mean of the sum of effect sizes on each haplotype. It is undefined for the case where these sums are negative.

The final genetic value is additive across loci. The GBR model is applied within loci.

__getstate__(self: fwdpy11.genetic_values.MlocusGBR) → tuple
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11.genetic_values.MlocusGBR, gv2w: fwdpy11::GeneticValueIsTrait) -> None

Construct object with specific genetic value to fitness map.

param gv2w:Genetic value to fitness map
type gv2w:fwdpy11.genetic_values.GeneticValueIsTrait
  1. __init__(self: fwdpy11.genetic_values.MlocusGBR, gv2w: fwdpy11::GeneticValueIsTrait, noise: fwdpy11.genetic_value_noise.GeneticValueNoise) -> None

Construct object with specific genetic value to fitness map and random effects on trait value.

Parameters:
__setstate__(self: fwdpy11.genetic_values.MlocusGBR, arg0: tuple) → None
class fwdpy11.genetic_values.MlocusMult

Bases: fwdpy11.genetic_values.MlocusPopGeneticValueWithMapping

Multiplicative effects on trait values

__getstate__(self: fwdpy11.genetic_values.MlocusMult) → tuple
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11.genetic_values.MlocusMult, scaling: float) -> None

Multiplicative effects on fitness.

Parameters:scaling (float) – How to treat mutant homozygotes.

For a model of fitness, the genetic value is 1, 1+e*h, 1+scaling*e for genotypes AA, Aa, and aa, respectively.

  1. __init__(self: fwdpy11.genetic_values.MlocusMult, scaling: float, gv2w: fwdpy11::GeneticValueIsTrait) -> None

Construct an object of multiplicative effects on a trait with a specific functional mapping from genetic value to fitness.

Parameters:
  1. __init__(self: fwdpy11.genetic_values.MlocusMult, scaling: float, gv2w: fwdpy11::GeneticValueIsTrait, scaling: fwdpy11.genetic_value_noise.GeneticValueNoise) -> None

Multiplicative effects on a trait with a specific mapping from genetic value to fitness and random effects (“noise”).

Parameters:
__setstate__(self: fwdpy11.genetic_values.MlocusMult, arg0: tuple) → None
is_fitness

Returns True if instance calculates fitness as the genetic value and False if the genetic value is a trait value.

scaling

Access to the scaling parameter.

class fwdpy11.genetic_values.MlocusPopGeneticValue

Bases: pybind11_builtins.pybind11_object

ABC for genetic value calculations for diploid members of fwdpy11.MlocusPop

__call__(self: fwdpy11.genetic_values.MlocusPopGeneticValue, diploid_index: int, pop: fwdpy11._Populations._MlocusPop) → float
Parameters:
  • diploid_index (int >= 0) – The index of the individual to calculate.
  • pop (fwdpy11.MlocusPop) – The population object containing the individual.
Returns:

The genetic value of an individual.

Return type:

float

__init__

Initialize self. See help(type(self)) for accurate signature.

fitness(self: fwdpy11.genetic_values.MlocusPopGeneticValue, diploid_index: int, pop: fwdpy11._Populations._MlocusPop) → float
Parameters:
  • diploid_index (int >= 0) – The index of the individual to calculate.
  • pop (fwdpy11.MlocusPop) – The population object containing the individual.
Returns:

The fitness of an individual.

Return type:

float

class fwdpy11.genetic_values.MlocusPopGeneticValueWithMapping

Bases: fwdpy11.genetic_values.MlocusPopGeneticValue

Genetic value calculations with flexible mapping of genetic value to fitness.

__init__

Initialize self. See help(type(self)) for accurate signature.

gvalue_to_fitness

Access the genetic value to fitness map.

noise

Access the random noise function.

class fwdpy11.genetic_values.SlocusAdditive

Bases: fwdpy11.genetic_values.SlocusPopGeneticValueWithMapping

Additive genetic values.

__getstate__(self: fwdpy11.genetic_values.SlocusAdditive) → tuple
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11.genetic_values.SlocusAdditive, scaling: float) -> None

Additive effects on fitness.

Parameters:scaling (float) – How to treat mutant homozygotes.

For a model of fitness, the genetic value is 1, 1+e*h, 1+scaling*e for genotypes AA, Aa, and aa, respectively.

  1. __init__(self: fwdpy11.genetic_values.SlocusAdditive, scaling: float, gv2w: fwdpy11::GeneticValueIsTrait) -> None

Construct an object of additive effects on a trait with a specific functional mapping from genetic value to fitness.

Parameters:
  1. __init__(self: fwdpy11.genetic_values.SlocusAdditive, scaling: float, gv2w: fwdpy11::GeneticValueIsTrait, noise: fwdpy11.genetic_value_noise.GeneticValueNoise) -> None

Additive effects on a trait with a specific mapping from genetic value to fitness and random effects (“noise”).

Parameters:
__setstate__(self: fwdpy11.genetic_values.SlocusAdditive, arg0: tuple) → None
is_fitness

Returns True if instance calculates fitness as the genetic value and False if the genetic value is a trait value.

scaling

Access to the scaling parameter.

class fwdpy11.genetic_values.SlocusGBR

Bases: fwdpy11.genetic_values.SlocusPopGeneticValueWithMapping

The “gene-based recessive” trait model described in Thornton et al. 2013 http://dx.doi.org/10.1371/journal.pgen.1003258 and Sanjak et al. 2017 http://dx.doi.org/10.1371/journal.pgen.1006573.

The trait value is the geometric mean of the sum of effect sizes on each haplotype. It is undefined for the case where these sums are negative.

__getstate__(self: fwdpy11.genetic_values.SlocusGBR) → tuple
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11.genetic_values.SlocusGBR, gv2w: fwdpy11::GeneticValueIsTrait) -> None

Construct object with specific genetic value to fitness map.

param gv2w:Genetic value to fitness map
type gv2w:fwdpy11.genetic_values.GeneticValueIsTrait
  1. __init__(self: fwdpy11.genetic_values.SlocusGBR, gv2w: fwdpy11::GeneticValueIsTrait, noise: fwdpy11.genetic_value_noise.GeneticValueNoise) -> None

Construct object with specific genetic value to fitness map and random effects on trait value.

Parameters:
__setstate__(self: fwdpy11.genetic_values.SlocusGBR, arg0: tuple) → None
class fwdpy11.genetic_values.SlocusMult

Bases: fwdpy11.genetic_values.SlocusPopGeneticValueWithMapping

Multiplicative genetic values.

__getstate__(self: fwdpy11.genetic_values.SlocusMult) → tuple
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: fwdpy11.genetic_values.SlocusMult, scaling: float) -> None

Multiplicative effects on fitness.

Parameters:scaling (float) – How to treat mutant homozygotes.

For a model of fitness, the genetic value is 1, 1+e*h, 1+scaling*e for genotypes AA, Aa, and aa, respectively.

  1. __init__(self: fwdpy11.genetic_values.SlocusMult, scaling: float, gv2w: fwdpy11::GeneticValueIsTrait) -> None

Construct an object of multiplicative effects on a trait with a specific functional mapping from genetic value to fitness.

Parameters:
  1. __init__(self: fwdpy11.genetic_values.SlocusMult, scaling: float, gv2w: fwdpy11::GeneticValueIsTrait, noise: fwdpy11.genetic_value_noise.GeneticValueNoise) -> None

Multiplicative effects on a trait with a specific mapping from genetic value to fitness and random effects (“noise”).

Parameters:
__setstate__(self: fwdpy11.genetic_values.SlocusMult, arg0: tuple) → None
is_fitness

Returns True if instance calculates fitness as the genetic value and False if the genetic value is a trait value.

scaling

Access to the scaling parameter.

class fwdpy11.genetic_values.SlocusPopGeneticValue

Bases: pybind11_builtins.pybind11_object

ABC for genetic value calculations for diploid members of fwdpy11.SlocusPop

__call__(self: fwdpy11.genetic_values.SlocusPopGeneticValue, diploid_index: int, pop: fwdpy11._Populations._SlocusPop) → float
Parameters:
  • diploid_index (int >= 0) – The index of the individual to calculate.
  • pop (fwdpy11.SlocusPop) – The population object containing the individual.
Returns:

The genetic value of an individual.

Return type:

float

__init__

Initialize self. See help(type(self)) for accurate signature.

fitness(self: fwdpy11.genetic_values.SlocusPopGeneticValue, diploid_index: int, pop: fwdpy11._Populations._SlocusPop) → float
Parameters:
  • diploid_index (int >= 0) – The index of the individual
  • pop (fwdpy11.SlocusPop) – The population containing the individual
Returns:

The fitness of an individual.

Return type:

float

class fwdpy11.genetic_values.SlocusPopGeneticValueWithMapping

Bases: fwdpy11.genetic_values.SlocusPopGeneticValue

Genetic value calculations with flexible mapping of genetic value to fitness.

__init__

Initialize self. See help(type(self)) for accurate signature.

gvalue_to_fitness

Access the genetic value to fitness map.

noise

Access the random noise funcion

fwdpy11.genetic_value_noise

“Noise” added to genetic values.

class fwdpy11.genetic_value_noise.GaussianNoise

Bases: fwdpy11.genetic_value_noise.GeneticValueNoise

Gaussian noise added to genetic values.

__getstate__(self: fwdpy11.genetic_value_noise.GaussianNoise) → object
__init__(self: fwdpy11.genetic_value_noise.GaussianNoise, sd: float, mean: float=0.0) → None
Parameters:
  • sd (float) – Standard deviation of noise.
  • mean (float) – Mean value of noise.
__setstate__(self: fwdpy11.genetic_value_noise.GaussianNoise, arg0: object) → None
class fwdpy11.genetic_value_noise.GeneticValueNoise

Bases: pybind11_builtins.pybind11_object

ABC for noise classes affecting fwdpy11.SlocusPop.

__init__

Initialize self. See help(type(self)) for accurate signature.

class fwdpy11.genetic_value_noise.NoNoise

Bases: fwdpy11.genetic_value_noise.GeneticValueNoise

Type implying no random effects on genetic values.

__getstate__(self: fwdpy11.genetic_value_noise.NoNoise) → object
__init__(self: fwdpy11.genetic_value_noise.NoNoise) → None
__setstate__(self: fwdpy11.genetic_value_noise.NoNoise, arg0: object) → None

fwdpy11.sampling

Taking samples from populations

class fwdpy11.sampling.DataMatrix

Bases: pybind11_builtins.pybind11_object

Represent a sample from a population in a matrix format.

There are two possible representations of the data:

1. As a genotype matrix, where individuals are encoded a 0,1, or 2 copies of the derived mutation. There is one column per diploid here,

and one row per variable site.

2. As a haplotype matrix, with two columns per diploid, and each column containing a 0 (ancestral) or 1 (derived) label. Each row

represents a variable site.

You do not create objects of this type directly. Instead, you use one of the following functions:

Please see Representing samples from a population in matrix form for examples of generating instances of this type. The API requires multiple steps, in order to maximize flexibility.

Changed in version 0.2.0: Changed layout to row = variable site. Changed to match fwdpp 0.7.0 layour where the neutral and selected data are represented as a fwdpy11.sampling.StateMatrix

__init__

Initialize self. See help(type(self)) for accurate signature.

ncol

Sample size of the matrix

neutral

Return a buffer representing neutral variants. This buffer may be used to create a NumPy ndarray object.

Changed in version 0.1.2: Return a buffer instead of 1d numpy.array

Changed in version 0.1.4: Allow read/write access instead of readonly

Changed in version 0.2.0: Type is fwdpy11.sampling.StateMatrix

neutral_keys

Keys for neutral mutations used to generate matrix

selected

Return a buffer representing neutral variants. This buffer may be used to create a NumPy ndarray object.

Changed in version 0.1.2: Return a buffer instead of 1d numpy.array

Changed in version 0.1.4: Allow read/write access instead of readonly

Changed in version 0.2.0: Type is fwdpy11.sampling.StateMatrix

selected_keys

Keys for selected mutations used to generate matrix

class fwdpy11.sampling.StateMatrix

Bases: pybind11_builtins.pybind11_object

Simple matrix representation of variation data.

These are not constructed directly. Rather, they are generated when a fwdpy11.sampling.DataMatrix is generated.

This object supports the buffer protocol.

New in version 0.2.0.

__init__

Initialize self. See help(type(self)) for accurate signature.

positions

The mutation positions

shape

Shape of the matrix.

fwdpy11.sampling.genotype_matrix(*args, **kwargs)

Overloaded function.

  1. genotype_matrix(arg0: fwdpy11::SlocusPop, arg1: List[int], arg2: List[Tuple[int, int]], arg3: List[Tuple[int, int]]) -> fwdpy11.sampling.DataMatrix

Generate a fwdpy11.sampling.DataMatrix from a fwdpy11.SlocusPop object. The DataMatrix will be encoded as diploid genotypes.

Parameters:
Return type:

fwdpy11.sampling.DataMatrix encoded as a genotype matrix

  1. genotype_matrix(arg0: fwdpy11::MlocusPop, arg1: List[int], arg2: List[Tuple[int, int]], arg3: List[Tuple[int, int]]) -> fwdpy11.sampling.DataMatrix

Generate a fwdpy11.sampling.DataMatrix from a fwdpy11.MlocusPop object. The DataMatrix will be encoded as diploid genotypes.

Parameters:
Return type:

fwdpy11.sampling.DataMatrix encoded as a genotype matrix

fwdpy11.sampling.haplotype_matrix(*args, **kwargs)

Overloaded function.

  1. haplotype_matrix(arg0: fwdpy11::SlocusPop, arg1: List[int], arg2: List[Tuple[int, int]], arg3: List[Tuple[int, int]]) -> fwdpy11.sampling.DataMatrix

Generate a fwdpy11.sampling.DataMatrix from a fwdpy11.SlocusPop object. The DataMatrix will be encoded as haplotypes.

Parameters:
Return type:

fwdpy11.sampling.DataMatrix encoded as a haplotype matrix

  1. haplotype_matrix(arg0: fwdpy11::MlocusPop, arg1: List[int], arg2: List[Tuple[int, int]], arg3: List[Tuple[int, int]]) -> fwdpy11.sampling.DataMatrix

Generate a fwdpy11.sampling.DataMatrix from a fwdpy11.MlocusPop object. The DataMatrix will be encoded as haplotypes.

Parameters:
Return type:

fwdpy11.sampling.DataMatrix encoded as a haplotype matrix

fwdpy11.sampling.matrix_to_sample(m: fwdpy11.sampling.DataMatrix) → tuple

Convert a fwdpy11.sampling.DataMatrix into a tuple representing the neutral and selected data, resepectively, as a list of (positon, string) tuples.

See Sampling from simulated populations and Representing samples from a population in matrix form for more details.

New in version 0.1.1.

Changed in version 0.2.0: The return value is now a tuple (neutral, selected)

Parameters:m (fwdpy11.sampling.DataMatrix) – A data matrix
Return type:tuple
Returns:A tuple of the (neutral, selected) mutations. Each element of the tuple holds data in list format. Positions are in same order as the original matrix. The genotypes are represented as strings with elements 0 through nrow-1 being in the same order as the original matrix.

Note

If the input data represent a haplotype matrix, then the return value may be further processed using pylibseq. Any filtering on position, frequency, etc., should have aleady been done when the original matrix was generated. However, you may filter the return value as you see fit. If the matrix was created from a multi-locus simulation, you may wish to use fwdpy11.sampling.separate_samples_by_loci() to split the return value up

into separate lists for each locus.
fwdpy11.sampling.mutation_keys(*args, **kwargs)

Overloaded function.

  1. mutation_keys(pop: fwdpy11::SlocusPop, individuals: List[int], neutral: bool=True, selected: bool=True) -> Tuple[List[Tuple[int, int]], List[Tuple[int, int]]]

Generate a tuple of (mutation_key, sample count) for mutations in a specific set of diploids in a fwdpy11.SlocusPop object.

Parameters:
  • pop – A population object.
  • individuals – A list of indexes to diploids.
  • netural – (True) A boolean indicating whether to include neutral variants.
  • selected – (True) A boolean indicating whether to include selected variants.

Note

Mutation keys are returned unsorted.

  1. mutation_keys(pop: fwdpy11::MlocusPop, individuals: List[int], neutral: bool=True, selected: bool=True) -> Tuple[List[Tuple[int, int]], List[Tuple[int, int]]]

Generate a tuple of (mutation_key, sample count) for mutations in a specific set of diploids in a fwdpy11.MlocusPop object.

Parameters:
  • pop – A population object.
  • individuals – A list of indexes to diploids.
  • netural – (True) A boolean indicating whether to include neutral variants.
  • selected – (True) A boolean indicating whether to include selected variants.

Note

Mutation keys are returned unsorted.

fwdpy11.sampling.separate_samples_by_loci(arg0: List[Tuple[float, float]], arg1: List[Tuple[float, str]]) → List[List[Tuple[float, str]]]

Convert the output from fwdpy11.sampling.matrix_to_sample() into separate records per locus.

New in version 0.1.1.

Changed in version 0.1.2: Take a list of positions as arguments and not a population object.

Changed in version 0.2.0: Return type changed from dict to list

Parameters:
Return type:

list

Returns:

The data returned follow the same structure

as fwdpy11.sampling.matrix_to_sample(),

but there is one entry per locus. The data for consecutive loci are consecutive elements in the return value.

fwdpy11.model_params

Define classes for parameterizing simulations.

The classes take either kwargs or an expanded dict as arguments. The names of the kwargs are the same as the names of class properties. The properties themselves are gettable/settable in the usual way.

Each class has a validate function that attempts to do a full error-checking on the data stored in a class instance.

The module fwdpy11.ezparams contains some functions for rapidly setting up dictionaries of parameters for common cases.

Todo

The classes should make deep copies of the input so that data from the calling environment are not changed, which can happen in some cases. There is an issue for C++ types holding things like Python objects. Currently, tests/test_python_genetic_values.py will segfault if we copy.deepcopy the params objects.

class fwdpy11.model_params.ModelParams(**kwargs)

Bases: object

Class to hold simulation parameters

New in version 0.1.1.

Changed in version 0.2.0: Changed this from a horrible class hierarchy into a much simpler, single class.

See Parameterizing a simulation for detailed documentation.

__init__(**kwargs)

Initialize self. See help(type(self)) for accurate signature.

demography

Get or set demographic history.

gvalue

Get/set the type name of the genetic value calculator.

interlocus_rec

Get/set interlocus recombination functions.

mutrate_n

Return neutral mutation rate(s).

mutrate_s

Return selected mutation rate(s).

mutrates_n

Return neutral mutation rate(s).

mutrates_s

Return selected mutation rate(s).

nregions

Get or set the neutral regions.

prune_selected

Get or set whether or not selected fixations are to be removed during simulaton.

When setting, a bool is required.

pself

Get/set selfing probability/probabilities.

rates

Get/set mutation and recombination rates.

recrate

Return recombination rate(s).

recrates

Return recombination rate(s).

recregions

Get or set the recombination regions.

sregions

Get or set the selected regions.

validate()

Error check model params.

Raises:TypeError – Throws TypeError if validation fails.

fwdpy11.temporal_samplers

class fwdpy11.temporal_samplers.RecordNothing

Bases: object

A temporal sampler that does nothing.

fwdpy11.wright_fisher

fwdpy11.wright_fisher.evolve(rng, pop, params, recorder=None)

Evolve a population

Parameters:

Note

If recorder is None, then fwdpy11.temporal_samplers.RecordNothing will be used.

fwdpy11.wright_fisher_ts

fwdpy11.wright_fisher_ts.evolve(rng, pop, params, simplification_interval, recorder=None, suppress_table_indexing=False)

Evolve a population

Parameters:
  • rng (fwdpy11.GSLrng) – random number generator
  • pop (fwdpy11.SlocusPop) – A population
  • params (fwdpy11.model_params.ModelParams) – simulation parameters
  • simplification_interval (int) – Number of generations between simplifications.
  • recorder (callable) – (None) A temporal sampler/data recorder.
  • suppress_table_indexing (boolean) – (False) Prevents edge table indexing until end of simulation

Note

If recorder is None, then fwdpy11.tsrecorders.NoAncientSamples will be used.

fwdpy11.multilocus

Types and functions specific to multi-locus/region simulations

class fwdpy11.multilocus.InterlocusRecombination

Bases: pybind11_builtins.pybind11_object

This class parameterizes interlocus recombination in multilocus simulations. You do not make instances of this class directly. Rather, you make calls to one of fwdpy11.multilocus.poisson_rec() or fwdpy11.multilocus.binomial_rec().

__init__(self: fwdpy11.multilocus.InterlocusRecombination, arg0: float, arg1: int) → None
fwdpy11.multilocus.binomial_rec(*args, **kwargs)

Overloaded function.

  1. binomial_rec(arg0: List[float]) -> list

    Parameterize interlocus recomination as a Binomial process.

    param probs:A list of genetic distance in cM/100.
    rtype:list
    return:A list of of fwdpy11.multilocus.InterlocusRecombination.

    Changed in version 0.1.3: No longer takes a fwdpy11.GSLrng as argument.

  2. binomial_rec(arg0: float) -> fwdpy11.multilocus.InterlocusRecombination

    Parameterize interlocus recomination as a Binomial process.

    param prob:The genetic distance in cM/100.
    rtype:fwdpy11.multilocus.InterlocusRecombination
    return:An instance of fwdpy11.multilocus.InterlocusRecombination.

    Changed in version 0.1.3: No longer takes a fwdpy11.GSLrng as argument.

fwdpy11.multilocus.poisson_rec(*args, **kwargs)

Overloaded function.

  1. poisson_rec(arg0: List[float]) -> list

    Parameterize interlocus recomination as a Poisson process.

    param means:A list of mean values.
    rtype:list
    return:A list of fwdpy11.multilocus.InterlocusRecombination.

    Changed in version 0.1.3: No longer takes a fwdpy11.GSLrng as argument.

  2. poisson_rec(arg0: float) -> fwdpy11.multilocus.InterlocusRecombination

    Parameterize interlocus recomination as a Poisson process.

    param mean:The mean of a Poisson process.
    rtype:fwdpy11.multilocus.InterlocusRecombination
    return:An instance of fwdpy11.multilocus.InterlocusRecombination.

    Changed in version 0.1.3: No longer takes a fwdpy11.GSLrng as argument.

fwdpy11.util

Miscellaneous utilities for simulations.

fwdpy11.util.change_effect_size(pop: fwdpy11._Population.Population, index: int, new_esize: float=0, new_dominance: float=1.0, new_esizes: list=[], new_heffects: list=[]) → None

Change effect sizes and/or dominance of mutations.

From the Python size, the population objects are immutable. This function allows you to change the effect of a mutation on genetic value.

Parameters:

New in version 0.1.3.

Changed in version 0.2.0: Modified to act on base class and handle vectors of effect sizes. Default values also updated.

fwdpy11.util.sort_gamete_keys(arg0: fwdpy11._opaque_gametes.VecGamete, arg1: fwdpy11._opaque_mutations.VecMutation) → None

Sorts mutation keys in gametes. Useful when constructing population objects directly. See Construction of population objects from a predetermined state for example use.

New in version 0.1.4.

fwdpy11.demography

fwdpy11.demography.exponential_size_change(Nstart, Nstop, time)

Generate a list of population sizes according to exponential size_change model

Parameters:
  • Nstart – population size at onset of size change
  • Nstop – Population size to reach at end of size change
  • time – Time (in generations) to get from Nstart to Nstop
Returns:

A list of integers representing population size over time.

New in version 0.1.1.

Indices and tables