dylanplummer commited on
Commit
29e01b6
·
1 Parent(s): 36ab5ef

add muultires

Browse files
Files changed (1) hide show
  1. app.py +22 -10
app.py CHANGED
@@ -42,10 +42,14 @@ rna_file = unzip(rna_file)
42
  hic_file = unzip(hic_file)
43
 
44
  cooler_celltypes = ['Alpha', 'Beta', 'Delta', 'PP', 'Acinar', 'Duct', 'PSC', 'Endothelial']
45
- coolers = []
 
 
 
46
  for celltype in cooler_celltypes:
47
- 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'])
48
- coolers.append(cooler.Cooler(cooler_file))
 
49
  beta_cooler = coolers[1]
50
 
51
  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'])
@@ -177,14 +181,22 @@ def get_heatmap_locus(gene, locus1, locus2, heatmap_range):
177
  a2_start = peaks.loc[a2, 'chromStart']
178
  interaction_dist = abs(a1_start - a2_start)
179
  chrom_size = beta_cooler.chromsizes[chrom]
180
- heatmap_locus = f'{chrom}:{max(0, chromStart - interaction_dist - heatmap_range * 1000)}-{min(chrom_size, chromEnd + interaction_dist + heatmap_range * 1000)}'
181
- print(heatmap_locus)
182
- return heatmap_locus
 
 
 
 
 
 
 
 
183
 
184
 
185
  def get_heatmap(celltype, gene, locus1, locus2, heatmap_range):
186
- heatmap_locus = get_heatmap_locus(gene, locus1, locus2, heatmap_range)
187
- c = coolers[cooler_celltypes.index(celltype)]
188
  mat = c.matrix().fetch(heatmap_locus)
189
  #img = draw_heatmap(mat, 0, return_image=True)
190
  fig, ax = plt.subplots(figsize=(4, 4))
@@ -373,8 +385,8 @@ with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
373
  h, w = img.shape[:2]
374
  idx = evt.index
375
  x, y = idx[0], idx[1]
376
- heatmap_locus = get_heatmap_locus(gene, locus1, locus2, heatmap_range)
377
- bins = beta_cooler.bins().fetch(heatmap_locus)
378
  bins_idx_x = int(x / w * len(bins))
379
  bins_idx_y = int(y / h * len(bins))
380
  new_a1 = f"{bins.iloc[bins_idx_x]['chrom']}:{bins.iloc[bins_idx_x]['start']}"
 
42
  hic_file = unzip(hic_file)
43
 
44
  cooler_celltypes = ['Alpha', 'Beta', 'Delta', 'PP', 'Acinar', 'Duct', 'PSC', 'Endothelial']
45
+ cooler_resolutions = ['50kb', '200kb', '500kb']
46
+ coolers = {}
47
+ for resolution in cooler_resolutions:
48
+ coolers[resolution] = []
49
  for celltype in cooler_celltypes:
50
+ for resolution 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[resolution].append(cooler.Cooler(cooler_file))
53
  beta_cooler = coolers[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'])
 
181
  a2_start = peaks.loc[a2, 'chromStart']
182
  interaction_dist = abs(a1_start - a2_start)
183
  chrom_size = beta_cooler.chromsizes[chrom]
184
+ locus_start = max(0, chromStart - interaction_dist - heatmap_range * 1000)
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
+ resolution = '50kb'
189
+ if heatmap_size > 5000000:
190
+ resolution = '200kb'
191
+ if heatmap_size > 10000000:
192
+ resolution = '500kb'
193
+ print(heatmap_locus, resolution)
194
+ return heatmap_locus, resolution
195
 
196
 
197
  def get_heatmap(celltype, gene, locus1, locus2, heatmap_range):
198
+ heatmap_locus, resolution = get_heatmap_locus(gene, locus1, locus2, heatmap_range)
199
+ c = coolers[resolution][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, resolution = get_heatmap_locus(gene, locus1, locus2, heatmap_range)
389
+ bins = coolers[resolution][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']}"