Spaces:
Runtime error
Runtime error
Commit ·
e115ec1
1
Parent(s): 50d65f4
global variables bad
Browse files
app.py
CHANGED
|
@@ -44,12 +44,12 @@ hic_file = unzip(hic_file)
|
|
| 44 |
cooler_celltypes = ['Alpha', 'Beta', 'Delta', 'PP', 'Acinar', 'Duct', 'PSC', 'Endothelial']
|
| 45 |
cooler_resolutions = ['50kb', '200kb', '500kb']
|
| 46 |
coolers = {}
|
| 47 |
-
for
|
| 48 |
-
coolers[
|
| 49 |
for celltype in cooler_celltypes:
|
| 50 |
-
for
|
| 51 |
cooler_file = hf_hub_download(repo_id="dylanplummer/islet-epigenome", filename=f"pseudobulk_coolers/{celltype}_50kb.cool", repo_type="dataset", token=os.environ['DATASET_SECRET'])
|
| 52 |
-
coolers[
|
| 53 |
beta_cooler = coolers[cooler_resolutions[0]][1]
|
| 54 |
|
| 55 |
model_file = hf_hub_download(repo_id="dylanplummer/HiGLUE-islet", filename=f"glue_hic_{prior_name}_prior_{resolution}_{suffix}.dill", repo_type="model", token=os.environ['DATASET_SECRET'])
|
|
@@ -185,18 +185,18 @@ def get_heatmap_locus(gene, locus1, locus2, heatmap_range):
|
|
| 185 |
locus_end = min(chrom_size, chromEnd + interaction_dist + heatmap_range * 1000)
|
| 186 |
heatmap_locus = f'{chrom}:{locus_start}-{locus_end}'
|
| 187 |
heatmap_size = abs(locus_start - locus_end)
|
| 188 |
-
|
| 189 |
if heatmap_size > 5000000:
|
| 190 |
-
|
| 191 |
if heatmap_size > 10000000:
|
| 192 |
-
|
| 193 |
-
print(heatmap_locus,
|
| 194 |
-
return heatmap_locus,
|
| 195 |
|
| 196 |
|
| 197 |
def get_heatmap(celltype, gene, locus1, locus2, heatmap_range):
|
| 198 |
-
heatmap_locus,
|
| 199 |
-
c = coolers[
|
| 200 |
mat = c.matrix().fetch(heatmap_locus)
|
| 201 |
#img = draw_heatmap(mat, 0, return_image=True)
|
| 202 |
fig, ax = plt.subplots(figsize=(4, 4))
|
|
@@ -385,8 +385,8 @@ with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
|
|
| 385 |
h, w = img.shape[:2]
|
| 386 |
idx = evt.index
|
| 387 |
x, y = idx[0], idx[1]
|
| 388 |
-
heatmap_locus,
|
| 389 |
-
bins = coolers[
|
| 390 |
bins_idx_x = int(x / w * len(bins))
|
| 391 |
bins_idx_y = int(y / h * len(bins))
|
| 392 |
new_a1 = f"{bins.iloc[bins_idx_x]['chrom']}:{bins.iloc[bins_idx_x]['start']}"
|
|
|
|
| 44 |
cooler_celltypes = ['Alpha', 'Beta', 'Delta', 'PP', 'Acinar', 'Duct', 'PSC', 'Endothelial']
|
| 45 |
cooler_resolutions = ['50kb', '200kb', '500kb']
|
| 46 |
coolers = {}
|
| 47 |
+
for res in cooler_resolutions:
|
| 48 |
+
coolers[res] = []
|
| 49 |
for celltype in cooler_celltypes:
|
| 50 |
+
for res in cooler_resolutions:
|
| 51 |
cooler_file = hf_hub_download(repo_id="dylanplummer/islet-epigenome", filename=f"pseudobulk_coolers/{celltype}_50kb.cool", repo_type="dataset", token=os.environ['DATASET_SECRET'])
|
| 52 |
+
coolers[res].append(cooler.Cooler(cooler_file))
|
| 53 |
beta_cooler = coolers[cooler_resolutions[0]][1]
|
| 54 |
|
| 55 |
model_file = hf_hub_download(repo_id="dylanplummer/HiGLUE-islet", filename=f"glue_hic_{prior_name}_prior_{resolution}_{suffix}.dill", repo_type="model", token=os.environ['DATASET_SECRET'])
|
|
|
|
| 185 |
locus_end = min(chrom_size, chromEnd + interaction_dist + heatmap_range * 1000)
|
| 186 |
heatmap_locus = f'{chrom}:{locus_start}-{locus_end}'
|
| 187 |
heatmap_size = abs(locus_start - locus_end)
|
| 188 |
+
res = '50kb'
|
| 189 |
if heatmap_size > 5000000:
|
| 190 |
+
res = '200kb'
|
| 191 |
if heatmap_size > 10000000:
|
| 192 |
+
res = '500kb'
|
| 193 |
+
print(heatmap_locus, res)
|
| 194 |
+
return heatmap_locus, res
|
| 195 |
|
| 196 |
|
| 197 |
def get_heatmap(celltype, gene, locus1, locus2, heatmap_range):
|
| 198 |
+
heatmap_locus, res = get_heatmap_locus(gene, locus1, locus2, heatmap_range)
|
| 199 |
+
c = coolers[res][cooler_celltypes.index(celltype)]
|
| 200 |
mat = c.matrix().fetch(heatmap_locus)
|
| 201 |
#img = draw_heatmap(mat, 0, return_image=True)
|
| 202 |
fig, ax = plt.subplots(figsize=(4, 4))
|
|
|
|
| 385 |
h, w = img.shape[:2]
|
| 386 |
idx = evt.index
|
| 387 |
x, y = idx[0], idx[1]
|
| 388 |
+
heatmap_locus, res = get_heatmap_locus(gene, locus1, locus2, heatmap_range)
|
| 389 |
+
bins = coolers[res][0].bins().fetch(heatmap_locus)
|
| 390 |
bins_idx_x = int(x / w * len(bins))
|
| 391 |
bins_idx_y = int(y / h * len(bins))
|
| 392 |
new_a1 = f"{bins.iloc[bins_idx_x]['chrom']}:{bins.iloc[bins_idx_x]['start']}"
|