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

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

  • $\begingroup$ Please edit your question and clarify what you want to test. $\endgroup$
    – terdon
    Jan 30 at 16:10

1 Answer 1


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.

  • 1
    $\begingroup$ Hi @M__ thank you so much for your input. Will try doing it with Rstudio. $\endgroup$
    – K_081
    Feb 19 at 12:11
  • $\begingroup$ Thanks @K_081 it should work fine. $\endgroup$
    – M__
    Feb 19 at 13:25
  • $\begingroup$ 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. $\endgroup$
    – K_081
    Feb 23 at 2:37
  • $\begingroup$ @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. $\endgroup$
    – M__
    Feb 23 at 3:48
  • 1
    $\begingroup$ Done @M__ : bioinformatics.stackexchange.com/questions/22210/… $\endgroup$
    – K_081
    Feb 23 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.