Skip to content

Commit

Permalink
Merge pull request #25 from dpryan79/no_numpy_fixes
Browse files Browse the repository at this point in the history
Fix compilation when numpy isn't used.
  • Loading branch information
dpryan79 authored Nov 25, 2016
2 parents 1cddce7 + 084b4a9 commit b818db2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 29 deletions.
64 changes: 43 additions & 21 deletions pyBigWig.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,10 +749,14 @@ int isType1(PyObject *chroms, PyObject *starts, PyObject *values, PyObject *span
if(!isNumeric(span)) return rv;

if(PyList_Check(starts)) sz = PyList_Size(starts);
#ifdef WITHNUMPY
if(PyArray_Check(starts)) sz += PyArray_Size(starts);
#endif

if(PyList_Check(values)) if(sz != PyList_Size(values)) return rv;
#ifdef WITHNUMPY
if(PyArray_Check(values)) if(sz != PyArray_Size(values)) return rv;
#endif

if(PyList_Check(starts)) {
for(i=0; i<sz; i++) {
Expand Down Expand Up @@ -819,7 +823,9 @@ int canAppend(pyBigWigFile_t *self, int desiredType, PyObject *chroms, PyObject
Py_ssize_t i, sz = 0;
uint32_t tid, uspan, ustep, ustart;
PyObject *tmp;
#ifdef WITHNUMPY
void *foo;
#endif

if(self->lastType == -1) return 0;
if(self->lastTid == -1) return 0;
Expand All @@ -833,24 +839,28 @@ int canAppend(pyBigWigFile_t *self, int desiredType, PyObject *chroms, PyObject
if(PyArray_Check(chroms)) sz = PyArray_Size(chroms);
#endif
for(i=0; i<sz; i++) {
if(PyList_Check(chroms)) {
tmp = PyList_GetItem(chroms, i);
tid = bwGetTid(bw, PyString_AsString(tmp));
#ifdef WITHNUMPY
} else {
if(PyArray_Check(chroms)) {
foo = PyArray_GETPTR1((PyArrayObject*)chroms, i);
tid = bwGetTid(bw, PyString_AsString(PyArray_GETITEM((PyArrayObject*)chroms, foo)));
} else {
#endif
tmp = PyList_GetItem(chroms, i);
tid = bwGetTid(bw, PyString_AsString(tmp));
#ifdef WITHNUMPY
}
#endif
if(tid != (uint32_t) self->lastTid) return 0;
}
if(PyList_Check(starts)) {
ustart = Numeric2Uint(PyList_GetItem(starts, 0));
#ifdef WITHNUMPY
} else {
if(PyArray_Check(starts)) {
ustart = getNumpyU32((PyArrayObject*)starts, 0);
} else {
#endif
ustart = Numeric2Uint(PyList_GetItem(starts, 0));
#ifdef WITHNUMPY
}
#endif
if(PyErr_Occurred()) return 0;
if(ustart < self->lastStart) return 0;
return 1;
Expand All @@ -863,9 +873,11 @@ int canAppend(pyBigWigFile_t *self, int desiredType, PyObject *chroms, PyObject
tid = bwGetTid(bw, PyString_AsString(chroms));
if(tid != (uint32_t) self->lastTid) return 0;

if(PyList_Check(starts)) ustart = Numeric2Uint(PyList_GetItem(starts, 0));
#ifdef WITHNUMPY
if(PyList_Check(starts)) ustart = Numeric2Uint(PyList_GetItem(starts, 0));
else ustart = getNumpyU32((PyArrayObject*) starts, 0);
#else
ustart = Numeric2Uint(PyList_GetItem(starts, 0));
#endif
if(PyErr_Occurred()) return 0;
if(ustart < self->lastStart) return 0;
Expand Down Expand Up @@ -899,7 +911,9 @@ int PyAddIntervals(pyBigWigFile_t *self, PyObject *chroms, PyObject *starts, PyO
uint32_t n, *ustarts = NULL, *uends = NULL;
float *fvalues = NULL;
int rv;
#ifdef WITHNUMPY
void *foo;
#endif

if(PyList_Check(starts)) sz = PyList_Size(starts);
#ifdef WITHNUMPY
Expand Down Expand Up @@ -1259,34 +1273,40 @@ int addEntriesInputOK(pyBigWigFile_t *self, PyObject *chroms, PyObject *starts,
#endif
if(sz == 0) return 0;
for(i=0; i<sz; i++) {
if(PyList_Check(chroms)) {
tmp = PyList_GetItem(chroms, i);
cTid = bwGetTid(self->bw, PyString_AsString(tmp));
#ifdef WITHNUMPY
} else {
if(PyArray_Check(chroms)) {
tmpStr = getNumpyStr((PyArrayObject*)chroms, i);
cTid = bwGetTid(self->bw, tmpStr);
free(tmpStr);
} else {
#endif
tmp = PyList_GetItem(chroms, i);
cTid = bwGetTid(self->bw, PyString_AsString(tmp));
#ifdef WITHNUMPY
}
#endif
if(PyErr_Occurred()) return 0;
if(cTid == (uint32_t) -1) return 0;

if(PyList_Check(starts)) {
ustart = Numeric2Uint(PyList_GetItem(starts, i));
#ifdef WITHNUMPY
} else {
if(PyArray_Check(starts)) {
ustart = getNumpyU32((PyArrayObject*)starts, i);
} else {
#endif
ustart = Numeric2Uint(PyList_GetItem(starts, i));
#ifdef WITHNUMPY
}
#endif
if(PyErr_Occurred()) return 0;
if(PyList_Check(ends)) {
uend = Numeric2Uint(PyList_GetItem(ends, i));
#ifdef WITHNUMPY
} else {
if(PyArray_Check(ends)) {
uend = getNumpyU32((PyArrayObject*) ends, i);
} else {
#endif
uend = Numeric2Uint(PyList_GetItem(ends, i));
#ifdef WITHNUMPY
}
#endif
if(PyErr_Occurred()) return 0;

if(ustart >= uend) return 0;
Expand Down Expand Up @@ -1321,13 +1341,15 @@ int addEntriesInputOK(pyBigWigFile_t *self, PyObject *chroms, PyObject *starts,
if(lastTid > cTid) return 0;
}
for(i=0; i<sz; i++) {
if(PyList_Check(starts)) {
ustart = Numeric2Uint(PyList_GetItem(starts, i));
#ifdef WITHNUMPY
} else {
if(PyArray_Check(starts)) {
ustart = getNumpyU32((PyArrayObject*)starts, i);
} else {
#endif
ustart = Numeric2Uint(PyList_GetItem(starts, i));
#ifdef WITHNUMPY
}
#endif
if(PyErr_Occurred()) return 0;
uend = ustart + uspan;

Expand Down
8 changes: 3 additions & 5 deletions pyBigWigTest/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,10 @@ def testBigBed(self):

class TestNumpy():
def testNumpy(self):
try:
import numpy as np
except:
print("skipping numpy tests!")
return 0
import os
if pyBigWig.numpy == 0:
return 0
import numpy as np

bw = pyBigWig.open("/tmp/delete.bw", "w")
bw.addHeader([("1", 1000)], maxZooms=0)
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@
include_dirs = include_dirs)

setup(name = 'pyBigWig',
version = '0.3.1',
version = '0.3.2',
description = 'A package for accessing bigWig files using libBigWig',
author = "Devon P. Ryan",
author_email = "[email protected]",
url = "https://github.com/dpryan79/pyBigWig",
download_url = "https://github.com/dpryan79/pyBigWig/tarball/0.3.1",
keywords = ["bioinformatics", "bigWig"],
download_url = "https://github.com/dpryan79/pyBigWig/tarball/0.3.2",
keywords = ["bioinformatics", "bigWig", "bigBed"],
classifier = ["Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved",
Expand Down

0 comments on commit b818db2

Please sign in to comment.