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

Using pedigrees with overlapping generations #38

Closed regevs closed 7 years ago

regevs commented 7 years ago

I want to use simuPOP in order to generate two individuals with a known relationship (e.g., grandparent and grandchild). For that, I am generating a Pedigree object manually with creating a file:

100 0 0 M U
101 0 0 F U
500 100 101 F U
200 0 0 M U
501 500 200 F U

and loading it using sim.loadPedigree. That is, 100 and 101 are the parents of 500; 500 and 200 are the parents of 501. However, the object generated looks like this:

> sim.dump(ped, ancGens=range(ped.ancestralGens()+1))
Ploidy: 2 (diploid)
Chromosomes:
1:  (AUTOSOME, 0 loci)
Information fields: 
ind_id father_id mother_id 
population size: 1 (1 subpopulations with 1 Individuals)
Number of ancestral populations: 2

SubPopulation 0 (), 1 Individuals:
   0: FU  |  |  501 500 200

Ancestral population 1
SubPopulation 0 (), 2 Individuals:
   0: FU  |  |  500 100 101
   1: FU  |  |  501 500 200

Ancestral population 2
SubPopulation 0 (), 3 Individuals:
   0: MU  |  |  100 0 0
   1: FU  |  |  101 0 0
   2: MU  |  |  200 0 0

In particular, note that ID 501 is in generation 1 and 0. I suspect this is a problem, because when I use this pedigree later with sim.PedigreeMating, Python crashes with:

terminate called after throwing an instance of 'simuPOP::RuntimeError'

I suppose this is a misuse of the pedigree object; is there a way to obtain what I want to do? Thanks!

BoPeng commented 7 years ago

A limitation of the existing loadPedigree implementation is that all individuals without parents will be placed in the top generation, so you would have to generate a few fake grandparents to complete the pedigree to place individuals in the right generation. This also applies to a pedigree mating scheme because all the genes will be dropped from the top generation.

BoPeng commented 7 years ago

After all, backward-time simulations could start from the last generation and determine the generation of all ancestors, forward-time simulations cannot do this unless we determine ancestor generations using a backward-time approach before forward-time simulation.