Exemple #1
0
def read_gs_chromosome_template(templatef):
    """
    Reads a genomeSIMLA format chromosome template file
    
    :param templatef: The filename of the template file
    :type templatef: string

    :rtype: A ChromosomeTemplate object corresponding to the file
    """
    with smartopen(templatef) as f:
        label = f.readline().strip()  # The label and
        f.readline()  # the number of markers, both of which we dont need.
        c = pydigree.ChromosomeTemplate(label=label)

        # genomeSIMLA chromosome files have marginal recombination probs
        # instead of map positions. We'll have to keep track of what the
        # last position was and add to it to get it into the shape we want
        # it to be in.
        last_cm = 0
        for line in f:
            if line == '\n':
                continue
            label, _, minf, cm, bp = line.strip().split()
            bp = int(bp)
            cm = float(cm)
            last_cm += cm
            c.add_genotype(float(minf), last_cm, label=label, bp=bp)
    return c
Exemple #2
0
def test_counters():
    nchrom = 50
    pop = pydigree.Population()
    for i in range(nchrom):
        c = pydigree.ChromosomeTemplate()
        c.add_genotype(0.1, 0)
        pop.add_chromosome(c)

    assert pop.chromosomes.nchrom() == nchrom
    assert pop.chromosomes.nloci() == nchrom
Exemple #3
0
def test_randomloci():
    nchrom = 100
    nloc = 50

    pop = pydigree.Population()
    for i in range(nchrom):
        c = pydigree.ChromosomeTemplate()
        c.add_genotype(0.1, 0)
        pop.add_chromosome(c)

    for i in range(100):
        locs = list(pop.chromosomes.select_random_loci(nloc))
        locs.sort()

        # all the chromosomes have 1 marker
        assert all(x[1] == 0 for x in locs)

        # all the chromosomes are valid indices
        assert all(0 <= x[0] < nchrom for x in locs)

        # No duplicates!
        for i in range(1, nloc):
            assert locs[i] != locs[i - 1]
Exemple #4
0
import numpy as np

import pydigree as pyd
from pydigree.simulation import QuantitativeTrait

ninds = 5000
nloc = 1000
maf = 0.5

traitname = 'synthetic'
# Create population
pop = pyd.Population()

# Create chromosomes
for i in range(100):
    c = pyd.ChromosomeTemplate()
    c.add_genotype(maf, 0)
    pop.add_chromosome(c)

# Create trait QuantitativeTrait
trait = QuantitativeTrait('synthetic',
                          'quantitative',
                          chromosomes=pop.chromosomes)
for i in range(100):
    trait.add_effect((i, 0), 1 * (-1 if i % 2 else 1))

print('Locus mean genotypic value: {}'.format(
    trait.effects[0].expected_genotypic_value))
print('Locus variance: {}'.format(trait.effects[0].locus_additive_variance))

print('Expected trait mean: {}'.format(trait.expected_genotypic_value))
Exemple #5
0
#!/usr/bin/env python3

import pydigree
from pydigree.simulation import QuantitativeTrait

nchrom = 1
popsize = 500
ngen = 100

pop = pydigree.Population(popsize)
for x in range(nchrom):
    c = pydigree.ChromosomeTemplate()
    c.add_genotype(0.1, 0)
    pop.add_chromosome(c)

trait = QuantitativeTrait('q', 'quantitative')
for i in range(nchrom):
    trait.add_effect_liability((i, 0), 0, 1)
print(trait)

pop.initialize_pool()
for x in range(popsize):
    pop.add_founder_individual()


def gen(ninds):
    "Advance by one generation, with ninds in the new generation"
    pop.advance_generation(ninds)
    pop.get_genotypes()
    pop.remove_ancestry()
    return pop.allele_frequency((0, 0), 1)