dylanplummer commited on
Commit
eeab113
·
1 Parent(s): 9c3e15a

it works!

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -147,7 +147,7 @@ def draw_heatmap(matrix, color_scale, ax=None, min_val=1.001, return_image=False
147
  return img
148
 
149
 
150
- def get_heatmap(gene, locus1, locus2):
151
  locus1 = locus1.replace(',', '')
152
  locus2 = locus2.replace(',', '')
153
  try:
@@ -176,6 +176,10 @@ def get_heatmap(gene, locus1, locus2):
176
  chrom_size = beta_cooler.chromsizes[chrom]
177
  heatmap_locus = f'{chrom}:{max(0, chromStart - interaction_dist - heatmap_range)}-{min(chrom_size, chromEnd + interaction_dist + heatmap_range)}'
178
  print(heatmap_locus)
 
 
 
 
179
  mat = beta_cooler.matrix().fetch(heatmap_locus)
180
  #img = draw_heatmap(mat, 0, return_image=True)
181
  fig, ax = plt.subplots(figsize=(4, 4))
@@ -351,14 +355,16 @@ with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
351
  run_button.click(perturb, inputs, outputs=outputs)
352
  heatmap_button.click(get_heatmap, inputs, outputs=[out_heatmap])
353
  def set_loop(img, gene, locus1, locus2, evt: gr.SelectData):
354
- print(evt)
355
- print(evt.target)
356
- print(gene, locus1, locus2)
357
  idx = evt.index
358
- value = evt.value
359
- print(idx)
360
- print(value)
361
- return idx[0], idx[1]
 
 
 
 
362
  out_heatmap.select(set_loop, [out_heatmap, in_locus, anchor1, anchor2], outputs=[anchor1, anchor2])
363
 
364
 
 
147
  return img
148
 
149
 
150
+ def get_heatmap_locus(gene, locus1, locus2):
151
  locus1 = locus1.replace(',', '')
152
  locus2 = locus2.replace(',', '')
153
  try:
 
176
  chrom_size = beta_cooler.chromsizes[chrom]
177
  heatmap_locus = f'{chrom}:{max(0, chromStart - interaction_dist - heatmap_range)}-{min(chrom_size, chromEnd + interaction_dist + heatmap_range)}'
178
  print(heatmap_locus)
179
+
180
+
181
+ def get_heatmap(gene, locus1, locus2):
182
+ heatmap_locus = get_heatmap_locus(gene, locus1, locus2)
183
  mat = beta_cooler.matrix().fetch(heatmap_locus)
184
  #img = draw_heatmap(mat, 0, return_image=True)
185
  fig, ax = plt.subplots(figsize=(4, 4))
 
355
  run_button.click(perturb, inputs, outputs=outputs)
356
  heatmap_button.click(get_heatmap, inputs, outputs=[out_heatmap])
357
  def set_loop(img, gene, locus1, locus2, evt: gr.SelectData):
358
+ h, w = img.shape[:2]
 
 
359
  idx = evt.index
360
+ x, y = idx[0], idx[1]
361
+ heatmap_locus = get_heatmap_locus(gene, locus1, locus2)
362
+ bins = beta_cooler.bins().fetch(heatmap_locus)
363
+ bins_idx_x = int(x / w * len(bins))
364
+ bins_idx_y = int(y / h * len(bins))
365
+ new_a1 = f"{bins.loc[bins_idx_x, 'chrom']}:{bins.loc[bins_idx_x, 'start']}"
366
+ new_a2 = f"{bins.loc[bins_idx_y, 'chrom']}:{bins.loc[bins_idx_y, 'start']}"
367
+ return new_a1, new_a2
368
  out_heatmap.select(set_loop, [out_heatmap, in_locus, anchor1, anchor2], outputs=[anchor1, anchor2])
369
 
370