Commit 337afeeb authored by nfontrod's avatar nfontrod
Browse files

src/visu/figure_maker.py: fix inspect_bigwig_regions to make it work with no environment

parent bb8ce1ba
......@@ -103,34 +103,47 @@ def inspect_bigwig_regions(bw: Any, region: List,
6 2.00 4 cond1 R1 exon2
7 1.00 5 cond1 R1 exon2
8 1.00 6 cond1 R1 exon2
>>> inspect_bigwig_regions(my_bw, mregion, 'R1', 5, [0, 0], 'cond1')
coverage bin condition replicate region
0 42.00 0 cond1 R1 exon2
1 8.00 1 cond1 R1 exon2
2 4.25 2 cond1 R1 exon2
3 2.00 3 cond1 R1 exon2
4 2.00 4 cond1 R1 exon2
"""
val = bw.stats(region[0], region[1], region[2], nBins=nb_bin, exact=True)
val = bw.stats(region[0],
max(region[1], 0),
min(region[2], bw.chroms(region[0])),
nBins=nb_bin,
exact=True)
bins = list(range(len(val)))
if len(bins) != nb_bin:
raise ValueError("The lenght of bins should be equals to nb_bin")
max_loc = max(region[1] - resize[0], 0)
min_loc = min(region[2] + resize[0], bw.chroms(region[0]))
if resize[0] > 0:
max_loc = max(region[1] - resize[0], 0)
val_before = bw.stats(region[0], max_loc, region[1], nBins=resize[1],
exact=True)
min_loc = min(region[2] + resize[0], bw.chroms(region[0]))
val_after = bw.stats(region[0], region[2], min_loc, nBins=resize[1],
exact=True)
if None in val_after:
val_after = val_after[::-1]
print(f"Warning ! None values found in {region} - "
f"{[region[0], region[2], min_loc]}")
if region[5] == "+":
bin_before = list(range(-len(val_before), 0))
bin_after = list(range(bins[-1] + 1,
bins[-1] + 1 + len(val_after)))
val = val_before + val + val_after
else:
bin_before = list(range(-len(val_after), 0))
bin_after = list(range(bins[-1] + 1,
bins[-1] + 1 + len(val_before)))
val = val_after[::-1] + val[::-1] + val_before[::-1]
bins = bin_before + bins + bin_after
else:
val_before = []
val_after = []
if None in val_after:
print(f"Warning ! None values found in {region} - "
f"{[region[0], region[2], min_loc]}")
if region[5] == "+":
bin_before = list(range(-len(val_before), 0))
bin_after = list(range(bins[-1] + 1,
bins[-1] + 1 + len(val_after)))
val = val_before + val + val_after
else:
bin_before = list(range(-len(val_after), 0))
bin_after = list(range(bins[-1] + 1,
bins[-1] + 1 + len(val_before)))
val = val_after[::-1] + val[::-1] + val_before[::-1]
bins = bin_before + bins + bin_after
dic = {"coverage": val, "bin": bins}
df = pd.DataFrame(dic)
df['condition'] = [condition_name] * df.shape[0]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment