Spaces:
Runtime error
Runtime error
Commit ·
095bd07
1
Parent(s): e11f23a
fix loo out of bounds from gene
Browse files
app.py
CHANGED
|
@@ -103,7 +103,6 @@ def get_closest_peak_to_gene(gene_name, rna, peaks):
|
|
| 103 |
return None
|
| 104 |
chrom = loc["chrom"]
|
| 105 |
chromStart = loc["chromStart"]
|
| 106 |
-
chromEnd = loc["chromEnd"]
|
| 107 |
peaks['in_chr'] = peaks['chrom'] == chrom
|
| 108 |
peaks['dist'] = peaks['chromStart'].apply(lambda s: abs(s - chromStart))
|
| 109 |
peaks.loc[~peaks['in_chr'], 'dist'] = 1e9 # set distance to 1e9 if not in same chromosome
|
|
@@ -177,8 +176,6 @@ def get_heatmap_locus(gene, locus1, locus2, heatmap_range):
|
|
| 177 |
print('Could not find loci', gene)
|
| 178 |
return None
|
| 179 |
chrom = loc["chrom"]
|
| 180 |
-
chromStart = loc["chromStart"]
|
| 181 |
-
chromEnd = loc["chromEnd"]
|
| 182 |
if locus1.startswith('chr'):
|
| 183 |
chrom = locus1.split(':')[0]
|
| 184 |
pos1 = locus1.split(':')[1]
|
|
@@ -195,8 +192,8 @@ def get_heatmap_locus(gene, locus1, locus2, heatmap_range):
|
|
| 195 |
a2_start = peaks.loc[a2, 'chromStart']
|
| 196 |
interaction_dist = abs(a1_start - a2_start)
|
| 197 |
chrom_size = beta_cooler.chromsizes[chrom]
|
| 198 |
-
locus_start = max(0,
|
| 199 |
-
locus_end = min(chrom_size,
|
| 200 |
heatmap_locus = f'{chrom}:{locus_start}-{locus_end}'
|
| 201 |
heatmap_size = abs(locus_start - locus_end)
|
| 202 |
res = '50kb'
|
|
@@ -382,7 +379,7 @@ def perturb(gene, locus1, locus2, use_max_gene):
|
|
| 382 |
|
| 383 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 384 |
sc.pl.violin(rna, gene, groupby='celltype', layer='counts', show=False, ax=ax, rotation=90)
|
| 385 |
-
ax.set_title(f'Normal {gene} expression')
|
| 386 |
fig.tight_layout()
|
| 387 |
fig.canvas.draw()
|
| 388 |
violin_img = np.frombuffer(fig.canvas.tostring_argb(), dtype=np.uint8)
|
|
@@ -391,7 +388,7 @@ def perturb(gene, locus1, locus2, use_max_gene):
|
|
| 391 |
|
| 392 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 393 |
sc.pl.violin(rna, 'new_mean', groupby='celltype', show=False, ax=ax, rotation=90)
|
| 394 |
-
ax.set_title(f'{gene} expression after perturbation')
|
| 395 |
fig.tight_layout()
|
| 396 |
fig.canvas.draw()
|
| 397 |
violin_img_new = np.frombuffer(fig.canvas.tostring_argb(), dtype=np.uint8)
|
|
@@ -400,7 +397,7 @@ def perturb(gene, locus1, locus2, use_max_gene):
|
|
| 400 |
|
| 401 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 402 |
sc.pl.violin(rna, 'log2FC', groupby='celltype', show=False, ax=ax, rotation=90)
|
| 403 |
-
ax.set_title(f'{gene} expression change')
|
| 404 |
ax.hlines(0, -1, len(celltypes), linestyles='dashed')
|
| 405 |
fig.tight_layout()
|
| 406 |
fig.canvas.draw()
|
|
|
|
| 103 |
return None
|
| 104 |
chrom = loc["chrom"]
|
| 105 |
chromStart = loc["chromStart"]
|
|
|
|
| 106 |
peaks['in_chr'] = peaks['chrom'] == chrom
|
| 107 |
peaks['dist'] = peaks['chromStart'].apply(lambda s: abs(s - chromStart))
|
| 108 |
peaks.loc[~peaks['in_chr'], 'dist'] = 1e9 # set distance to 1e9 if not in same chromosome
|
|
|
|
| 176 |
print('Could not find loci', gene)
|
| 177 |
return None
|
| 178 |
chrom = loc["chrom"]
|
|
|
|
|
|
|
| 179 |
if locus1.startswith('chr'):
|
| 180 |
chrom = locus1.split(':')[0]
|
| 181 |
pos1 = locus1.split(':')[1]
|
|
|
|
| 192 |
a2_start = peaks.loc[a2, 'chromStart']
|
| 193 |
interaction_dist = abs(a1_start - a2_start)
|
| 194 |
chrom_size = beta_cooler.chromsizes[chrom]
|
| 195 |
+
locus_start = max(0, a1_start - interaction_dist - heatmap_range * 1000)
|
| 196 |
+
locus_end = min(chrom_size, a2_start + interaction_dist + heatmap_range * 1000)
|
| 197 |
heatmap_locus = f'{chrom}:{locus_start}-{locus_end}'
|
| 198 |
heatmap_size = abs(locus_start - locus_end)
|
| 199 |
res = '50kb'
|
|
|
|
| 379 |
|
| 380 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 381 |
sc.pl.violin(rna, gene, groupby='celltype', layer='counts', show=False, ax=ax, rotation=90)
|
| 382 |
+
ax.set_title(f'Normal {max_gene if use_max_gene else gene} expression')
|
| 383 |
fig.tight_layout()
|
| 384 |
fig.canvas.draw()
|
| 385 |
violin_img = np.frombuffer(fig.canvas.tostring_argb(), dtype=np.uint8)
|
|
|
|
| 388 |
|
| 389 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 390 |
sc.pl.violin(rna, 'new_mean', groupby='celltype', show=False, ax=ax, rotation=90)
|
| 391 |
+
ax.set_title(f'{max_gene if use_max_gene else gene} expression after perturbation')
|
| 392 |
fig.tight_layout()
|
| 393 |
fig.canvas.draw()
|
| 394 |
violin_img_new = np.frombuffer(fig.canvas.tostring_argb(), dtype=np.uint8)
|
|
|
|
| 397 |
|
| 398 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 399 |
sc.pl.violin(rna, 'log2FC', groupby='celltype', show=False, ax=ax, rotation=90)
|
| 400 |
+
ax.set_title(f'{max_gene if use_max_gene else gene} expression change')
|
| 401 |
ax.hlines(0, -1, len(celltypes), linestyles='dashed')
|
| 402 |
fig.tight_layout()
|
| 403 |
fig.canvas.draw()
|