BoPeng / simuPOP

A general-purpose forward-time population genetics simulation environment.
http://bopeng.github.io/simuPOP/
GNU General Public License v2.0
31 stars 12 forks source link

Evolve previously generated genotypes under OutOfAfricaModel #60

Closed MrLocuace closed 6 years ago

MrLocuace commented 6 years ago

Dear Bo, I would like to use previously generated genotypes of a population A (n=7300; stored in an object "pop") and make these genotypes evolve under the class simuPOP.demography.OutOfAfricaModel, which has parameter N_A=7300. May I ask you how can I do this?

Many thanks, Luc

BoPeng commented 6 years ago

I think this page has an example on how to use a demographic model. You only need to change model to an instance of OutOfAfricaModel(...).

MrLocuace commented 6 years ago

Hi Bo, I did it the way you suggested:

model = sim.demography.OutOfAfricaModel(8800, outcome=['AF'])
pop.evolve(
    matingScheme=sim.RandomMating(
        subPopSize=model ),
    gen=100 
)

However, when I try to export the genotypes in ms format:

sim.utils.export(pop, format='ms',output='mypop.txt')

I get an error:

2018-10-02 18:58:51.382 python[3825:536428] -[NSApplication _setup:]: unrecognized selector sent to instance 0x10ff2ee20
Traceback (most recent call last):
  File "simupop_test11.py", line 134, in <module>
    sim.utils.export(pop, format='ms',output='/path/mypop.txt') 
  File "~/miniconda2/lib/python2.7/site-packages/simuPOP/utils.py", line 3095, in export
    Exporter(format, *args, **kwargs).apply(pop)
RuntimeError: Unknown runtime error happened.

In utils.py, line 3095:

def export(pop, format, *args, **kwargs):
    '''Apply operator ``Exporter`` to population *pop* in format *format*.'''
    Exporter(format, *args, **kwargs).apply(pop)

Do you know what is happening?

Thanks very much again

BoPeng commented 6 years ago

No,

 unrecognized selector sent to instance 0x10ff2ee20

does not look familiar to me. Perhaps you can create a minimal example to demonstrate the problem? You can create for example a population with 1 locus and some random sex and genotype etc...

MrLocuace commented 6 years ago

Hi Bo, thank you for your reply

model = sim.demography.OutOfAfricaModel(T0=8800, outcome=['AF'])
pop = sim.Population(size=[30], loci=10)
pop.evolve(initOps=[
         sim.InitSex(),
         sim.InitGenotype(freq=[0.5, 0.5])
     ],
    matingScheme=sim.RandomMating(subPopSize=model),
    gen=100
)

sim.utils.export(pop, format='ms',output='mypop.txt')
MrLocuace commented 6 years ago

Perhaps it has something to do when importing matplotlib in a Mac OS computer. I remember it was working before I did "import matplotlib", but now even without "import matplotlib" I am unable to export in ms format because of this error

BoPeng commented 6 years ago

A complete script

import simuPOP as sim
from simuPOP import demography

model = demography.OutOfAfricaModel(T0=8800, outcome=['AF'])
pop = sim.Population(size=[30], loci=10)
pop.evolve(initOps=[
         sim.InitSex(),
         sim.InitGenotype(freq=[0.5, 0.5])
     ],
    matingScheme=sim.RandomMating(subPopSize=model),
    gen=100
)

sim.utils.export(pop, format='ms',output='mypop.txt')

works ok here, so it might be something wrong with your environment. I would suggest that you create a new conda environment just for simuPOP and try again.

MrLocuace commented 6 years ago

Thank you Bo, I'll do it in that way