Tracking allele frequency of m2 in each subpopulation

16 views
Skip to first unread message

Héctor Alessandro López Hérnandez

unread,
May 17, 2024, 12:56:34 PMMay 17
to slim-discuss
Hi Ben! Me again

I am trying to follow the frequency of m2 in each generation/tick in a two-dimensional subpopulation matrix (50x50) from the next code:

initialize() {

initializeSex("A"); //autosomal chr

initializeMutationRate(1e-7);

initializeMutationType("m1", 0.5, "f", 0.0);

initializeMutationType("m2", 0.5, "f", 0.01); //positive mutation

initializeGenomicElementType("g1", m1, 1.0);

initializeGenomicElement(g1, 0, 99999);

initializeRecombinationRate(1e-7);

}

//create our two dimensional subpopulation matrix of metapopSide x metapopSide with 100 individuals

1 late() {

metapopSide=50;

metapopSize=metapopSide*metapopSide;

for (i in 1:metapopSize)

sim.addSubpop(i,100);

//migration rates btwn each subpop

subpops = sim.subpopulations;

for (x in 1:metapopSide)

for (y in 1:metapopSide)

{

destID = (x - 1) + (y - 1) * metapopSide + 1;

ds = subpops[destID - 1];

if (x > 1) // left to right

ds.setMigrationRates(destID - 1, 0.05);

if (x < metapopSide) // right to left

ds.setMigrationRates(destID + 1, 0.05);

if (y > 1) // top to bottom

ds.setMigrationRates(destID - metapopSide, 0.05);

if (y < metapopSide) // bottom to top

ds.setMigrationRates(destID + metapopSide, 0.05);

// set up SLiMgui's population visualization nicely

xd = ((x - 1) / (metapopSide - 1)) * 0.9 + 0.05;

yd = ((y - 1) / (metapopSide - 1)) * 0.9 + 0.05;

ds.configureDisplay(c(xd, yd), 0.4);

}



}

//adding new beneficial mutation in 25 inds in p1

1 late() {

target=sample(p1.genomes,50);

target.addNewDrawnMutation(m2,rdunif(1,0,sim.chromosome.lastPosition));


}

//following in each thick the number of chr which contains the beneficial mutation in each subpopulation

1:200 late() {

sweep = sim.mutationsOfType(m2);

if (size(sweep) > 0) {

for (subpop in sim.subpopulations) {

freq = sim.mutationFrequencies(subpop, sweep);

catn(sim.cycle + ": " + freq + subpop); <-MY PROBLEM!

}

}

}


However, I can't get the subpopulation where it is calculated the freq. I am interest in it even if this number is 0 because I want in search the velocity of dispersion of an allele under this model.


Sorry and thanks



Ben Haller

unread,
May 21, 2024, 2:43:21 AMMay 21
to Héctor Alessandro López Hérnandez, slim-discuss
Hi Héctor!  Thanks for the complete code for this question; that makes it much easier to reproduce the problem.

The error message generated by your code is:

ERROR (EidosValue::StringAtIndex_CAST): operand type object cannot be converted to type string.

As the message says, SLiM does not know how to convert an object (the subpopulation) into a string (which is what the + operator here wants to do).  The print() function can print a subpopulation object as a string, but that involves special smarts that only print() and cat()/catn() have; in general, objects cannot be treated as strings.

You probably want to print the id of the subpopulation?  So then just access that property, which is an integer and thus can be converted to a string:

catn(sim.cycle + ": " + freq + " " + subpop.id);

Or if you want to get "p3" instead of just "3", then do:

catn(sim.cycle + ": " + freq + " p" + subpop.id);

I hope this makes sense.  In general, I have tried to make the error messages given by SLiM/Eidos informative; if you get an error, don't just say "Aaargh, I got an error!" and despair; look at what the error message is telling you, and think carefully about what it means, and it will often lead you to the solution.  :->  Happy modeling!

Cheers,
-B.

Benjamin C. Haller
Messer Lab
Cornell University


Héctor Alessandro López Hérnandez wrote on 5/17/24 6:56 PM:
--
SLiM forward genetic simulation: http://messerlab.org/slim/
---
You received this message because you are subscribed to the Google Groups "slim-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to slim-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/slim-discuss/0e0fa689-2c1c-47d4-956f-106ece0c7e19n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages