# Hypergeometic test for the overlap of two set of genomic intervals (e.g. from Chip-seq data)

Suppose I have done two Chip-seq experiments. Now after the bias correction step such as MACS2, I get two set of genomic intervals (or peaks, as what is usually called) that corresponds to each of the experiment. I want to test the significance of the overlap of these two set genomic intervals that corresponds to each experiment.

The common test employed seemed to me is the Hypergeometic test. There's even a package specifically aim for this task: ChiPpeakAnno.

Recall from the Hypergeometric distrbition -- the analogy is that we have a bag of marbles with two different colors, say one blue and another red. A sample from such distribution consists of marbles drawn from this bag, and a probability measure for this distribution is the number of blue marbles in the sample.

Could someone explain what is the correspondence between the hypergeometric test and the significance overlap between two different set of genomic intervals?

• Interesting dicussion, its about sampling error in minority populations and whether this sampling error can throw a spurious "they are different result", when in fact its a sampling bias.
– M__
May 17 '20 at 12:41

There is no such thing as a hypergeometric test, at least in statistical textbooks. It's a fisher test based on hypergeometric distribution.

If it is chip-seq for the same target, i.e biological replicates, significance of overlap is not quite meaningful. You get more information by for example checking the correlation of the coverage between your replicates using deeptools or anything else.

If you are comparing between two different targets, for example, chip for two different histone marks, you can use the fisher test or chi-square this way.

1. Partition the genome in X bp bins, these are all your marbles
2. Identity those that overlap with peaks from target 1 and those that don't
3. Do 2. for target2
4. construct a contingency table using 2 and 3.

So you should end up with something like this (purely made up):

                      no_overlap_target2 overlap_target2
no_overlap_target1               9799             112
overlap_target1                    88               1


And if there is overlap, the bottom diagonal with be higher.. less on the off-diagonal, and you can test it with a fisher.test.

• So in your table, top left is the sum of the number of intervals in target1 and target2 that are not overlapping each other? Also the off-diagonal is the the number of target 1 that is not overlapping with target2 and vice versa?
– skc
May 18 '20 at 15:23
• sorry.. not very clear, this table is for example, we partition the genome into 10000 bins.. 9799 don't have target 1 or target 2, off diagonal is found in target2 but not in target1 May 18 '20 at 15:27
• Ah, I see. Thanks! Now I think I know how to do.
– skc
May 18 '20 at 15:42
• Yes, I have two targets. I think I'll just go ahead and use Granges package in R to do this task.
– skc
May 18 '20 at 15:44
• Do you mind if you could explain why this is corresponds to the hypergeometric distribution in this setting? In particular, why does "drawing the blue ball" from the urn corresponds to X-bp bins that are not in target1 nor target2?
– skc
May 18 '20 at 20:39

Just to make sure, I took a quick look at chippeakanno, and it uses a hypergeometric test for gene enrichment, not necessarily overlap of two chip-seq results.

As you mentioned, you can imagine in your set of genes, you have those that overlap with your peaks, and those that do not. Hypergeometric distribution calculates the probability of getting a certain number of genes that overlap with your peaks (which is the same as sampling some balls and calculate the p-value of some balls with one color). The hypergeometric test calculates a p-value to see whether this number of overlapping genes is more than expected.

I also read on Wikipedia that the P-value of hypergeometric test times 2 is exactly the P-value for Fisher's exact test. Fisher's exact test tests whether your overlap is more than (or less than) expectation. Hypergeometric tests just feel like a one-tailed version of Fisher's exact tests.