Arts-of-coding commited on
Commit
f04aa89
1 Parent(s): e8649cd

Create 4mhet_aniridia.py

Browse files
Files changed (1) hide show
  1. pages/4mhet_aniridia.py +542 -0
pages/4mhet_aniridia.py ADDED
@@ -0,0 +1,542 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dash app to visualize scRNA-seq data quality control metrics from scanpy objects
2
+ # Shoutout to Coding-with-Adam for the initial template of the project:
3
+ # https://github.com/Coding-with-Adam/Dash-by-Plotly/blob/master/Dash%20Components/Graph/dash-graph.py
4
+
5
+ import dash
6
+ from dash import dcc, html, Output, Input, callback
7
+ import plotly.express as px
8
+ import dash_callback_chain
9
+ import yaml
10
+ import polars as pl
11
+ import os
12
+ pl.enable_string_cache(False)
13
+
14
+ dash.register_page(__name__, location="sidebar")
15
+
16
+ dataset = "dataaniridia/4mhet/sc_liu_aniridia_4mhet_processed"
17
+
18
+ # Set custom resolution for plots:
19
+ config_fig = {
20
+ 'toImageButtonOptions': {
21
+ 'format': 'svg',
22
+ 'filename': 'custom_image',
23
+ 'height': 600,
24
+ 'width': 700,
25
+ 'scale': 1,
26
+ }
27
+ }
28
+ from adlfs import AzureBlobFileSystem
29
+ mountpount=os.environ['AZURE_MOUNT_POINT'],
30
+ AZURE_STORAGE_ACCESS_KEY=os.getenv('AZURE_STORAGE_ACCESS_KEY')
31
+ AZURE_STORAGE_ACCOUNT=os.getenv('AZURE_STORAGE_ACCOUNT')
32
+
33
+ # Load in config file
34
+ config_path = "./data/config.yaml"
35
+
36
+ # Add the read-in data from the yaml file
37
+ def read_config(filename):
38
+ with open(filename, 'r') as yaml_file:
39
+ config = yaml.safe_load(yaml_file)
40
+ return config
41
+
42
+ config = read_config(config_path)
43
+ path_parquet = config.get("path_parquet")
44
+ col_batch = config.get("col_batch")
45
+ col_features = config.get("col_features")
46
+ col_counts = config.get("col_counts")
47
+ col_mt = config.get("col_mt")
48
+
49
+ #filepath = f"az://{path_parquet}"
50
+
51
+ storage_options={'account_name': AZURE_STORAGE_ACCOUNT, 'account_key': AZURE_STORAGE_ACCESS_KEY,'anon': False}
52
+ #azfs = AzureBlobFileSystem(**storage_options )
53
+
54
+ # Load in multiple dataframes
55
+ df = pl.read_parquet(f"az://{dataset}.parquet", storage_options=storage_options)
56
+
57
+ # Setup the app
58
+ #external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
59
+ #app = dash.Dash(__name__, use_pages=True) #, requests_pathname_prefix='/dashboard1/'
60
+
61
+ #df = pl.read_parquet(filepath,storage_options=storage_options)
62
+ #df = pl.DataFrame()
63
+ #abfs = AzureBlobFileSystem(account_name=accountname,account_key=accountkey)
64
+ #df = df.rename({"__index_level_0__": "Unnamed: 0"})
65
+
66
+ #df1 = pl.read_parquet(filepath, storage_options=storage_options)
67
+
68
+ #df2 = pl.read_parquet(f"az://data10xflex/{dataset_chosen}.parquet", storage_options=storage_options)
69
+
70
+ #tab0_content = html.Div([
71
+ # html.Label("Dataset chosen"),
72
+ # dcc.Dropdown(id='dpdn1', value="corg/10xflexcorg_umap_clusres", multi=False,
73
+ # options=["corg/10xflexcorg_umap_clusres","d1011/10xflexd1011_umap_clusres"])
74
+ #])
75
+
76
+ #@app.callback(
77
+ # Input(component_id='dpdn1', component_property='value')
78
+ #)
79
+
80
+ #def update_filepath(dpdn1):
81
+ # global df
82
+ # if str(f"az://data10xflex/{dpdn1}.parquet") != str(filepath):
83
+ # print("not identical filepath, chosing other")
84
+ # df2 = pl.read_parquet(f"az://data10xflex/{dpdn1}.parquet", storage_options=storage_options)
85
+ # df = df2
86
+ # return
87
+
88
+ #df = pl.read_parquet(filepath, storage_options=storage_options)
89
+ min_value = df[col_features].min()
90
+ max_value = df[col_features].max()
91
+
92
+ min_value_2 = df[col_counts].min()
93
+ min_value_2 = round(min_value_2)
94
+ max_value_2 = df[col_counts].max()
95
+ max_value_2 = round(max_value_2)
96
+
97
+ min_value_3 = df[col_mt].min()
98
+ min_value_3 = round(min_value_3, 1)
99
+ max_value_3 = df[col_mt].max()
100
+ max_value_3 = round(max_value_3, 1)
101
+
102
+ # Loads in the conditions specified in the yaml file
103
+
104
+ # Note: Future version perhaps all values from a column in the dataframe of the parquet file
105
+ # Note 2: This could also be a tsv of the categories and own specified colors
106
+ #conditions = df[col_batch].unique().to_list()
107
+ # Create the first tab content
108
+ # Add Sliders for three QC params: N genes by counts, total amount of reads and pct MT reads
109
+
110
+ tab1_content = html.Div([
111
+ html.Label("Column chosen"),
112
+ dcc.Dropdown(id='dpdn2', value="batch", multi=False,
113
+ options=df.columns),
114
+ html.Label("N Genes by Counts"),
115
+ dcc.RangeSlider(
116
+ id='range-slider_db5-1',
117
+ step=250,
118
+ value=[min_value, max_value],
119
+ marks={i: str(i) for i in range(min_value, max_value + 1, 250)},
120
+ ),
121
+ dcc.Input(id='min-slider_db5-1', type='number', value=min_value, debounce=True),
122
+ dcc.Input(id='max-slider_db5-1', type='number', value=max_value, debounce=True),
123
+ html.Label("Total Counts"),
124
+ dcc.RangeSlider(
125
+ id='range-slider_db5-2',
126
+ step=7500,
127
+ value=[min_value_2, max_value_2],
128
+ marks={i: str(i) for i in range(min_value_2, max_value_2 + 1, 7500)},
129
+ ),
130
+ dcc.Input(id='min-slider_db5-2', type='number', value=min_value_2, debounce=True),
131
+ dcc.Input(id='max-slider_db5-2', type='number', value=max_value_2, debounce=True),
132
+ html.Label("Percent Mitochondrial Genes"),
133
+ dcc.RangeSlider(
134
+ id='range-slider_db5-3',
135
+ step=5,
136
+ min=0,
137
+ max=100,
138
+ value=[min_value_3, max_value_3],
139
+ ),
140
+ dcc.Input(id='min-slider_db5-3', type='number', value=min_value_3, debounce=True),
141
+ dcc.Input(id='max-slider_db5-3', type='number', value=max_value_3, debounce=True),
142
+ html.Div([
143
+ dcc.Graph(id='pie-graph_db5', figure={}, className='four columns',config=config_fig),
144
+ dcc.Graph(id='my-graph_db5', figure={}, clickData=None, hoverData=None,
145
+ className='four columns',config=config_fig
146
+ ),
147
+ dcc.Graph(id='scatter-plot_db5', figure={}, className='four columns',config=config_fig)
148
+ ]),
149
+ html.Div([
150
+ dcc.Graph(id='scatter-plot_db5-2', figure={}, className='four columns',config=config_fig)
151
+ ]),
152
+ html.Div([
153
+ dcc.Graph(id='scatter-plot_db5-3', figure={}, className='four columns',config=config_fig)
154
+ ]),
155
+ html.Div([
156
+ dcc.Graph(id='scatter-plot_db5-4', figure={}, className='four columns',config=config_fig)
157
+ ]),
158
+ ])
159
+
160
+ # Create the second tab content with scatter-plot_db5-5 and scatter-plot_db5-6
161
+ tab2_content = html.Div([
162
+ html.Div([
163
+ html.Label("S-cycle genes"),
164
+ dcc.Dropdown(id='dpdn3', value="Mcm5", multi=False,
165
+ options=[
166
+ "Cdc45",
167
+ "Uhrf1",
168
+ "Mcm2",
169
+ "Slbp",
170
+ "Mcm5",
171
+ "Pola1",
172
+ "Gmnn",
173
+ "Cdc6",
174
+ "Rrm2",
175
+ "Atad2",
176
+ "Dscc1",
177
+ "Mcm4",
178
+ "Chaf1b",
179
+ "Rfc2",
180
+ "Msh2",
181
+ "Fen1",
182
+ "Hells",
183
+ "Prim1",
184
+ "Tyms",
185
+ "Mcm6",
186
+ "Wdr76",
187
+ "Rad51",
188
+ "Pcna",
189
+ "Ccne2",
190
+ "Casp8ap2",
191
+ "Usp1",
192
+ "Nasp",
193
+ "Rpa2",
194
+ "Ung",
195
+ "Rad51ap1",
196
+ "Blm",
197
+ "Pold3",
198
+ "Rrm1",
199
+ "Cenpu",
200
+ "Gins2",
201
+ "Tipin",
202
+ "Brip1",
203
+ "Dtl",
204
+ "Exo1",
205
+ "Ubr7",
206
+ "Clspn",
207
+ "E2f8",
208
+ "Cdca7"
209
+ ]),
210
+ html.Label("G2M-cycle genes"),
211
+ dcc.Dropdown(id='dpdn4', value="Top2a", multi=False,
212
+ options=[
213
+ "Ube2c",
214
+ "Lbr",
215
+ "Ctcf",
216
+ "Cdc20",
217
+ "Cbx5",
218
+ "Kif11",
219
+ "Anp32e",
220
+ "Birc5",
221
+ "Cdk1",
222
+ "Tmpo",
223
+ "Hmmr",
224
+ "Pimreg",
225
+ "Aurkb",
226
+ "Top2a",
227
+ "Gtse1",
228
+ "Rangap1",
229
+ "Cdca3",
230
+ "Ndc80",
231
+ "Kif20b",
232
+ "Cenpf",
233
+ "Nek2",
234
+ "Nuf2",
235
+ "Nusap1",
236
+ "Bub1",
237
+ "Tpx2",
238
+ "Aurka",
239
+ "Ect2",
240
+ "Cks1b",
241
+ "Kif2c",
242
+ "Cdca8",
243
+ "Cenpa",
244
+ "Mki67",
245
+ "Ccnb2",
246
+ "Kif23",
247
+ "Smc4",
248
+ "G2e3",
249
+ "Tubb4b",
250
+ "Anln",
251
+ "Tacc3",
252
+ "Dlgap5",
253
+ "Ckap2",
254
+ "Ncapd2",
255
+ "Ttk",
256
+ "Ckap5",
257
+ "Cdc25c",
258
+ "Hjurp",
259
+ "Cenpe",
260
+ "Ckap2l",
261
+ "Cdca2",
262
+ "Hmgb2",
263
+ "Cks2",
264
+ "Psrc1",
265
+ "Gas2l3"
266
+ ]),
267
+
268
+ ]),
269
+ html.Div([
270
+ dcc.Graph(id='scatter-plot_db5-5', figure={}, className='three columns',config=config_fig)
271
+ ]),
272
+ html.Div([
273
+ dcc.Graph(id='scatter-plot_db5-6', figure={}, className='three columns',config=config_fig)
274
+ ]),
275
+ html.Div([
276
+ dcc.Graph(id='scatter-plot_db5-7', figure={}, className='three columns',config=config_fig)
277
+ ]),
278
+ html.Div([
279
+ dcc.Graph(id='scatter-plot_db5-8', figure={}, className='three columns',config=config_fig)
280
+ ]),
281
+ ])
282
+
283
+ # Create the second tab content with scatter-plot_db5-5 and scatter-plot_db5-6
284
+ tab3_content = html.Div([
285
+ html.Div([
286
+ html.Label("UMAP condition 1"),
287
+ dcc.Dropdown(id='dpdn5', value="batch", multi=False,
288
+ options=df.columns),
289
+ html.Label("UMAP condition 2"),
290
+ dcc.Dropdown(id='dpdn6', value="n_genes_by_counts", multi=False,
291
+ options=df.columns),
292
+ html.Div([
293
+ dcc.Graph(id='scatter-plot_db5-9', figure={}, className='four columns',config=config_fig)
294
+ ]),
295
+ html.Div([
296
+ dcc.Graph(id='scatter-plot_db5-10', figure={}, className='four columns',config=config_fig)
297
+ ]),
298
+ html.Div([
299
+ dcc.Graph(id='scatter-plot_db5-11', figure={}, className='four columns',config=config_fig)
300
+ ]),
301
+ html.Div([
302
+ dcc.Graph(id='my-graph_db52', figure={}, clickData=None, hoverData=None,
303
+ className='four columns',config=config_fig
304
+ )
305
+ ]),
306
+ ]),
307
+ ])
308
+ # html.Div([
309
+ # dcc.Graph(id='scatter-plot_db5-12', figure={}, className='four columns',config=config_fig)
310
+ # ]),
311
+
312
+
313
+ tab4_content = html.Div([
314
+ html.Div([
315
+ html.Label("Multi gene"),
316
+ dcc.Dropdown(id='dpdn7', value=["Pax6","Krt15","Trp63","Krt14","Krt5","Sox9","Cdk8","Il31ra","Gpha2","Abl1","Areg","Lars2","Calml3","Krt13","Krt19","Psca","Muc20","Muc4","Aqp5","S100a8","S100a9","Lama3","Itgb4","Itga6","Lamc2","Cd44","Cdh1","Thy1","Dcn","Scn7a","Cdh19","Mpz","Ptprc","Cd52","Cd69","Cd86","Rgs5","Des","Myh11","Cd93","Pecam1","Abcg2","Lyve1","Mki67","Top2a","Ube2c","Birc5"], multi=True,
317
+ options=df.columns),
318
+ ]),
319
+ html.Div([
320
+ dcc.Graph(id='scatter-plot_db5-12', figure={}, className='row',style={'width': '100vh', 'height': '90vh'}), # px)
321
+ ]),
322
+ ])
323
+
324
+ # Define the tabs layout
325
+ layout = html.Div([
326
+ html.H1(f'Dataset analysis dashboard: {dataset}'),
327
+ dcc.Tabs(id='tabs', style= {'width': 600,
328
+ 'font-size': '100%',
329
+ 'height': 50}, value='tab1',children=[
330
+ #dcc.Tab(label='Dataset', value='tab0', children=tab0_content),
331
+ dcc.Tab(label='QC', value='tab1', children=tab1_content),
332
+ dcc.Tab(label='Cell cycle', value='tab2', children=tab2_content),
333
+ dcc.Tab(label='Custom', value='tab3', children=tab3_content),
334
+ dcc.Tab(label='Multi dot', value='tab4', children=tab4_content),
335
+ ]),
336
+ ])
337
+
338
+ # Define the circular callback
339
+ @callback(
340
+ Output("min-slider_db5-1", "value"),
341
+ Output("max-slider_db5-1", "value"),
342
+ Output("min-slider_db5-2", "value"),
343
+ Output("max-slider_db5-2", "value"),
344
+ Output("min-slider_db5-3", "value"),
345
+ Output("max-slider_db5-3", "value"),
346
+ Input("min-slider_db5-1", "value"),
347
+ Input("max-slider_db5-1", "value"),
348
+ Input("min-slider_db5-2", "value"),
349
+ Input("max-slider_db5-2", "value"),
350
+ Input("min-slider_db5-3", "value"),
351
+ Input("max-slider_db5-3", "value"),
352
+
353
+ )
354
+ def circular_callback(min_1, max_1, min_2, max_2, min_3, max_3):
355
+ return min_1, max_1, min_2, max_2, min_3, max_3
356
+
357
+ @callback(
358
+ Output('range-slider_db5-1', 'value'),
359
+ Output('range-slider_db5-2', 'value'),
360
+ Output('range-slider_db5-3', 'value'),
361
+ Input('min-slider_db5-1', 'value'),
362
+ Input('max-slider_db5-1', 'value'),
363
+ Input('min-slider_db5-2', 'value'),
364
+ Input('max-slider_db5-2', 'value'),
365
+ Input('min-slider_db5-3', 'value'),
366
+ Input('max-slider_db5-3', 'value'),
367
+
368
+ )
369
+ def update_slider_values(min_1, max_1, min_2, max_2, min_3, max_3):
370
+ return [min_1, max_1], [min_2, max_2], [min_3, max_3]
371
+
372
+ @callback(
373
+ Output(component_id='my-graph_db5', component_property='figure'),
374
+ Output(component_id='pie-graph_db5', component_property='figure'),
375
+ Output(component_id='scatter-plot_db5', component_property='figure'),
376
+ Output(component_id='scatter-plot_db5-2', component_property='figure'),
377
+ Output(component_id='scatter-plot_db5-3', component_property='figure'),
378
+ Output(component_id='scatter-plot_db5-4', component_property='figure'), # Add this new scatter plot
379
+ Output(component_id='scatter-plot_db5-5', component_property='figure'),
380
+ Output(component_id='scatter-plot_db5-6', component_property='figure'),
381
+ Output(component_id='scatter-plot_db5-7', component_property='figure'),
382
+ Output(component_id='scatter-plot_db5-8', component_property='figure'),
383
+ Output(component_id='scatter-plot_db5-9', component_property='figure'),
384
+ Output(component_id='scatter-plot_db5-10', component_property='figure'),
385
+ Output(component_id='scatter-plot_db5-11', component_property='figure'),
386
+ Output(component_id='scatter-plot_db5-12', component_property='figure'),
387
+ Output(component_id='my-graph_db52', component_property='figure'),
388
+ Input(component_id='dpdn2', component_property='value'),
389
+ Input(component_id='dpdn3', component_property='value'),
390
+ Input(component_id='dpdn4', component_property='value'),
391
+ Input(component_id='dpdn5', component_property='value'),
392
+ Input(component_id='dpdn6', component_property='value'),
393
+ Input(component_id='dpdn7', component_property='value'),
394
+ Input(component_id='range-slider_db5-1', component_property='value'),
395
+ Input(component_id='range-slider_db5-2', component_property='value'),
396
+ Input(component_id='range-slider_db5-3', component_property='value'),
397
+
398
+ )
399
+
400
+ def update_graph_and_pie_chart(col_chosen, s_chosen, g2m_chosen, condition1_chosen, condition2_chosen, condition3_chosen, range_value_1, range_value_2, range_value_3): #batch_chosen,
401
+ batch_chosen = df[col_chosen].unique().to_list()
402
+ dff = df.filter(
403
+ (pl.col(col_chosen).cast(str).is_in(batch_chosen)) &
404
+ (pl.col(col_features) >= range_value_1[0]) &
405
+ (pl.col(col_features) <= range_value_1[1]) &
406
+ (pl.col(col_counts) >= range_value_2[0]) &
407
+ (pl.col(col_counts) <= range_value_2[1]) &
408
+ (pl.col(col_mt) >= range_value_3[0]) &
409
+ (pl.col(col_mt) <= range_value_3[1])
410
+ )
411
+
412
+ #Drop categories that are not in the filtered data
413
+ dff = dff.with_columns(dff[col_chosen].cast(pl.Categorical))
414
+
415
+ dff = dff.sort(col_chosen)
416
+
417
+ # Plot figures
418
+ fig_violin_db5 = px.violin(data_frame=dff, x=col_chosen, y=col_features, box=True, points="all",
419
+ color=col_chosen, hover_name=col_chosen,template="seaborn")
420
+
421
+ # Cache commonly used subexpressions
422
+ total_count = pl.lit(len(dff))
423
+ category_counts = dff.group_by(col_chosen).agg(pl.col(col_chosen).count().alias("count"))
424
+ category_counts = category_counts.with_columns(((pl.col("count") / total_count * 100).round(decimals=2)).alias("normalized_count"))
425
+
426
+ # Sort the dataframe
427
+ #category_counts = category_counts.sort(col_chosen) does not work check if the names are different ...
428
+
429
+ # Display the result
430
+ total_cells = total_count # Calculate total number of cells
431
+ pie_title = f'Percentage of Total Cells: {total_cells}' # Include total cells in the title
432
+
433
+ # Calculate the mean expression
434
+
435
+ # Melt wide format DataFrame into long format
436
+ # Specify batch column as string type and gene columns as float type
437
+ list_conds = condition3_chosen
438
+ list_conds += [col_chosen]
439
+ dff_pre = dff.select(list_conds)
440
+
441
+ # Melt wide format DataFrame into long format
442
+ dff_long = dff_pre.melt(id_vars=col_chosen, variable_name="Gene", value_name="Mean expression")
443
+
444
+ # Calculate the mean expression levels for each gene in each region
445
+ expression_means = dff_long.lazy().group_by([col_chosen, "Gene"]).agg(pl.mean("Mean expression")).collect()
446
+
447
+ # Calculate the percentage total expressed
448
+ dff_long1 = dff_pre.melt(id_vars=col_chosen, variable_name="Gene")#.group_by(pl.all()).agg(pl.len())
449
+ count = 1
450
+ dff_long2 = dff_long1.with_columns(pl.lit(count).alias("len"))
451
+ dff_long3 = dff_long2.filter(pl.col("value") > 0).group_by([col_chosen, "Gene"]).agg(pl.sum("len").alias("len"))
452
+ dff_long4 = dff_long2.group_by([col_chosen, "Gene"]).agg(pl.sum("len").alias("total"))
453
+ dff_5 = dff_long4.join(dff_long3, on=[col_chosen,"Gene"], how="outer")
454
+ result = dff_5.select([
455
+ pl.when((pl.col('len').is_not_null()) & (pl.col('total').is_not_null()))
456
+ .then(pl.col('len') / pl.col('total')*100)
457
+ .otherwise(None).alias("%"),
458
+ ])
459
+ result = result.with_columns(pl.col("%").fill_null(0))
460
+ dff_5[["percentage"]] = result[["%"]]
461
+ dff_5 = dff_5.select(pl.col(col_chosen,"Gene","percentage"))
462
+
463
+ # Final part to join the percentage expressed and mean expression levels
464
+ # TO DO
465
+ expression_means = expression_means.join(dff_5, on=[col_chosen,"Gene"], how="inner")
466
+
467
+ # Order the dataframe on ascending categories
468
+ expression_means = expression_means.sort(col_chosen, descending=True)
469
+
470
+ #expression_means = expression_means.select(["batch", "Gene", "Expression"] + condition3_chosen)
471
+ category_counts = category_counts.sort(col_chosen)
472
+
473
+ fig_pie_db5 = px.pie(category_counts, values="normalized_count", names=col_chosen, labels=col_chosen, hole=.3, title=pie_title, template="seaborn")
474
+
475
+ #labels = category_counts[col_chosen].to_list()
476
+ #values = category_counts["normalized_count"].to_list()
477
+
478
+ # Create the scatter plots
479
+ fig_scatter_db5 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_chosen,
480
+ labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
481
+ hover_name='batch',template="seaborn")
482
+
483
+ fig_scatter_db5_2 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_mt,
484
+ labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
485
+ hover_name='batch',template="seaborn")
486
+
487
+ fig_scatter_db5_3 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_features,
488
+ labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
489
+ hover_name='batch',template="seaborn")
490
+
491
+
492
+ fig_scatter_db5_4 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_counts,
493
+ labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
494
+ hover_name='batch',template="seaborn")
495
+
496
+ fig_scatter_db5_5 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=s_chosen,
497
+ labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
498
+ hover_name='batch', title="S-cycle gene:",template="seaborn")
499
+
500
+ fig_scatter_db5_6 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=g2m_chosen,
501
+ labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
502
+ hover_name='batch', title="G2M-cycle gene:",template="seaborn")
503
+
504
+ fig_scatter_db5_7 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="S_score",
505
+ labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
506
+ hover_name='batch', title="S score:",template="seaborn")
507
+
508
+ fig_scatter_db5_8 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="G2M_score",
509
+ labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
510
+ hover_name='batch', title="G2M score:",template="seaborn")
511
+
512
+ # Sort values of custom in-between
513
+ dff = dff.sort(condition1_chosen)
514
+
515
+ fig_scatter_db5_9 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition1_chosen,
516
+ labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
517
+ hover_name='batch',template="seaborn")
518
+
519
+ fig_scatter_db5_10 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition2_chosen,
520
+ labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
521
+ hover_name='batch',template="seaborn")
522
+
523
+ fig_scatter_db5_11 = px.scatter(data_frame=dff, x=condition1_chosen, y=condition2_chosen, color=condition1_chosen,
524
+ #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
525
+ hover_name='batch',template="seaborn")
526
+
527
+ fig_scatter_db5_12 = px.scatter(data_frame=expression_means, x="Gene", y=col_chosen, color="Mean expression",
528
+ size="percentage", size_max = 20,
529
+ #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
530
+ hover_name=col_chosen,template="seaborn")
531
+
532
+ fig_violin_db52 = px.violin(data_frame=dff, x=condition1_chosen, y=condition2_chosen, box=True, points="all",
533
+ color=condition1_chosen, hover_name=condition1_chosen,template="seaborn")
534
+
535
+
536
+ return fig_violin_db5, fig_pie_db5, fig_scatter_db5, fig_scatter_db5_2, fig_scatter_db5_3, fig_scatter_db5_4, fig_scatter_db5_5, fig_scatter_db5_6, fig_scatter_db5_7, fig_scatter_db5_8, fig_scatter_db5_9, fig_scatter_db5_10, fig_scatter_db5_11, fig_scatter_db5_12, fig_violin_db52
537
+
538
+ # Set http://localhost:5000/ in web browser
539
+ # Now create your regular FASTAPI application
540
+
541
+ #if __name__ == '__main__':
542
+ # app.run_server(debug=False, use_reloader=False, host='0.0.0.0', port=5000) #