<p>The following is not the clearest explanation of dN/dS humankind has seen, but I hope you get the gist and core idea of likelihood is absolutely correct. I am wondering if you are thinking of a different test to the way I would do this calculation. This ain't a text book clarity answer.</p>
<p>Anyway what you are proposing is a likelihood ratio test (LRT) for  selection based on the parameterisation of omega. Your idea isn't quite correct ... its not dN/dS value you are looking at to assess significance, its the likelihood. This point is critical and is the most important difference in our thinking on this test.</p>
<p>LRT works because its a log likelihood and subtracting two log likelihood is the same as dividing them (I forget the theory - but you subtract the likelihood to work out the p-value via Chi squared). There's some theory about why the Chi-squared distribution works but I can't remember it.</p>
<p>You need to work out the degrees of freedom which is the parameter differences between 'free branch model' and the neutral model and this value is LOW. If the neutral model is the &quot;global model&quot;, then its 2 degrees of freedom - IN YOUR TREE. This is because the SP you are looking at form a single clade (monophyly). From memory you stick a #1 on the branch leading into the clade, ie. defining the node and thats your 'model' on the treefile. Here you have two dN/dS one for the whole tree excluding your clade and one for your taxa. This gives you a likelihood.</p>
<p><strong>Note</strong> you could stick a #1 on each branch within the clade, i.e. the treefile. That means something different - like every branch was subject to ... in this case purifying selection ... not just the common ancestor.</p>
<p>You now work out the likelihood of the 'global' model... i.e. remove the #1 and make sure it gives you only 1 dN/dS value.</p>
<p>Subtract the likelihoods and multiple by two - if its LRT (super important).</p>
<p>You now need to work out the degrees of freedom. If its the same model but one has an additional node with a different dN/dS ... the df = 2. If you've dumped a #1 on every branch in the clade ... I still think df = 2 - you need to check.</p>
<p>If the difference in likelihood results in <em>p</em> &lt; 0.05 you are correct the difference is significant ... whatever that difference might be.</p>
<p>If the neutral model is some different calculation of omega within the population genetics process (see <a href="https://journals.plos.org/plosgenetics/article?id=10.1371/journal.pgen.1000304" rel="nofollow noreferrer">here</a>) then it will be the parameter differences between your model and the 'neutral' model.</p>
<p><strong>To reiterate</strong>
I like simulations so much I type in reiterations ... So again the LRT usual will usually subtract one likelihood from another and THEM multiply the probability by two ... and compare the result on the Chi squared table for the difference in degrees of freedom. And again what you are looking at is not the value of dN/dS but the difference in LIKELIHOOD. That is very important. You need to be careful with the degrees of freedom on an LRT because they can introduce an additional subtraction constant, test dependings (its ages since I've done one so I can't remember).</p>
<p>If the test is significant and one dN/dS is x for the clade and y for the rest of the tree, then that differences is significant and if y is &gt;1 (bit unlikely) and x &lt; 1 then sure thats purifying selection. Usually clades evolve via positive selection rather than purifying selection.</p>
<p>From memory that is my understanding ... but if you have a neutral model of omega and a purifying model of omega ... yeah sort of, but usually thats for a 'global' model, i.e. no differences within the tree. In your case your interested in a specific clade. The idea is still the same its measured through likelihood.</p>
<p>Its so long since I've done this, but I do caution not to confuse two different tests.</p>
<hr />
<p>I do understand Yang et al did an MCMC for dN/dS ... what I'm thinking of here is maximum likelihood. You'd need to watch for that carefully and thats what you are referring to when you say Chi-squared, because that is LRT 100%. LRT is maximum likelihood.</p>

