Query regarding the behavior of bbi.fetch in situations where window_size < bin_size
smitkadvani opened this issue · 1 comments
Dear Team,
I am currently working with a section of code as detailed below:
python code
path_bigwig_file = chip_folder + ring1b
with bbi.open(path_bigwig_file) as f:
x = f.fetch('chr1', 4500015, 4500016, bins=40)
During the execution of this code, it appears that when the 'window_size' is smaller than the 'bin_size' (in this case, the bin_size is 40), the function repetitively returns the same value corresponding to the 'bin_size' instead of throwing an error or providing an alternative output.
My question is, is this the expected behavior of the system in such scenarios? Or should the system ideally return an error message in such instances to alert the user of the possible inconsistency?
I would greatly appreciate your insights into this matter, and any guidance you could provide would be of immense value.
Best regards,
Smit
I think the behavior, while relaxed, is reasonable given the request. You are asking to divide the range [4500015, 4500016)
into 40 evenly-spaced bins, so it interpolates appropriately. The UCSC code was designed for plotting in the genome browser, after all. For plotting with matplotlib this would look like:
chrom, start, end = "chr1", 4500015, 4500016
n_bins = 40
x = np.linspace(start, end, n_bins + 1)
y = f.fetch(chrom, start, end, bins=n_bins)
plt.stairs(values=y, edges=x)
Note that bins=
does not indicate the size of the bins, but the number of bins to divide the interval into. In your example, the bin size ends up being 0.025bp.