How to calculate p-value of a sample sum for a sample/subset from a given distribution? I am totally new here :-)
I have a following distribution, where a first column coresponds to the items' attribute count (specifically: number of occurences of a certain motif in a gene's regulatory region) and the second to the number of items (here: number of genes) with that attribute count.
0   5994
1   7907
2   5418
3   2799
4   1230
5   431
6   151
7   40
8   17
9   7
10  3
11  2
12  1

I have a specific list of let's say 100 genes. I would like to assess probability that a total number of motifs (sum of counts) in any 100-gene set is equal or higher than a sum of counts in this specific 100-gene list. In other words, calculate a p-value.
What is the best way of calculating it? I am working in R. Is there any R package that I could use? Or maybe in other programs/ languages? 
Thanks,
VQ
 A: The sum of $n$ identical and independently distributed random variables, each with mean $\mu$ and variance $\sigma^2$, will be distributed normally with mean $n\mu$ and variance $n\sigma^2$. (In fact its distribution only converges to normal, but in your case that's not a problem.)  
Using this property, the variable $X$ - sum of counts in 100 genes should be distributed as $N(100\mu, 100\sigma^2)$, $\mu=1.486$, $\sigma^2=1.7486$ (calculated from your provided distribution). Here's a basic simulation for proof:
df = data.frame(n=0:12, c=c(5994,7907,5418,2799,1230,431,151,40,17,7,3,2,1))
df$p = df$c/sum(df$c)

sum(df$p * df$n)
sum(df$p * (df$n - sum(df$p * df$n))^2)

s = c()
for(i in 1:10000){
    s = c(s, sum(sample(df$n, 100, prob=df$c, replace=T)))
}

mean(s)
var(s)

ggplot() + geom_density(aes(x=s)) +
    geom_line(aes(x=100:200, y=dnorm(100:200, 148.6, sqrt(174.86))), col="red")

In reality though, gene set enrichment tools usually resort to permutations (building your own null distribution), because various factors can violate the assumptions above. E.g., maybe longer genes have more motifs and also are more likely to be selected in whatever method you use to get your list of 100...