CC BY-SA 4.0
2020-11-22T18:46:46.687Z
Thank you very much for your time and all the explanation it wad really usefull !!! I also enjoy it since you know PAML implemented in biopython, I'm currently doing a dN/dS pairwise analysis (runmode=-2), but it doesn't seem to work, do you have an idea ? I've created a post here with more informations  : https://www.biostars.org/p/474752/
chippycentra
CC BY-SA 4.0
2020-11-22T19:59:08.863Z
Hi @chippycentra much appreciated. I'm afraid I've never done Biostars - I don't even have an account - ... but I will have a look and post my thoughts here. PAML does work but can be a bit fiddly.
M__
CC BY-SA 4.0
2020-11-19T17:34:55.923Z
2020-11-19T17:41:42.153Z
2020-11-19T17:41:42.153Z
M__
<p>I am posting this message because I need clarity about the analysis I want to perform.
In my analysis, I have a homologous gene in <strong>13 species</strong>, and I would like to evaluate the selection pressure of this gene (its dN/dS) in <strong>3 species</strong> of the tree and test if this value is significantly different from the neutral model (dN/dS = 1).</p>
<p>So here is the protocol I am considering, and I would like you to tell me if I am right or not:</p>
<p>To calculate this selection pressure, the ratio of non-synonymous to synonymous substitution rates (dN/dS) must be calculated.</p>
<p>For this I use CODEML implemented in ete3.</p>
<p>So I need :</p>
<pre><code>A phylogenetic tree of the gene (performed with the AA alignment of the gene via Iqtree)

A codon alignment (performed with the DNA alignment of the gene with pal2nal)

Mark branches in the tree. 
</code></pre>
<p>Here is the exemple where I want to get the <strong>dN/dS</strong> value of <strong>SP5,6</strong> and <strong>7</strong>.:</p>
<pre><code>         /-SP1
        /-|
       |   \-SP2
       |
     /-|      /-SP3
    |  |   /-|
    |  |  |   \-SP4
    |   \-|
    |     |   /-SP5
  /-|      \- |  /-SP6
 |  |         \-|   
 |  |           |
 |  |            \-SP7
 |  |
 |  |   /-SP8
-|   \-|
 |      \-SP9
 |
 |     /-SP10
 |  /-|
 | |   \-SP11
 |-|     
   |   /-SP12
    \-|
       \-SP13
</code></pre>
<p>And I want to calculate the <strong>dN/dS</strong> of <code>SP5,SP6</code> and <code>SP7</code> in order to confirme the hypotesis that the gene is under strong purifying selection on this 3 species.</p>
<p>I mark the SP5, SP6 and SP7, run a <code>free-branch</code> model and look at the Codeml output (the dN/dS value should be the same for the 3 marked species right?) Then this value is kind of the mean dN/dS value between three leafs?</p>
<p>Suppose I get an omega = <strong>0.15</strong>
If I want to test that this value is significantly different from 1, I need to mark the same sheets and run the neutral model, then compare the two models (<code>neutral</code> vs. <code>free</code>) using chi2, and if the p-value is <code>&lt;0.5</code>, then the dN/dS value (<strong>0.15</strong>) is significantly different from 1.
I'm right  ?</p>

CC BY-SA 4.0
2020-11-19T09:43:07.777Z
Hi @chippycentra ... thats a funny username mixing.crossing cultural colloquialisms from very different regions, Ireland and the Northern GB! Anyway your question is fine but you need to provide some code. I get what you are doing, this is Python. Otherwise the response will be equally as vague. I do not think codeml is implemented in ETE3 ... I may have missed recent developments, but I'd be surprised if ETE3's developers have gone down that path.
M__
CC BY-SA 4.0
2020-11-19T09:43:09.143Z
Hello, ahah I did not know that it was a random username ^.^. Well I used this protocol http://etetoolkit.org/docs/latest/tutorial/tutorial_adaptation.html#test-on-branches) ete3 implemented codeml (they still use codeml but with a python code).  I edited the post in order to be more precise.
chippycentra
CC BY-SA 4.0
2020-11-19T09:49:03.073Z
There is no way that is a random username ... anyway you are right about CODEML. I want to read how they have done this first because it would imply CODEML (UCL, UK) have teamed up with the ETE3 guys (Spain).  Its possible CODEML code was just given to ETE3 and has changed its user license. I can give you the answer in terms of CODEML outside ETE3, but inside it ... this is new to me.
M__
CC BY-SA 4.0
2020-11-19T09:54:55.717Z
Well, since ete3 simply write a script for codeml and then run this script on it, you can give my an answer with codeml and i will understand :-)
chippycentra
CC BY-SA 4.0
2020-11-19T10:36:44.727Z
Okay, not till the weekend, its just that Biopython was the standard wrapper for this sort of stuff so I'm astonished by the ETE3 thing.
M__
CC BY-SA 4.0
2020-11-19T11:32:57.133Z
it is juste that ete3 allows to deal easily with trees I guess
chippycentra
CC BY-SA 4.0
2020-11-19T12:39:41.300Z
In my opinion .. it is very good for handling and traversing trees and great in data pipelines. As a CODEML wrapper I never knew it existed.
M__
CC BY-SA 4.0
2020-11-19T14:21:03.083Z
@Michael Just as an aside, do you know a software that allows, from an alignment of n sequences, to calculate the dN, dS, dN/dS between each pairwise sequence? But with a robust method such as likelihood (and not a counting method).
chippycentra
CC BY-SA 4.0
2020-11-19T14:54:49.470Z
Please see this post https://bioinformatics.stackexchange.com/questions/14801/multiple-alignment-cost-application/14813#14813 ... I'm not a fan of what I think you are proposing, but I might be wrong in what you are asking
M__
<phylogenetics><phylogeny><positive-selection>
Measure the purifying selection for certain taxa along a phylogeny
# Measure the purifying selection for certain taxa along a phylogeny

