dylanplummer commited on
Commit
76e85b0
·
1 Parent(s): 7ea80fb

add violin

Browse files
Files changed (1) hide show
  1. app.py +23 -4
app.py CHANGED
@@ -7,6 +7,7 @@ import os
7
  import gzip
8
  import shutil
9
  import numpy as np
 
10
  import matplotlib.pyplot as plt
11
 
12
  from huggingface_hub import hf_hub_download
@@ -193,7 +194,19 @@ def perturb(gene, locus1, locus2):
193
  # convert from argb to rgba
194
  image_from_plot = image_from_plot[:, :, [1, 2, 3, 0]]
195
 
196
- return image_from_plot
 
 
 
 
 
 
 
 
 
 
 
 
197
 
198
 
199
 
@@ -207,8 +220,14 @@ with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
207
  run_button = gr.Button(label="Run", elem_id='run-button', scale=1)
208
  with gr.Row():
209
  out_img = gr.Image(elem_id='out-img', scale=1)
 
 
 
210
  #out_plot = gr.Plot(elem_id='out-plot', scale=1)
211
 
 
 
 
212
  gr.Examples(examples=[['INS', 'chr11:2,289,895', 'chr11:2,298,840'],
213
  ['INS', 'INS', 'IGF1'],
214
  ['TSPAN1', 'TSPAN1', 'PIK3R3'],
@@ -216,10 +235,10 @@ with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
216
  ['KRT19', 'chr17:22,220,637', 'chr17:39,591,813'],
217
  ['LPP', 'chr3:188,097,749', 'chr3:197,916,262'],
218
  ['CEL', 'chr9:135,937,365', 'chr9:135,973,107']],
219
- inputs=[in_locus, anchor1, anchor2],
220
- outputs=[out_img],
221
  fn=perturb, cache_examples=os.getenv('SYSTEM') == 'spaces')
222
- run_button.click(perturb, [in_locus, anchor1, anchor2], outputs=[out_img])
223
 
224
 
225
  if __name__ == "__main__":
 
7
  import gzip
8
  import shutil
9
  import numpy as np
10
+ import plotly.plotly as py
11
  import matplotlib.pyplot as plt
12
 
13
  from huggingface_hub import hf_hub_download
 
194
  # convert from argb to rgba
195
  image_from_plot = image_from_plot[:, :, [1, 2, 3, 0]]
196
 
197
+ fig = sc.pl.violin(rna, gene, groupby='celltype', return_fig=True)
198
+ fig.canvas.draw()
199
+ violin_img = np.frombuffer(fig.canvas.tostring_argb(), dtype=np.uint8)
200
+ violin_img = violin_img.reshape(fig.canvas.get_width_height()[::-1] + (4,))
201
+ violin_img = violin_img[:, :, [1, 2, 3, 0]]
202
+
203
+ fig = sc.pl.violin(rna, 'log2FC', groupby='celltype', return_fig=True)
204
+ fig.canvas.draw()
205
+ violin_img_fc = np.frombuffer(fig.canvas.tostring_argb(), dtype=np.uint8)
206
+ violin_img_fc = violin_img_fc.reshape(fig.canvas.get_width_height()[::-1] + (4,))
207
+ violin_img_fc = violin_img_fc[:, :, [1, 2, 3, 0]]
208
+
209
+ return image_from_plot, violin_img, violin_img_fc
210
 
211
 
212
 
 
220
  run_button = gr.Button(label="Run", elem_id='run-button', scale=1)
221
  with gr.Row():
222
  out_img = gr.Image(elem_id='out-img', scale=1)
223
+ with gr.Row():
224
+ out_violin = gr.Image(elem_id='out-violin', scale=1)
225
+ out_violin_fc = gr.Image(elem_id='out-violin-fc', scale=1)
226
  #out_plot = gr.Plot(elem_id='out-plot', scale=1)
227
 
228
+ inputs = [in_locus, anchor1, anchor2]
229
+ outputs = [out_img, out_violin, out_violin_fc]
230
+
231
  gr.Examples(examples=[['INS', 'chr11:2,289,895', 'chr11:2,298,840'],
232
  ['INS', 'INS', 'IGF1'],
233
  ['TSPAN1', 'TSPAN1', 'PIK3R3'],
 
235
  ['KRT19', 'chr17:22,220,637', 'chr17:39,591,813'],
236
  ['LPP', 'chr3:188,097,749', 'chr3:197,916,262'],
237
  ['CEL', 'chr9:135,937,365', 'chr9:135,973,107']],
238
+ inputs=inputs,
239
+ outputs=outputs,
240
  fn=perturb, cache_examples=os.getenv('SYSTEM') == 'spaces')
241
+ run_button.click(perturb, [in_locus, anchor1, anchor2], outputs=outputs)
242
 
243
 
244
  if __name__ == "__main__":