dylanplummer commited on
Commit
3b8d556
·
1 Parent(s): 9beb97d

add closest gene perturb

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py CHANGED
@@ -110,6 +110,20 @@ def get_closest_peak_to_gene(gene_name, rna, peaks):
110
  return peaks['dist'].idxmin()
111
 
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  def get_chromosome_from_filename(filename):
114
  chr_index = filename.find('chr') # index of chromosome name
115
  if chr_index == 0: # if chromosome name is file prefix
@@ -288,6 +302,10 @@ def perturb(gene, locus1, locus2, use_max_gene):
288
 
289
  print(a1)
290
  print(a2)
 
 
 
 
291
 
292
  guidance_hvf = prior.copy()
293
  try:
@@ -319,6 +337,16 @@ def perturb(gene, locus1, locus2, use_max_gene):
319
  guidance_hvf.remove_edge(a2, a1)
320
  except:
321
  pass
 
 
 
 
 
 
 
 
 
 
322
 
323
  perterbed_rna_recon = glue.decode_data("rna", "rna", rna, guidance_hvf)
324
  ism = np.log2((perterbed_rna_recon + eps) / (rna_recon + eps))
 
110
  return peaks['dist'].idxmin()
111
 
112
 
113
+ def get_closest_gene_to_peak(peak_name, rna, peaks):
114
+ try:
115
+ loc = peaks.loc[peak_name]
116
+ except KeyError:
117
+ print('Could not find peak', peak_name)
118
+ return None
119
+ chrom = loc["chrom"]
120
+ chromStart = loc["chromStart"]
121
+ rna.var['in_chr'] = rna['chrom'] == chrom
122
+ rna.var['dist'] = rna['chromStart'].apply(lambda s: abs(s - chromStart))
123
+ rna.var.loc[~rna.var['in_chr'], 'dist'] = 1e9 # set distance to 1e9 if not in same chromosome
124
+ return rna.var['dist'].idxmin()
125
+
126
+
127
  def get_chromosome_from_filename(filename):
128
  chr_index = filename.find('chr') # index of chromosome name
129
  if chr_index == 0: # if chromosome name is file prefix
 
302
 
303
  print(a1)
304
  print(a2)
305
+
306
+ a1_closest_gene = get_closest_gene_to_peak(a1, rna, peaks)
307
+ a2_closest_gene = get_closest_gene_to_peak(a2, rna, peaks)
308
+ print(a1_closest_gene, a2_closest_gene)
309
 
310
  guidance_hvf = prior.copy()
311
  try:
 
337
  guidance_hvf.remove_edge(a2, a1)
338
  except:
339
  pass
340
+ try:
341
+ guidance_hvf.remove_edge(a1, a1_closest_gene)
342
+ guidance_hvf.remove_edge(a1_closest_gene, a1)
343
+ except:
344
+ pass
345
+ try:
346
+ guidance_hvf.remove_edge(a2, a2_closest_gene)
347
+ guidance_hvf.remove_edge(a2_closest_gene, a2)
348
+ except:
349
+ pass
350
 
351
  perterbed_rna_recon = glue.decode_data("rna", "rna", rna, guidance_hvf)
352
  ism = np.log2((perterbed_rna_recon + eps) / (rna_recon + eps))