(Asked by: username_0 on 2020-11-19)

I am posting this message because I need clarity about the analysis I want to perform.
In my analysis, I have a homologous gene in 13 species, and I would like to evaluate the selection pressure of this gene (its dN/dS) in 3 species of the tree and test if this value is significantly different from the neutral model (dN/dS = 1).
So here is the protocol I am considering, and I would like you to tell me if I am right or not:
To calculate this selection pressure, the ratio of non-synonymous to synonymous substitution rates (dN/dS) must be calculated.
For this I use CODEML implemented in ete3.
So I need :
A phylogenetic tree of the gene (performed with the AA alignment of the gene via Iqtree)

A codon alignment (performed with the DNA alignment of the gene with pal2nal)

Mark branches in the tree. 

Here is the exemple where I want to get the dN/dS value of SP5,6 and 7.:
         /-SP1
        /-|
       |   \-SP2
       |
     /-|      /-SP3
    |  |   /-|
    |  |  |   \-SP4
    |   \-|
    |     |   /-SP5
  /-|      \- |  /-SP6
 |  |         \-|   
 |  |           |
 |  |            \-SP7
 |  |
 |  |   /-SP8
-|   \-|
 |      \-SP9
 |
 |     /-SP10
 |  /-|
 | |   \-SP11
 |-|     
   |   /-SP12
    \-|
       \-SP13

And I want to calculate the dN/dS of SP5,SP6 and SP7 in order to confirme the hypotesis that the gene is under strong purifying selection on this 3 species.
I mark the SP5, SP6 and SP7, run a free-branch model and look at the Codeml output (the dN/dS value should be the same for the 3 marked species right?) Then this value is kind of the mean dN/dS value between three leafs?
Suppose I get an omega = 0.15
If I want to test that this value is significantly different from 1, I need to mark the same sheets and run the neutral model, then compare the two models (neutral vs. free) using chi2, and if the p-value is <0.5, then the dN/dS value (0.15) is significantly different from 1.
I'm right  ?

**Tags:** phylogenetics, phylogeny, positive-selection
> **Comments:**
> **username_1**: Hi @chippycentra ... thats a funny username mixing.crossing cultural colloquialisms from very different regions, Ireland and the Northern GB! Anyway your question is fine but you need to provide some code. I get what you are doing, this is Python. Otherwise the response will be equally as vague. I do not think codeml is implemented in ETE3 ... I may have missed recent developments, but I'd be surprised if ETE3's developers have gone down that path.  
> **username_0**: Hello, ahah I did not know that it was a random username ^.^. Well I used this protocol http://etetoolkit.org/docs/latest/tutorial/tutorial_adaptation.html#test-on-branches) ete3 implemented codeml (they still use codeml but with a python code).  I edited the post in order to be more precise.  
> **username_1**: There is no way that is a random username ... anyway you are right about CODEML. I want to read how they have done this first because it would imply CODEML (UCL, UK) have teamed up with the ETE3 guys (Spain).  Its possible CODEML code was just given to ETE3 and has changed its user license. I can give you the answer in terms of CODEML outside ETE3, but inside it ... this is new to me.  
> **username_0**: Well, since ete3 simply write a script for codeml and then run this script on it, you can give my an answer with codeml and i will understand :-)  
> **username_1**: Okay, not till the weekend, its just that Biopython was the standard wrapper for this sort of stuff so I'm astonished by the ETE3 thing.  
> **username_0**: it is juste that ete3 allows to deal easily with trees I guess  
> **username_1**: In my opinion .. it is very good for handling and traversing trees and great in data pipelines. As a CODEML wrapper I never knew it existed.  
> **username_0**: @Michael Just as an aside, do you know a software that allows, from an alignment of n sequences, to calculate the dN, dS, dN/dS between each pairwise sequence? But with a robust method such as likelihood (and not a counting method).  
> **username_1**: Please see this post https://bioinformatics.stackexchange.com/questions/14801/multiple-alignment-cost-application/14813#14813 ... I'm not a fan of what I think you are proposing, but I might be wrong in what you are asking  

