Skip to content

Commit 414ce53

Browse files
authored
Merge pull request #92 from deeptools/fix91
PyUnicode_AsASCIIString returns a new object that needs to be DECREF'd
2 parents f0c6e16 + 9f94cf9 commit 414ce53

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@ For the sake of consistency with other tools, pyBigWig adopts this same methodol
144144
0.22213841940688142
145145
>>> bw.stats('chr1', 89294, 91629, exact=True)
146146
[0.22213841940688142]
147-
Additionally, `values()` can directly output a numpy vector:
148-
149-
>>> bw = bw.open("
150147

151148
## Retrieve values for individual bases in a range
152149

@@ -218,6 +215,8 @@ By default, up to 10 "zoom levels" are constructed for bigWig files. You can cha
218215

219216
>>> bw.addHeader([("chr1", 1000000), ("chr2", 1500000)], maxZooms=0)
220217

218+
If you set `maxTooms=0`, please note that IGV and many other tools WILL NOT WORK as they assume that at least one zoom level will be present. You are advised to use the default unless you do not expect the bigWig files to be used by other packages.
219+
221220
## Adding entries to a bigWig file
222221

223222
Assuming you've opened a file for writing and added a header, you can then add entries. Note that the entries **must** be added in order, as bigWig files always contain ordered intervals. There are three formats that bigWig files can use internally to store entries. The most commonly observed format is identical to a [bedGraph](https://genome.ucsc.edu/goldenpath/help/bedgraph.html) file:

pyBigWig.c

+20-1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ static PyObject *pyBwGetHeader(pyBigWigFile_t *self, PyObject *args) {
276276
PyErr_SetString(PyExc_RuntimeError, "The bigWig file handle is not opened!");
277277
return NULL;
278278
}
279+
if(bw->isWrite == 1) {
280+
PyErr_SetString(PyExc_RuntimeError, "The header cannot be accessed in files opened for writing!");
281+
return NULL;
282+
}
279283

280284
ret = PyDict_New();
281285
val = PyLong_FromUnsignedLong(bw->hdr->version);
@@ -321,6 +325,11 @@ static PyObject *pyBwGetChroms(pyBigWigFile_t *self, PyObject *args) {
321325
return NULL;
322326
}
323327

328+
if(bw->isWrite == 1) {
329+
PyErr_SetString(PyExc_RuntimeError, "Chromosomes cannot be accessed in files opened for writing!");
330+
return NULL;
331+
}
332+
324333
if(!(PyArg_ParseTuple(args, "|s", &chrom)) || !chrom) {
325334
ret = PyDict_New();
326335
for(i=0; i<bw->cl->nKeys; i++) {
@@ -380,6 +389,11 @@ static PyObject *pyBwGetStats(pyBigWigFile_t *self, PyObject *args, PyObject *kw
380389
return NULL;
381390
}
382391

392+
if(bw->isWrite == 1) {
393+
PyErr_SetString(PyExc_RuntimeError, "Statistics cannot be accessed in files opened for writing!");
394+
return NULL;
395+
}
396+
383397
if(bw->type == 1) {
384398
PyErr_SetString(PyExc_RuntimeError, "bigBed files have no statistics!");
385399
return NULL;
@@ -621,6 +635,11 @@ static PyObject *pyBwGetIntervals(pyBigWigFile_t *self, PyObject *args, PyObject
621635
return NULL;
622636
}
623637

638+
if(bw->isWrite == 1) {
639+
PyErr_SetString(PyExc_RuntimeError, "Intervals cannot be accessed in files opened for writing!");
640+
return NULL;
641+
}
642+
624643
if(bw->type == 1) {
625644
PyErr_SetString(PyExc_RuntimeError, "bigBed files have no intervals! Use 'entries()' instead.");
626645
return NULL;
@@ -724,7 +743,7 @@ int PyString_Check(PyObject *obj) {
724743

725744
//I don't know what happens if PyBytes_AsString(NULL) is used...
726745
char *PyString_AsString(PyObject *obj) {
727-
return PyBytes_AsString(PyUnicode_AsASCIIString(obj));
746+
return PyUnicode_AsUTF8(obj);
728747
}
729748
#endif
730749

pyBigWig.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <structmember.h>
33
#include "bigWig.h"
44

5-
#define pyBigWigVersion "0.3.16"
5+
#define pyBigWigVersion "0.3.17"
66

77
typedef struct {
88
PyObject_HEAD

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
include_dirs = include_dirs)
6363

6464
setup(name = 'pyBigWig',
65-
version = '0.3.16',
65+
version = '0.3.17',
6666
description = 'A package for accessing bigWig files using libBigWig',
6767
author = "Devon P. Ryan",
6868
author_email = "[email protected]",

0 commit comments

Comments
 (0)