Spaces:
Runtime error
Runtime error
Commit ·
cdebb72
1
Parent(s): ef7f813
try new count after perturb
Browse files
app.py
CHANGED
|
@@ -197,11 +197,11 @@ def get_heatmap_locus(gene, locus1, locus2, heatmap_range):
|
|
| 197 |
heatmap_locus = f'{chrom}:{locus_start}-{locus_end}'
|
| 198 |
heatmap_size = abs(locus_start - locus_end)
|
| 199 |
res = 'deeploop'
|
| 200 |
-
if heatmap_size >
|
| 201 |
res = '50kb'
|
| 202 |
-
if heatmap_size >
|
| 203 |
res = '200kb'
|
| 204 |
-
if heatmap_size >
|
| 205 |
res = '500kb'
|
| 206 |
print(heatmap_locus, res)
|
| 207 |
return heatmap_locus, res
|
|
@@ -241,7 +241,10 @@ def get_heatmap(celltype, gene, locus1, locus2, heatmap_range):
|
|
| 241 |
print(a1_idx, a2_idx)
|
| 242 |
#img = draw_heatmap(mat, 0, return_image=True)
|
| 243 |
fig, ax = plt.subplots(figsize=(4, 4))
|
| 244 |
-
|
|
|
|
|
|
|
|
|
|
| 245 |
|
| 246 |
# remove white padding
|
| 247 |
plt.subplots_adjust(left=0, right=1, top=1, bottom=0)
|
|
@@ -254,7 +257,7 @@ def get_heatmap(celltype, gene, locus1, locus2, heatmap_range):
|
|
| 254 |
#print(heatmap_x, heatmap_y)
|
| 255 |
heatmap_x = a1_idx
|
| 256 |
heatmap_y = a2_idx
|
| 257 |
-
ax.scatter(int(heatmap_x), int(heatmap_y), color='green', marker='*', s=
|
| 258 |
|
| 259 |
# redraw the canvas
|
| 260 |
fig = plt.gcf()
|
|
@@ -360,6 +363,8 @@ def perturb(gene, locus1, locus2, use_max_gene):
|
|
| 360 |
rna.obs['log2FC'] = ism[:, gene_idx]
|
| 361 |
rna.obs['old_mean'] = rna_recon[:, gene_idx]
|
| 362 |
rna.obs['new_mean'] = perterbed_rna_recon[:, gene_idx]
|
|
|
|
|
|
|
| 363 |
|
| 364 |
fig = sc.pl.umap(rna,
|
| 365 |
color=['celltype', 'log2FC'],
|
|
@@ -381,8 +386,8 @@ def perturb(gene, locus1, locus2, use_max_gene):
|
|
| 381 |
image_from_plot = image_from_plot[:, :, [1, 2, 3, 0]]
|
| 382 |
|
| 383 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 384 |
-
|
| 385 |
-
sc.pl.violin(rna, 'old_mean', groupby='celltype', show=False, ax=ax, rotation=90)
|
| 386 |
ax.set_title(f'Normal {max_gene if use_max_gene else gene} expression')
|
| 387 |
fig.tight_layout()
|
| 388 |
fig.canvas.draw()
|
|
@@ -391,7 +396,7 @@ def perturb(gene, locus1, locus2, use_max_gene):
|
|
| 391 |
violin_img = violin_img[:, :, [1, 2, 3, 0]]
|
| 392 |
|
| 393 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 394 |
-
sc.pl.violin(rna, '
|
| 395 |
ax.set_title(f'{max_gene if use_max_gene else gene} expression after perturbation')
|
| 396 |
fig.tight_layout()
|
| 397 |
fig.canvas.draw()
|
|
@@ -447,6 +452,7 @@ with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
|
|
| 447 |
['TSPAN1', 'TSPAN1', 'PIK3R3', False],
|
| 448 |
['IRX1', 'chr5:5397612', 'chr5:4850008', False],
|
| 449 |
['GCG', 'GCG', 'FAP', False],
|
|
|
|
| 450 |
['LOXL4', 'chr10:100186215', 'chr10:99913493', False],
|
| 451 |
['KRT19', 'chr17:22,220,637', 'chr17:39,591,813', False],
|
| 452 |
['LPP', 'chr3:188,097,749', 'chr3:197,916,262', False],
|
|
|
|
| 197 |
heatmap_locus = f'{chrom}:{locus_start}-{locus_end}'
|
| 198 |
heatmap_size = abs(locus_start - locus_end)
|
| 199 |
res = 'deeploop'
|
| 200 |
+
if heatmap_size > 5000000:
|
| 201 |
res = '50kb'
|
| 202 |
+
if heatmap_size > 10000000:
|
| 203 |
res = '200kb'
|
| 204 |
+
if heatmap_size > 20000000:
|
| 205 |
res = '500kb'
|
| 206 |
print(heatmap_locus, res)
|
| 207 |
return heatmap_locus, res
|
|
|
|
| 241 |
print(a1_idx, a2_idx)
|
| 242 |
#img = draw_heatmap(mat, 0, return_image=True)
|
| 243 |
fig, ax = plt.subplots(figsize=(4, 4))
|
| 244 |
+
if res == 'deeploop':
|
| 245 |
+
draw_heatmap(mat, 0, ax=ax)
|
| 246 |
+
else:
|
| 247 |
+
ax.imshow(mat, cmap='Reds', norm=PowerNorm(gamma=0.3), interpolation=None)
|
| 248 |
|
| 249 |
# remove white padding
|
| 250 |
plt.subplots_adjust(left=0, right=1, top=1, bottom=0)
|
|
|
|
| 257 |
#print(heatmap_x, heatmap_y)
|
| 258 |
heatmap_x = a1_idx
|
| 259 |
heatmap_y = a2_idx
|
| 260 |
+
ax.scatter(int(heatmap_x), int(heatmap_y), color='green', marker='*', s=150)
|
| 261 |
|
| 262 |
# redraw the canvas
|
| 263 |
fig = plt.gcf()
|
|
|
|
| 363 |
rna.obs['log2FC'] = ism[:, gene_idx]
|
| 364 |
rna.obs['old_mean'] = rna_recon[:, gene_idx]
|
| 365 |
rna.obs['new_mean'] = perterbed_rna_recon[:, gene_idx]
|
| 366 |
+
# compute new count based on log2FC
|
| 367 |
+
rna.obs['new_count'] = rna.layers['counts'][:, gene_idx] * np.exp(rna.obs['log2FC'])
|
| 368 |
|
| 369 |
fig = sc.pl.umap(rna,
|
| 370 |
color=['celltype', 'log2FC'],
|
|
|
|
| 386 |
image_from_plot = image_from_plot[:, :, [1, 2, 3, 0]]
|
| 387 |
|
| 388 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 389 |
+
sc.pl.violin(rna, max_gene if use_max_gene else gene, groupby='celltype', layer='counts', show=False, ax=ax, rotation=90)
|
| 390 |
+
#sc.pl.violin(rna, 'old_mean', groupby='celltype', show=False, ax=ax, rotation=90)
|
| 391 |
ax.set_title(f'Normal {max_gene if use_max_gene else gene} expression')
|
| 392 |
fig.tight_layout()
|
| 393 |
fig.canvas.draw()
|
|
|
|
| 396 |
violin_img = violin_img[:, :, [1, 2, 3, 0]]
|
| 397 |
|
| 398 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 399 |
+
sc.pl.violin(rna, 'new_count', groupby='celltype', show=False, ax=ax, rotation=90)
|
| 400 |
ax.set_title(f'{max_gene if use_max_gene else gene} expression after perturbation')
|
| 401 |
fig.tight_layout()
|
| 402 |
fig.canvas.draw()
|
|
|
|
| 452 |
['TSPAN1', 'TSPAN1', 'PIK3R3', False],
|
| 453 |
['IRX1', 'chr5:5397612', 'chr5:4850008', False],
|
| 454 |
['GCG', 'GCG', 'FAP', False],
|
| 455 |
+
['GCG', 'chr2:163162903', 'chr2:162852164', True]
|
| 456 |
['LOXL4', 'chr10:100186215', 'chr10:99913493', False],
|
| 457 |
['KRT19', 'chr17:22,220,637', 'chr17:39,591,813', False],
|
| 458 |
['LPP', 'chr3:188,097,749', 'chr3:197,916,262', False],
|