---

## 1 answers

### Answer by username_1 on 2020-11-19. Score: 1 | Accepted answer

The following is not the clearest explanation of dN/dS humankind has seen, but I hope you get the gist and core idea of likelihood is absolutely correct. I am wondering if you are thinking of a different test to the way I would do this calculation. This ain't a text book clarity answer.

Anyway what you are proposing is a likelihood ratio test (LRT) for selection based on the parameterisation of omega. Your idea isn't quite correct ... its not dN/dS value you are looking at to assess significance, its the likelihood. This point is critical and is the most important difference in our thinking on this test.

LRT works because its a log likelihood and subtracting two log likelihood is the same as dividing them (I forget the theory - but you subtract the likelihood to work out the p-value via Chi squared). There's some theory about why the Chi-squared distribution works but I can't remember it.

You need to work out the degrees of freedom which is the parameter differences between 'free branch model' and the neutral model and this value is LOW. If the neutral model is the "global model", then its 2 degrees of freedom - IN YOUR TREE. This is because the SP you are looking at form a single clade (monophyly). From memory you stick a #1 on the branch leading into the clade, ie. defining the node and thats your 'model' on the treefile. Here you have two dN/dS one for the whole tree excluding your clade and one for your taxa. This gives you a likelihood.

**Note** you could stick a #1 on each branch within the clade, i.e. the treefile. That means something different - like every branch was subject to ... in this case purifying selection ... not just the common ancestor.

You now work out the likelihood of the 'global' model... i.e. remove the #1 and make sure it gives you only 1 dN/dS value.

Subtract the likelihoods and multiple by two - if its LRT (super important).

You now need to work out the degrees of freedom. If its the same model but one has an additional node with a different dN/dS ... the df = 2. If you've dumped a #1 on every branch in the clade ... I still think df = 2 - you need to check.

If the difference in likelihood results in *p* < 0.05 you are correct the difference is significant ... whatever that difference might be.

If the neutral model is some different calculation of omega within the population genetics process (see [here](https://journals.plos.org/plosgenetics/article?id=10.1371/journal.pgen.1000304)) then it will be the parameter differences between your model and the 'neutral' model.

**To reiterate**
I like simulations so much I type in reiterations ... So again the LRT usual will usually subtract one likelihood from another and THEM multiply the probability by two ... and compare the result on the Chi squared table for the difference in degrees of freedom. And again what you are looking at is not the value of dN/dS but the difference in LIKELIHOOD. That is very important. You need to be careful with the degrees of freedom on an LRT because they can introduce an additional subtraction constant, test dependings (its ages since I've done one so I can't remember).

If the test is significant and one dN/dS is x for the clade and y for the rest of the tree, then that differences is significant and if y is >1 (bit unlikely) and x < 1 then sure thats purifying selection. Usually clades evolve via positive selection rather than purifying selection.

From memory that is my understanding ... but if you have a neutral model of omega and a purifying model of omega ... yeah sort of, but usually thats for a 'global' model, i.e. no differences within the tree. In your case your interested in a specific clade. The idea is still the same its measured through likelihood.

Its so long since I've done this, but I do caution not to confuse two different tests.

---

I do understand Yang et al did an MCMC for dN/dS ... what I'm thinking of here is maximum likelihood. You'd need to watch for that carefully and thats what you are referring to when you say Chi-squared, because that is LRT 100%. LRT is maximum likelihood.

> **Comments:**
> **username_0**: Thank you very much for your time and all the explanation it wad really usefull !!! I also enjoy it since you know PAML implemented in biopython, I'm currently doing a dN/dS pairwise analysis (runmode=-2), but it doesn't seem to work, do you have an idea ? I've created a post here with more informations  : https://www.biostars.org/p/474752/  
> **username_1**: Hi @chippycentra much appreciated. I'm afraid I've never done Biostars - I don't even have an account - ... but I will have a look and post my thoughts here. PAML does work but can be a bit fiddly.  

---

