<p>Sorry I've got my head around your question. For Fisher's Exact you need 2 &quot;independent&quot; observations and for SciPy its a 2x2 table.</p>
<p>So in your case ...</p>
<div class="s-table-container"><table class="s-table">
<thead>
<tr>
<th>Genome</th>
<th>Species A</th>
<th>Species B</th>
</tr>
</thead>
<tbody>
<tr>
<td>Pan</td>
<td>6.07</td>
<td>6.10</td>
</tr>
<tr>
<td>Core</td>
<td>6.08</td>
<td>6.12</td>
</tr>
</tbody>
</table></div>
<p>If you think about it, thats a better way of doing it because thats comparing pan vs core between species. A single observation isn't sufficient. To really do this you need 2 x 10 type contingency tables but SciPy will not do that, but you can do it in RStudio. For example using 10 species rather than just 2 ... and thats a real test of pan/core. My advice is to have your test species and in the other column have your control species ... like E. coli that sort of thing.</p>
<p>The SciPy solution is here. Place your data in a list of lists here its <code>mylist</code>. Next place into a numpy array and place that in a scipy function, like this...</p>
<pre><code>import numpy as np
from scipy.stats import fisher_exact
mylist = [[6.07, 6.08], [6.10, 6.12]]
mytable = np.array(mylist)
res = fisher_exact(mytable, alternative='two-sided')
print (res.pvalue)
</code></pre>
<p>It should print the p value where &gt; 0.05 is not significant.</p>
<p>To start doing 2 x &gt;2 contingency tables in Python r2py is needed and from my experience (albeit about 5 years ago) I wouldn't advise it. r2py is a disaster when I tried to use it and just did the calculations in RStudio.</p>

CC BY-SA 4.0
2024-02-19T12:11:55.063Z
Hi @M__ thank you so much for your input. Will try doing it with Rstudio.
K_081
CC BY-SA 4.0
2024-02-19T13:25:46.527Z
Thanks @K_081 it should work fine.
M__
CC BY-SA 4.0
2024-02-23T02:37:59.167Z
Hi @M__ , I have added a table to my question for clarity, could you possibly go through that? I want to compare the proportion of "C" or other COG categories between the pan, core and the others, not between species as all the species I need for the analysis are included in the pan, core. Sorry for all the trouble and thanks a lot, if you can look at this again.
K_081
CC BY-SA 4.0
2024-02-23T03:48:36.773Z
@K_081 could you kindly ask this as a separate question please and link this question within it? It doesn't look easy but I know what COGs are.
M__
CC BY-SA 4.0
2024-02-23T05:42:42.390Z
Done @M__ : https://bioinformatics.stackexchange.com/questions/22210/calculating-fishers-exact-test-for-cog-categories
K_081
CC BY-SA 4.0
2024-01-30T23:00:29.033Z
2024-02-14T13:47:54.240Z
2024-02-14T13:47:54.240Z
M__
<p>I have come across several papers that do a Fisher's exact test to show over represented genes in COG categories specifically in a pan-core-accessory-species specific genome analysis. The test is done to show over represented genes in the core, accessory and species specific datasets as compared to the pan genome. Here is one such paper - <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9101195/#:%7E:text=cincinnatiensis%2C%20represented%20as%20a%20species,septicemia%20and%20meningitis%20%5B6%5D." rel="nofollow noreferrer">Vibrio cincinnatiensis - comparative genome analysis</a></p>
<p>Usually, the way the pan and core genome analysis is represented in papers is by showing the proportion of genes in each of the COG categories in both. For example, the proportion of C (Energy production and conversion) could be 6.07 in the pan but 6.8 in the core genome. The Fisher's exact test is used to show that this particular category is over represented in the core genome as compared to the pan.</p>
<p>I already have the csv files from eggNOG from which I filtered out the genes in major COG categories for the pan, core, accessory and species-specific genomes into a single Excel sheet for 8 closely related genomes. Could someone tell me how to perform this test on this dataset?</p>
<p>My null hypothesis is that the proportion of genes in the pan, core, accessory and species specific genomes is the same. But, obviously this analysis is done to show how the proportions vary in some COG categories between the above mentioned 4 genome datasets.</p>
<p>I did try using python and R as well, but the test requires 2 rows and columns and here I am just comparing two columns (pan, core) with respect to 1 row - the 'C' category. It seems impossible to apply the test to this problem and I am sure I am missing something and that's why I posted it here.</p>
<p>I tried doing the Fisher's test on the proportions I mentioned previously (6.07 and 6.8) but I am getting an error : 'Fisher's test requires two rows and two columns'. Should I compare the absolute values, like '3745' genes in the pan and '4195' genes in the core?</p>
<p><a href="https://i.sstatic.net/Y3XVJ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Y3XVJ.png" alt="An example dataset for COG categories in pan, core, accessory and species specific genomes" /></a></p>

