<p>I have 2 sets of bed files from ChIP-seq, A and B, and a certain number of peaks overlap. Now I want to put some kind of enrichment score / p-value on that overlap - if only 2 peaks overlap and A and B contain both 10 000 peaks, it&#39;s not really significant, while if 90 peaks overlap, A is 10000 peaks and B is 100, it&#39;s more significant.</p>

<p>The classical way to do this would be to do a hypergeometric test - all the variables of the test are easily filled in (number of draws, number of successes, number of &#39;failures&#39;) except one, the total population number. In this scenario it would be something similar to &#39;the total number of peaks one could potentially draw from the genome&#39;, which is impossible to estimate, and could be biased (regions that don&#39;t chip well, unmappable regions, etc).</p>

<p>What&#39;s the best way to put a &#39;score&#39; on an overlap between A and B then? The ultimate goal is to display some kind of heatmap, as I&#39;m doing the comparison between many A&#39;s and many B&#39;s.</p>

Something to this effect is available in the latest release of bedtools as [bedtools fisher][1].

It uses bases, rather than counts of peaks. Currently, it doesn't allow you to exclude regions like centromeres or "quiescient" regions that are unlikely to harbor overlaps and I have a PR with that as a work in progress, but it won't be ready for a while.

I have a ticket open to allow the use of counts of intervals, but it will suffer from determining the denominator as you suggest. I think that the total number of possible intervals could be the number of times an interval of the average size could fit into the genome.

For your stuff, you may want to check out [this paper][2] and the associated software.

 [1]: http://bedtools.readthedocs.org/en/latest/content/tools/fisher.html
 [2]: http://www.ncbi.nlm.nih.gov/pubmed/22262674