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

MlSelector with Loci=sim.ALL_AVAIL not working #111

Closed cruzan-lab closed 11 months ago

cruzan-lab commented 1 year ago

With two loci each with two alleles. In preOps I'm using:

sim.MlSelector([
    sim.MapSelector(loci=[0, 1], fitness={(0,0):1, (0,1):1, (1,1):.8})],
    mode = sim.ADDITIVE)

or

sim.MlSelector([
    sim.MapSelector(loci=sim.ALL_AVAIL, fitness={(0,0):1, (0,1):1, (1,1):.8})],
    mode = sim.ADDITIVE)

both of these generates an error message saying that fitness is not defined (it's defined for both homozygotes but not for heterozygotes). If I use:

sim.MlSelector([
    sim.MapSelector(loci=0, fitness={(0,0):1, (0,1):1, (1,1):.8}),
    sim.MapSelector(loci=1, fitness={(0,0):1, (0,1):1, (1,1):.8})],
    mode = sim.ADDITIVE)

then it works just fine. I'm trying to apply the same fitness levels to a large number of loci. There must be some additioanl trick to get "sim.ALL_AVAIL" to work. Please let me know what it is. Thanks Mitch

cruzan-lab commented 1 year ago

Hoping for a response soon.

BoPeng commented 1 year ago

The documentation says

although less used because of potentially a large number of keys, this operator can act on multiple loci

which means if you have loci=[0, 1] or loci=sim.ALL_AVAIL, you are supposed to list all combination of genotypes, which is certainly a bad idea for a large number of loci.

For your case,

sim.MlSelector([
    sim.MapSelector(loci=x, fitness={(0,0):1, (0,1):1, (1,1):.8}) for x in range(pop.totNumLoci())],
    mode = sim.ADDITIVE)

looks easy enough to specify a list of MapSelector using list comprehension.