CC BY-SA 4.0
2024-01-30T16:10:14.303Z
Please [edit] your question and clarify what you want to test.
terdon
<r><eggnog><pangenome>
Fisher's exact test for COG categories in pan, core genome analysis
# Fisher's exact test for COG categories in pan, core genome analysis

(Asked by: username_0 on 2024-01-30)

I have come across several papers that do a Fisher's exact test to show over represented genes in COG categories specifically in a pan-core-accessory-species specific genome analysis. The test is done to show over represented genes in the core, accessory and species specific datasets as compared to the pan genome. Here is one such paper - [Vibrio cincinnatiensis - comparative genome analysis](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9101195/#:%7E:text=cincinnatiensis%2C%20represented%20as%20a%20species,septicemia%20and%20meningitis%20%5B6%5D.)

Usually, the way the pan and core genome analysis is represented in papers is by showing the proportion of genes in each of the COG categories in both. For example, the proportion of C (Energy production and conversion) could be 6.07 in the pan but 6.8 in the core genome. The Fisher's exact test is used to show that this particular category is over represented in the core genome as compared to the pan.

I already have the csv files from eggNOG from which I filtered out the genes in major COG categories for the pan, core, accessory and species-specific genomes into a single Excel sheet for 8 closely related genomes. Could someone tell me how to perform this test on this dataset?

My null hypothesis is that the proportion of genes in the pan, core, accessory and species specific genomes is the same. But, obviously this analysis is done to show how the proportions vary in some COG categories between the above mentioned 4 genome datasets.

I did try using python and R as well, but the test requires 2 rows and columns and here I am just comparing two columns (pan, core) with respect to 1 row - the 'C' category. It seems impossible to apply the test to this problem and I am sure I am missing something and that's why I posted it here.

I tried doing the Fisher's test on the proportions I mentioned previously (6.07 and 6.8) but I am getting an error : 'Fisher's test requires two rows and two columns'. Should I compare the absolute values, like '3745' genes in the pan and '4195' genes in the core?

[![An example dataset for COG categories in pan, core, accessory and species specific genomes](https://i.sstatic.net/Y3XVJ.png)](https://i.sstatic.net/Y3XVJ.png)

**Tags:** r, eggnog, pangenome
> **Comments:**
> **username_1**: Please [edit] your question and clarify what you want to test.  

---

## 1 answers

### Answer by username_2 on 2024-01-30. Score: 1 | Accepted answer

Sorry I've got my head around your question. For Fisher's Exact you need 2 "independent" observations and for SciPy its a 2x2 table.
So in your case ...



Genome
Species A
Species B




Pan
6.07
6.10


Core
6.08
6.12



If you think about it, thats a better way of doing it because thats comparing pan vs core between species. A single observation isn't sufficient. To really do this you need 2 x 10 type contingency tables but SciPy will not do that, but you can do it in RStudio. For example using 10 species rather than just 2 ... and thats a real test of pan/core. My advice is to have your test species and in the other column have your control species ... like E. coli that sort of thing.
The SciPy solution is here. Place your data in a list of lists here its mylist. Next place into a numpy array and place that in a scipy function, like this...
import numpy as np
from scipy.stats import fisher_exact
mylist = [[6.07, 6.08], [6.10, 6.12]]
mytable = np.array(mylist)
res = fisher_exact(mytable, alternative='two-sided')
print (res.pvalue)

It should print the p value where > 0.05 is not significant.
To start doing 2 x >2 contingency tables in Python r2py is needed and from my experience (albeit about 5 years ago) I wouldn't advise it. r2py is a disaster when I tried to use it and just did the calculations in RStudio.

> **Comments:**
> **username_0**: Hi @M__ thank you so much for your input. Will try doing it with Rstudio.  
> **username_2**: Thanks @K_081 it should work fine.  
> **username_0**: Hi @M__ , I have added a table to my question for clarity, could you possibly go through that? I want to compare the proportion of "C" or other COG categories between the pan, core and the others, not between species as all the species I need for the analysis are included in the pan, core. Sorry for all the trouble and thanks a lot, if you can look at this again.  
> **username_2**: @K_081 could you kindly ask this as a separate question please and link this question within it? It doesn't look easy but I know what COGs are.  
> **username_0**: Done @M__ : https://bioinformatics.stackexchange.com/questions/22210/calculating-fishers-exact-test-for-cog-categories  

---

