Hi Grace!
I assume that fitnessScaling code gives you an error, in fact? The
error is because it is a property that you need to assign a value
into; it looks like you are not doing any assignment, in the code
you posted.
To start with, I'd recommend that you do a for loop over
individuals, and treat each individual separately using the same
code that you have in your fitnessEffect() callback now, but
assigning the desired effect into fitnessScaling. Vectorization of
that code is then a separate step, once you've got the
non-vectorized version working.
For that vectorization, since
inds.haplosomes.countOfMutationsOfType() returns a vector of length
2 (one value per haplosome) it is difficult to incorporate into a
vectorized algorithm. You might have better luck using
inds.haploidGenome1.countOfMutationsOfType() and
inds.haploidGenome2.countOfMutationsOfType() to get separate logical
vectors, and then proceeding with your vectorized calculations from
there. I think the ifelse() function will also be useful to you,
since it is a vectorized version of the ?else operator you are using
in your fitnessEffect() callback. The SLiM workshop has a fair bit
of discussion of vectorization, if you're unfamiliar with it. If
you remain stuck after working on this for a while, feel free to
post again with your non-vectorized code using fitnessScaling.
I don't know whether any of this will actually speed up your model
much, though, since it might be that the large majority of the
runtime is spent in countOfMutationsOfType(). Searching through
haplosomes to find/count mutations is just a very slow thing to do.
If the total number of mutations in your model is small, maybe it
won't be too bad; if it is large, that will be the bottleneck for
sure. I notice that you appear to be modeling only one mutation
type, m1, and then you're counting m1 mutations. If so, rather than
countOfMutationsOfType() you could just use the number of mutations
in the haplosome – EXCEPT that I notice I never made a Haplosome
property for that! That's an oversight, whoops! It has never come
up before now, though; knowing the number of mutations is not
usually useful, but in your case perhaps it is! I've just opened an
issue on this at
https://github.com/MesserLab/SLiM/issues/612; this
property will be added in the next version of SLiM. (If you would
like to have it sooner than that, and are happy to build SLiM from
sources yourself following the instructions in chapter 2 of the
manual, then please comment on the issue to say so, and I'll have it
pushed to SLiM's GitHub repo ASAP).
I hope this helps! Good luck and happy modeling!
Cheers,
-B.
Benjamin C. Haller
Messer Lab
Cornell University