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

Tracking birth experience #34

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hello everyone,

I'm trying to simulate a population in overlapping generation, in which females can have offsprings only if they didn't have offsprings in the previous year. Males can have offsprings any time. Although I thought that offspring_idx could be helpful, the index is reset for each mating event. Is there any way to track whether an individual had offsprings in the previous year or not? Any help would be appreciated.

Best regards, Ito

BoPeng commented 7 years ago

Can you add an info field (e.g. has_offspring) and assign it during mating using something like:

ops = [ ... genotype transmitter ...,
    PyOperator(lambda mom: mom.has_offspring = 1)
    ]

The actual implementation can be a bit more complex because of overlapping generation in which parents would be copied to the next generation, so you should generate offspring before parents are copied (CloneMating in the end).

Then you can define a mating VSP that excludes mom with has_offspring. The vsp can be a bit complex but these virtual splitters could help.

ghost commented 7 years ago

Thank you for your kind reply.

I understood. However, I encountered a following error. SyntaxError: lambda cannot contain assignment Is there any way to fix this or to assign it without using lambda?

Best regards, Ito

BoPeng commented 7 years ago

You can try lambda mom: mom.setInfo(1, 'has_offspring') is None. The setInfo is equivalent to = and is None makes the function return True. Otherwise the offspring will be discarded.

ghost commented 7 years ago

Thank you so much for your prompt reply. I solved the problem.

I have another short question. This seems to track the birth experience in one's life span. Is it possible to track whether an individual had offsprings in the previous year.

BoPeng commented 7 years ago

You can save year (gen) information to the information field.