Added MACS source
[htsworkflow.git] / htswanalysis / MACS / lib / gsl / cdf.c
1 /*
2  * Copyright (C) 2008 Tao Liu.
3  *
4  * This code is free software; you can redistribute it and/or modify
5  * it under the terms of the Artistic License (see the file COPYING
6  * included with the distribution).
7  *
8  *
9  */
10
11 #include <Python.h>
12
13 #include <string.h>
14 /* include GSL cdf function for poisson */
15 #include  "gsl_cdf.h"
16
17 static PyObject *
18 poisson_cdf_Q ( PyObject * self, PyObject * args)
19 {
20   double lambda;
21   int k;
22   double pvalue;
23
24   if (! PyArg_ParseTuple(args, "di", &lambda,&k))
25     return NULL;
26   pvalue = gsl_cdf_poisson_Q (k,lambda);
27   return Py_BuildValue("d",pvalue);
28 }
29
30
31 static PyObject *
32 binom_cdf_Q ( PyObject * self, PyObject * args)
33 {
34   double p;
35   int n;
36   int k;
37   double pvalue;
38
39   if (! PyArg_ParseTuple(args, "dii", &p,&n,&k))
40     return NULL;
41   pvalue = gsl_cdf_binomial_Q(k,p,n);
42   return Py_BuildValue("d",pvalue);
43 }
44
45 static PyMethodDef pcdfMethods[] = 
46   {
47         {"poisson_cdf_Q",poisson_cdf_Q,METH_VARARGS,"Calculate CDF for a poisson distribution ( for upper tail). Usage: poisson_cdf_Q(lambda,k); Return: P-value"},
48         {"binom_cdf_Q",binom_cdf_Q,METH_VARARGS,"Calculate CDF for a binomial distribution ( for upper tail). Usage: binom_cdf_Q(p,n,k); Return: P-value"},
49         {NULL,NULL}
50   };
51   
52 void initcdf()
53 {
54   PyObject * m;
55   m = Py_InitModule("cdf",pcdfMethods);
56 }