コード例 #1
0
def createGenome(size, numMSats, numSNPs):
    maxAlleleN = 100
    # print "Mutation model is most probably not correct", numMSats, numSNPs
    loci = (numMSats + numSNPs) * [1]
    initOps = []

    for msat in range(numMSats):
        diri = numpy.random.mtrand.dirichlet([1.0] * cfg.startAlleles)
        if type(diri[0]) == float:
            diriList = diri
        else:
            diriList = list(diri)

        initOps.append(
            sp.InitGenotype(freq=[0.0] * ((maxAlleleN + 1 - 8) // 2) +
                            diriList + [0.0] * ((maxAlleleN + 1 - 8) // 2),
                            loci=msat))

    for snp in range(numSNPs):
        freq = 0.5
        initOps.append(
            sp.InitGenotype(
                # Position 0 is coded as 0, not good for genepop
                freq=[0.0, freq, 1 - freq],
                loci=numMSats + snp))

    preOps = []
    if cfg.mutFreq > 0:
        preOps.append(sp.StepwiseMutator(rates=cfg.mutFreq,
                      loci=list(range(numMSats))))
    return loci, initOps, preOps
コード例 #2
0
ファイル: model.py プロジェクト: gavieira/genomics-notebooks
    def _create_genome(self, num_msats, mut=None, start_alleles=10):
        init_ops = []
        loci = num_msats * [1]
        pre_ops = []
        max_allele_msats = 100

        for msat in range(num_msats):
            diri = np.random.mtrand.dirichlet([1.0] * start_alleles)
            if type(diri[0]) == float:
                diri_list = diri
            else:
                diri_list = list(diri)

            init_ops.append(
                sp.InitGenotype(freq=[0.0] * ((max_allele_msats + 1 - 8) //
                                2) + diri_list + [0.0] *
                                ((max_allele_msats + 1 - 8) // 2),
                                loci=msat))
        if mut is not None:
            pre_ops.append(sp.StepwiseMutator(rates=mut))

        return loci, init_ops, pre_ops
コード例 #3
0
import simuOpt
simuOpt.setOptions(quiet=True, alleleType='long')
import simuPOP as sim
pop = sim.Population(size=[2500]*10, loci=1)
simu = sim.Simulator(pop, rep=2)
simu.evolve(
    initOps=[
        sim.InitSex(),
        sim.InitGenotype(genotype=20),
    ],
    preOps=[
        sim.StepwiseMutator(rates=0.0001, reps=0),
        sim.KAlleleMutator(k=10000, rates=0.0001, reps=1),
    ],
    matingScheme=sim.RandomMating(),
    postOps=[
        # Use vars=['alleleFreq_sp'] to calculate allele frequency for
        # each subpopulation
        sim.Stat(alleleFreq=0, vars=['alleleFreq_sp'], step=200),
        sim.PyEval('gen', step=200, reps=0),
        sim.PyEval(r"'\t%.2f' % (sum([len(subPop[x]['alleleFreq'][0]) "
            "for x in range(10)])/10.)", step=200),
        sim.PyOutput('\n', reps=-1, step=200)
    ],
    gen=601
)
コード例 #4
0
ファイル: mutatorVSP.py プロジェクト: sudorook/simuPOP
    pop.dvars().avgAllele = avg
    return True

pop = sim.Population(10000, loci=[1, 1])
pop.setVirtualSplitter(sim.AffectionSplitter())
pop.evolve(
    initOps=[
        sim.InitSex(),
        sim.InitGenotype(genotype=[50, 50])
    ],
    matingScheme=sim.RandomMating(),
    postOps=[
        # determine affection sim.status for each offspring (duringMating)
        sim.PyPenetrance(func=fragileX, loci=0),
        # unaffected offspring, mutation rate is high to save some time
        sim.StepwiseMutator(rates=1e-3, loci=1),
        # unaffected offspring, mutation rate is high to save some time
        sim.StepwiseMutator(rates=1e-3, loci=0, subPops=[(0, 0)]),
        # affected offspring have high probability of mutating upward
        sim.StepwiseMutator(rates=1e-2, loci=0, subPops=[(0, 1)],
           incProb=0.7, mutStep=3),
        # number of affected
        sim.PyOperator(func=avgAllele, step=20),
        sim.PyEval(r"'Gen: %3d #Aff: %d AvgRepeat: %.2f (unaff), %.2f (aff), %.2f (unrelated)\n'"
            + " % (gen, numOfAffected, avgAllele[0], avgAllele[1], avgAllele[2])",
            step=20),
    ],
    gen = 101
)

コード例 #5
0
ファイル: StepwiseMutator.py プロジェクト: sudorook/simuPOP
#

# This script is an example in the simuPOP user's guide. Please refer to
# the user's guide (http://simupop.sourceforge.net/manual) for a detailed
# description of this example.
#

import simuPOP as sim
pop = sim.Population(size=1000, loci=[1, 1])
pop.evolve(
    # all start from allele 50
    initOps=[sim.InitSex(),
             sim.InitGenotype(freq=[0] * 50 + [1])],
    matingScheme=sim.RandomMating(),
    preOps=[
        sim.StepwiseMutator(rates=1e-3, loci=0),
        sim.StepwiseMutator(rates=1e-3,
                            incProb=0.6,
                            loci=1,
                            mutStep=(sim.GEOMETRIC_DISTRIBUTION, 0.2)),
    ],
    gen=100)
# count the average number tandem repeats at both loci
cnt0 = cnt1 = 0
for ind in pop.individuals():
    cnt0 += ind.allele(0, 0) + ind.allele(0, 1)
    cnt1 += ind.allele(1, 0) + ind.allele(1, 1)

print('Average number of repeats at two loci are %.2f and %.2f.' % \
    (cnt0/2000., cnt1/2000.))
コード例 #6
0
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

# This script is an example in the simuPOP user's guide. Please refer to
# the user's guide (http://simupop.sourceforge.net/manual) for a detailed
# description of this example.
#

import simuPOP as sim
pop = sim.Population(5000, loci=[1, 1])
pop.evolve(
    initOps=[sim.InitSex(), sim.InitGenotype(genotype=[50, 50])],
    preOps=[
        # the first locus uses a pure stepwise mutation model
        sim.StepwiseMutator(rates=0.001, loci=0),
        # the second locus uses a mixed model
        sim.MixedMutator(rates=0.001,
                         loci=1,
                         mutators=[
                             sim.KAlleleMutator(rates=1, k=100),
                             sim.StepwiseMutator(rates=1)
                         ],
                         prob=[0.1, 0.9])
    ],
    matingScheme=sim.RandomMating(),
    gen=20)
# what alleles are there?
geno0 = []
geno1 = []
for ind in pop.individuals():