dylanplummer commited on
Commit
0676acf
·
1 Parent(s): 68f2aa3

zero out tf counts

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -278,12 +278,17 @@ def get_heatmaps(gene, locus1, locus2, heatmap_range):
278
 
279
 
280
  def perturb(gene, locus1, locus2, use_max_gene, tf_knockout):
 
281
  if tf_knockout:
282
  guidance_hvf = prior.copy()
283
  try:
284
  guidance_hvf.remove_node(gene)
285
  except:
286
  pass
 
 
 
 
287
  else:
288
  locus1 = locus1.replace(',', '')
289
  locus2 = locus2.replace(',', '')
@@ -356,16 +361,18 @@ def perturb(gene, locus1, locus2, use_max_gene, tf_knockout):
356
  guidance_hvf.remove_edge(a2_closest_gene, a2)
357
  except:
358
  pass
359
-
360
- perterbed_rna_recon = glue.decode_data("rna", "rna", rna, guidance_hvf)
361
  ism = np.log2((perterbed_rna_recon + eps) / (rna_recon + eps))
362
- max_gene_idxs = np.abs(np.mean(ism, axis=0)).argsort()[::-1][:10]
363
- max_gene_idx = np.abs(np.mean(ism, axis=0)).argmax()
 
 
 
364
  max_gene = rna.var.query(f"highly_variable").index[max_gene_idx]
365
  print('Max gene:', max_gene)
366
  for max_gene_idx in max_gene_idxs:
367
- max_gene = rna.var.query(f"highly_variable").index[max_gene_idx]
368
- print(max_gene, np.mean(ism[:, max_gene_idx]))
369
  # get integer index of gene
370
  if use_max_gene:
371
  gene_idx = gene_idx_map[max_gene]
 
278
 
279
 
280
  def perturb(gene, locus1, locus2, use_max_gene, tf_knockout):
281
+ in_rna = rna.copy()
282
  if tf_knockout:
283
  guidance_hvf = prior.copy()
284
  try:
285
  guidance_hvf.remove_node(gene)
286
  except:
287
  pass
288
+ # find index of tf and set all counts and values to zero
289
+ gene_idx = gene_idx_map[gene]
290
+ in_rna.layers['counts'][:, gene_idx] = 0
291
+ in_rna.X[:, gene_idx] = 0
292
  else:
293
  locus1 = locus1.replace(',', '')
294
  locus2 = locus2.replace(',', '')
 
361
  guidance_hvf.remove_edge(a2_closest_gene, a2)
362
  except:
363
  pass
364
+
365
+ perterbed_rna_recon = glue.decode_data("rna", "rna", in_rna, guidance_hvf)
366
  ism = np.log2((perterbed_rna_recon + eps) / (rna_recon + eps))
367
+ if tf_knockout:
368
+ max_gene_idxs = np.abs(np.mean(ism, axis=0)).argsort()[::-1][:10]
369
+ max_gene_idx = max_gene_idxs[1]
370
+ else:
371
+ max_gene_idx = np.abs(np.mean(ism, axis=0)).argmax()
372
  max_gene = rna.var.query(f"highly_variable").index[max_gene_idx]
373
  print('Max gene:', max_gene)
374
  for max_gene_idx in max_gene_idxs:
375
+ print(rna.var.query(f"highly_variable").index[max_gene_idx], np.mean(ism[:, max_gene_idx]))
 
376
  # get integer index of gene
377
  if use_max_gene:
378
  gene_idx = gene_idx_map[max_gene]