subset individual method

21 views
Skip to first unread message

Rohini Janivara

unread,
Apr 25, 2024, 4:56:48 PMApr 25
to slim-discuss
Hi all,

I was wondering if there's a way to calculate frequencies in a subset of individuals? I am trying to subset all individuals in the final tick, based on their mutation status for a particular mutation and calculate allele frequencies of all other mutations only within this subset. But I seem to encounter an error which I think might be because the .mutationFrequenciesinGenomes() function is trying to calculate frequencies after iterating through genomes individually rather than on the whole subset.

200003 late(){

catn("\nPersistent selective mutants:");
for (selecmut in sim.mutationsOfType(m1)){
if (sim.mutationFrequencies(p1,selecmut)>0.00002){
catn("Origin tick = "+selecmut.originTick);
//hasmut=which(p1.individuals.containsMutations(selecmut));
catn("Adv Mut frqs conditioned on advmutant: "+p1.individuals[p1.individuals.containsMutations(selecmut)].genomes.mutationFrequenciesinGenomes(sim.mutationsOfType(m1)));
catn("Neutral Mut frqs conditioned on advmutant: "+p1.individuals[p1.individuals.containsMutations(selecmut)].genomes.mutationFrequenciesinGenomes(sim.mutationsOfType(m2)));
}
}
}
The error returned is 

ERROR (EidosInterpreter::Evaluate_Call): method mutationFrequenciesinGenomes() is not defined on object element type Genome.

Error on script line 97, character 116:

      catn("Adv Mut frqs conditioned on advmutant: "+p1.individuals[p1.individuals.containsMutations(selecmut)].genomes.mutationFrequenciesinGenomes(sim.mutationsOfType(m1)));

All of this is to calculate frequencies of all mutations conditioned on certain selective mutations (ie, given a sample of individuals in the end possessing a particular advantageous mutation, what are the allele frequencies of all other mutations in the sample).

I would appreciate any help regarding this. I can also provide the rest of my code if it could be relevant.

Thanks!
Rohini

Rohini Janivara

unread,
Apr 25, 2024, 5:05:44 PMApr 25
to slim-discuss
When I print out the genomes using
catn(p1.individuals[p1.individuals.containsMutations(selecmut)].genomes);

 this is the output I see
Genome<A:14> Genome<A:11> Genome<A:14> Genome<A:11>

So this does indeed output (a vector?) or genomes

Ben Haller

unread,
Apr 26, 2024, 3:51:42 AMApr 26
to Rohini Janivara, slim-discuss
Hi Rohini!

The error you're getting is simply because you have misspelled the name of the method.  Method "mutationFrequenciesinGenomes()" is indeed not defined on Genome, but method "mutationFrequenciesInGenomes()" is; note the capital "I".

That said, I'm not sure this code is doing what you want it to do.  The problem is with the use of the + operator here on strings.  A simple example in the Eidos console:

> x = 1:10
> "foo" + x
"foo1" "foo2" "foo3" "foo4" "foo5" "foo6" "foo7" "foo8" "foo9" "foo10"

As with other operators in Eidos, the + operator is vectorized; asked to add 1:10 to "foo", it produces the result shown above.  This results in output like:

Adv Mut frqs conditioned on advmutant: 0.519608 Adv Mut frqs conditioned on advmutant: 0.0294118 Adv Mut frqs conditioned on advmutant: 0.00980392 Adv Mut frqs conditioned on advmutant: 0.411765 Adv Mut frqs conditioned on advmutant: 0.539216 Adv Mut frqs conditioned on advmutant: 0.990196 Adv Mut frqs conditioned on advmutant: 0.0294118 Adv Mut frqs conditioned on advmutant: 0.0 Adv Mut frqs conditioned on advmutant: 0.0 Adv Mut frqs conditioned on advmutant: 0.0 Adv Mut frqs conditioned on advmutant: 0.0 Adv Mut frqs conditioned on advmutant: 0.00980392 Adv Mut frqs conditioned on advmutant: 0.0 Adv Mut frqs conditioned on advmutant: 0.0

What I think you want is to use paste() to generate a string of output values first, like:

> x = 1:10 > y = paste(x) > "Adv Mut...: " + y "Adv Mut...: 1 2 3 4 5 6 7 8 9 10"


I think this probably answers the next question you asked, so I'll leave my replies at that.  The only other thing I'll mention is that this expression:

p1.individuals[p1.individuals.containsMutations(selecmut)].genomes

is a pretty expensive thing for SLiM to compute, for a large model; since you use it twice in your code, it might be a good idea (and make the code easier to read) if you cached it in a local variable so that it is only computed once (per time through the selecmut loop, of course).

Of course follow up if you have further questions.  Happy modeling!

Cheers,
-B.

Benjamin C. Haller
Messer Lab
Cornell University


Rohini Janivara wrote on 4/25/24 4: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/3e5b0de7-096f-4bd1-8856-5c65ea7b2addn%40googlegroups.com.

Ben Haller

unread,
Apr 26, 2024, 4:02:08 AMApr 26
to Rohini Janivara, slim-discuss
Hi Rohini!

Ah, this question is a bit different, actually, so I'll reply to it as well.

Here's a bit of exploration in the Eidos console, after running the default neutral model in SLiMgui:

> i = p1.individuals[0]
> i.genomes
Genome<A:2> Genome<A:2>

> i = p1.individuals[1]
> i.genomes
Genome<A:21> Genome<A:17>

So the two genomes of a given individual produce the same output in one case, which shows simply that each is an autosome ("A") and that each contains two mutations ("2").  In the other case, the two genomes happen to have different numbers of mutations (21 and 17).

Your code appears to have resulted in printing a vector of four genomes, containing 14, 11, 14, and 11 mutations respectively.  If you don't find that output useful (it is just for debugging), you could instead print, say, the genomePedigreeID property of the genomes, if you turned on pedigree tracking; that would then provide a unique id for each genome in the simulation.

I hope this helps.  Happy modeling!


Cheers,
-B.

Benjamin C. Haller
Messer Lab
Cornell University


Rohini Janivara wrote on 4/25/24 5:05 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.
Reply all
Reply to author
Forward
0 new messages