deeptools / pyBigWig

A python extension for quick access to bigWig and bigBed files
MIT License
212 stars 48 forks source link

error raised when start and end positions are identical. #110

Closed fardokhtsadat closed 3 years ago

fardokhtsadat commented 3 years ago

hello! I am trying to change the chromosome names in a gerp bigwig file. In the bigwig file, there are some entries where the start and end positions are the same. here is an example:

When I try to create a bigwig file, i get an error:

import pyBigWig 
import numpy as np 
bw = pyBigWig.open("delete.bw", "w") 
bw.addHeader([("chr1", 250000000)]) 
chroms = np.array(["chr1"] * 3) 
starts = np.array([2999997, 2999998, 2999999 ], dtype=np.int64) 
ends = np.array([2999998, 2999999, 2999999], dtype=np.int64) 
values0 = np.array(np.random.random_sample(3), dtype=np.float64) 
bw.addEntries(chroms, starts, ends=ends, values=values0) 
bw.close()

I get the following error: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py", line 3417, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-5-ee2f75383c55>", line 1, in <module> bw.addEntries(chroms, starts, ends=ends, values=values0) RuntimeError: The entries you tried to add are out of order, precede already added entries, or otherwise use illegal values. Please correct this and try again.

How can this be solved? Thanks!

dpryan79 commented 3 years ago

An entry where the start and end are the same can just be excluded since it doesn't actually yield information about a base (i.e., the width of the entry is 0 bases). You'll want to just filter those out (no clue how they got there to begin with).