From 12aa09d3ba029f73f0fbe28456af1504444e2bb1 Mon Sep 17 00:00:00 2001 From: Nezar Abdennur Date: Sat, 21 Sep 2019 12:45:06 -0400 Subject: [PATCH] Add numpy support for bw.stats() --- pyBigWig.c | 56 ++++++++++++++++++++++++++++++++------------ pyBigWigTest/test.py | 20 ++++++++++++++++ 2 files changed, 61 insertions(+), 15 deletions(-) diff --git a/pyBigWig.c b/pyBigWig.c index 5d63e08..6bf2adc 100644 --- a/pyBigWig.c +++ b/pyBigWig.c @@ -378,9 +378,10 @@ static PyObject *pyBwGetStats(pyBigWigFile_t *self, PyObject *args, PyObject *kw double *val; uint32_t start, end = -1, tid; unsigned long startl = 0, endl = -1; - static char *kwd_list[] = {"chrom", "start", "end", "type", "nBins", "exact", NULL}; + static char *kwd_list[] = {"chrom", "start", "end", "type", "nBins", "exact", "numpy", NULL}; char *chrom, *type = "mean"; PyObject *ret, *exact = Py_False, *starto = NULL, *endo = NULL; + PyObject *outputNumpy = Py_False; int i, nBins = 1; errno = 0; //In the off-chance that something elsewhere got an error and didn't clear it... @@ -399,7 +400,7 @@ static PyObject *pyBwGetStats(pyBigWigFile_t *self, PyObject *args, PyObject *kw return NULL; } - if(!PyArg_ParseTupleAndKeywords(args, kwds, "s|OOsiO", kwd_list, &chrom, &starto, &endo, &type, &nBins, &exact)) { + if(!PyArg_ParseTupleAndKeywords(args, kwds, "s|OOsiOO", kwd_list, &chrom, &starto, &endo, &type, &nBins, &exact, &outputNumpy)) { PyErr_SetString(PyExc_RuntimeError, "You must supply at least a chromosome!"); return NULL; } @@ -464,11 +465,26 @@ static PyObject *pyBwGetStats(pyBigWigFile_t *self, PyObject *args, PyObject *kw //Return a list of None if there are no entries at all if(!hasEntries(bw)) { - ret = PyList_New(nBins); - for(i=0; i