Arts-of-coding commited on
Commit
8480f07
·
verified ·
1 Parent(s): d91d7b3

Update pages/keratinocytes_scVI_integration.py

Browse files
pages/keratinocytes_scVI_integration.py CHANGED
@@ -9,7 +9,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
 
@@ -48,171 +49,27 @@ 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}
52
- #azfs = AzureBlobFileSystem(**storage_options )
53
 
54
  # Load in multiple dataframes
55
  df = pl.scan_parquet(f"az://{dataset}.parquet", storage_options=storage_options).collect()
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_db2-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_db2-1', type='number', value=min_value, debounce=True),
122
- dcc.Input(id='max-slider_db2-1', type='number', value=max_value, debounce=True),
123
- html.Label("Total Counts"),
124
- dcc.RangeSlider(
125
- id='range-slider_db2-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_db2-2', type='number', value=min_value_2, debounce=True),
131
- dcc.Input(id='max-slider_db2-2', type='number', value=max_value_2, debounce=True),
132
- html.Label("Percent Mitochondrial Genes"),
133
- dcc.RangeSlider(
134
- id='range-slider_db2-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_db2-3', type='number', value=min_value_3, debounce=True),
141
- dcc.Input(id='max-slider_db2-3', type='number', value=max_value_3, debounce=True),
142
- html.Div([
143
- dcc.Graph(id='pie-graph_db2', figure={}, className='four columns',config=config_fig),
144
- dcc.Graph(id='my-graph_db2', figure={}, clickData=None, hoverData=None,
145
- className='four columns',config=config_fig
146
- ),
147
- dcc.Graph(id='scatter-plot_db2', figure={}, className='four columns',config=config_fig)
148
- ]),
149
- html.Div([
150
- dcc.Graph(id='scatter-plot_db2-2', figure={}, className='four columns',config=config_fig)
151
- ]),
152
- html.Div([
153
- dcc.Graph(id='scatter-plot_db2-3', figure={}, className='four columns',config=config_fig)
154
- ]),
155
- html.Div([
156
- dcc.Graph(id='scatter-plot_db2-4', figure={}, className='four columns',config=config_fig)
157
- ]),
158
- ])
159
-
160
  # Create the second tab content with scatter-plot_db2-5 and scatter-plot_db2-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
- "MCM5",
167
- "PCNA",
168
- "TYMS",
169
- "FEN1",
170
- "MCM2",
171
- "MCM4",
172
- "RRM1",
173
- "UNG",
174
- "GINS2",
175
- "MCM6",
176
- "CDCA7",
177
- "DTL",
178
- "PRIM1",
179
- "UHRF1",
180
- "MLF1IP",
181
- "HELLS",
182
- "RFC2",
183
- "RPA2",
184
- "NASP",
185
- "RAD51AP1",
186
- "GMNN",
187
- "WDR76",
188
- "SLBP",
189
- "CCNE2",
190
- "UBR7",
191
- "POLD3",
192
- "MSH2",
193
- "ATAD2",
194
- "RAD51",
195
- "RRM2",
196
- "CDC45",
197
- "CDC6",
198
- "EXO1",
199
- "TIPIN",
200
- "DSCC1",
201
- "BLM",
202
- "CASP8AP2",
203
- "USP1",
204
- "CLSPN",
205
- "POLA1",
206
- "CHAF1B",
207
- "BRIP1",
208
- "E2F8"
209
- ]),
210
  html.Label("G2M-cycle genes"),
211
  dcc.Dropdown(id='dpdn4', value="TOP2A", multi=False,
212
- options=[
213
- 'HMGB2', 'CDK1', 'NUSAP1', 'UBE2C', 'BIRC5', 'TPX2', 'TOP2A', 'NDC80', 'CKS2', 'NUF2', 'CKS1B', 'MKI67', 'TMPO', 'CENPF', 'TACC3', 'FAM64A', 'SMC4', 'CCNB2', 'CKAP2L', 'CKAP2', 'AURKB', 'BUB1', 'KIF11', 'ANP32E', 'TUBB4B', 'GTSE1', 'KIF20B', 'HJURP', 'CDCA3', 'HN1', 'CDC20', 'TTK', 'CDC25C', 'KIF2C', 'RANGAP1', 'NCAPD2', 'DLGAP5', 'CDCA2', 'CDCA8', 'ECT2', 'KIF23', 'HMMR', 'AURKA', 'PSRC1', 'ANLN', 'LBR', 'CKAP5',
214
- 'CENPE', 'CTCF', 'NEK2', 'G2E3', 'GAS2L3', 'CBX5', 'CENPA'
215
- ]),
 
216
  ]),
217
  html.Div([
218
  dcc.Graph(id='scatter-plot_db2-5', figure={}, className='three columns',config=config_fig)
@@ -235,13 +92,13 @@ tab3_content = html.Div([
235
  dcc.Dropdown(id='dpdn5', value="batch", multi=False,
236
  options=df.columns),
237
  html.Label("UMAP condition 2"),
238
- dcc.Dropdown(id='dpdn6', value="n_genes_by_counts", multi=False,
239
  options=df.columns),
240
  html.Div([
241
- dcc.Graph(id='scatter-plot_db2-9', figure={}, className='four columns',config=config_fig)
242
  ]),
243
  html.Div([
244
- dcc.Graph(id='scatter-plot_db2-10', figure={}, className='four columns',config=config_fig)
245
  ]),
246
  html.Div([
247
  dcc.Graph(id='scatter-plot_db2-11', figure={}, className='four columns',config=config_fig)
@@ -253,12 +110,11 @@ tab3_content = html.Div([
253
  ]),
254
  ]),
255
  ])
256
- # html.Div([
257
- # dcc.Graph(id='scatter-plot_db2-12', figure={}, className='four columns',config=config_fig)
258
- # ]),
259
-
260
 
261
  tab4_content = html.Div([
 
 
 
262
  html.Div([
263
  html.Label("Multi gene"),
264
  dcc.Dropdown(id='dpdn7', value=["PAX6","TP63","S100A9","KRT5","KRT14","KRT10"], multi=True,
@@ -276,54 +132,14 @@ layout = html.Div([
276
  'font-size': '100%',
277
  'height': 50}, value='tab1',children=[
278
  #dcc.Tab(label='Dataset', value='tab0', children=tab0_content),
279
- dcc.Tab(label='QC', value='tab1', children=tab1_content),
280
- dcc.Tab(label='Cell cycle', value='tab2', children=tab2_content),
281
- dcc.Tab(label='Custom', value='tab3', children=tab3_content),
282
  dcc.Tab(label='Multi dot', value='tab4', children=tab4_content),
 
283
  ]),
284
  ])
285
 
286
- # Define the circular callback
287
- @callback(
288
- Output("min-slider_db2-1", "value"),
289
- Output("max-slider_db2-1", "value"),
290
- Output("min-slider_db2-2", "value"),
291
- Output("max-slider_db2-2", "value"),
292
- Output("min-slider_db2-3", "value"),
293
- Output("max-slider_db2-3", "value"),
294
- Input("min-slider_db2-1", "value"),
295
- Input("max-slider_db2-1", "value"),
296
- Input("min-slider_db2-2", "value"),
297
- Input("max-slider_db2-2", "value"),
298
- Input("min-slider_db2-3", "value"),
299
- Input("max-slider_db2-3", "value"),
300
-
301
- )
302
- def circular_callback(min_1, max_1, min_2, max_2, min_3, max_3):
303
- return min_1, max_1, min_2, max_2, min_3, max_3
304
-
305
- @callback(
306
- Output('range-slider_db2-1', 'value'),
307
- Output('range-slider_db2-2', 'value'),
308
- Output('range-slider_db2-3', 'value'),
309
- Input('min-slider_db2-1', 'value'),
310
- Input('max-slider_db2-1', 'value'),
311
- Input('min-slider_db2-2', 'value'),
312
- Input('max-slider_db2-2', 'value'),
313
- Input('min-slider_db2-3', 'value'),
314
- Input('max-slider_db2-3', 'value'),
315
-
316
- )
317
- def update_slider_values(min_1, max_1, min_2, max_2, min_3, max_3):
318
- return [min_1, max_1], [min_2, max_2], [min_3, max_3]
319
-
320
  @callback(
321
- Output(component_id='my-graph_db2', component_property='figure'),
322
- Output(component_id='pie-graph_db2', component_property='figure'),
323
- Output(component_id='scatter-plot_db2', component_property='figure'),
324
- Output(component_id='scatter-plot_db2-2', component_property='figure'),
325
- Output(component_id='scatter-plot_db2-3', component_property='figure'),
326
- Output(component_id='scatter-plot_db2-4', component_property='figure'), # Add this new scatter plot
327
  Output(component_id='scatter-plot_db2-5', component_property='figure'),
328
  Output(component_id='scatter-plot_db2-6', component_property='figure'),
329
  Output(component_id='scatter-plot_db2-7', component_property='figure'),
@@ -339,44 +155,19 @@ def update_slider_values(min_1, max_1, min_2, max_2, min_3, max_3):
339
  Input(component_id='dpdn5', component_property='value'),
340
  Input(component_id='dpdn6', component_property='value'),
341
  Input(component_id='dpdn7', component_property='value'),
342
- Input(component_id='range-slider_db2-1', component_property='value'),
343
- Input(component_id='range-slider_db2-2', component_property='value'),
344
- Input(component_id='range-slider_db2-3', component_property='value'),
345
 
346
  )
347
 
348
- 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,
349
  batch_chosen = df[col_chosen].unique().to_list()
350
  dff = df.filter(
351
- (pl.col(col_chosen).cast(str).is_in(batch_chosen)) &
352
- (pl.col(col_features) >= range_value_1[0]) &
353
- (pl.col(col_features) <= range_value_1[1]) &
354
- (pl.col(col_counts) >= range_value_2[0]) &
355
- (pl.col(col_counts) <= range_value_2[1]) &
356
- (pl.col(col_mt) >= range_value_3[0]) &
357
- (pl.col(col_mt) <= range_value_3[1])
358
  )
359
-
360
- #Drop categories that are not in the filtered data
361
- dff = dff.with_columns(dff[col_chosen].cast(pl.Categorical))
362
-
363
- dff = dff.sort(col_chosen)
364
-
365
- # Plot figures
366
- fig_violin_db2 = px.violin(data_frame=dff, x=col_chosen, y=col_features, box=True, points="all",
367
- color=col_chosen, hover_name=col_chosen,template="plotly_white")
368
-
369
- # Cache commonly used subexpressions
370
- total_count = pl.lit(len(dff))
371
- category_counts = dff.group_by(col_chosen).agg(pl.col(col_chosen).count().alias("count"))
372
- category_counts = category_counts.with_columns(((pl.col("count") / total_count * 100).round(decimals=2)).alias("normalized_count"))
373
-
374
- # Sort the dataframe
375
- #category_counts = category_counts.sort(col_chosen) does not work check if the names are different ...
376
-
377
- # Display the result
378
- total_cells = total_count # Calculate total number of cells
379
- pie_title = f'Percentage of Total Cells: {total_cells}' # Include total cells in the title
380
 
381
  # Calculate the mean expression
382
 
@@ -388,9 +179,9 @@ def update_graph_and_pie_chart(col_chosen, s_chosen, g2m_chosen, condition1_chos
388
 
389
  # Melt wide format DataFrame into long format
390
  dff_long = dff_pre.melt(id_vars=col_chosen, variable_name="Gene", value_name="Mean expression")
391
-
392
  # Calculate the mean expression levels for each gene in each region
393
- expression_means = dff_long.lazy().group_by([col_chosen, "Gene"]).agg(pl.mean("Mean expression")).collect()
394
 
395
  # Calculate the percentage total expressed
396
  dff_long1 = dff_pre.melt(id_vars=col_chosen, variable_name="Gene")#.group_by(pl.all()).agg(pl.len())
@@ -409,79 +200,58 @@ def update_graph_and_pie_chart(col_chosen, s_chosen, g2m_chosen, condition1_chos
409
  dff_5 = dff_5.select(pl.col(col_chosen,"Gene","percentage"))
410
 
411
  # Final part to join the percentage expressed and mean expression levels
412
- # TO DO
413
  expression_means = expression_means.join(dff_5, on=[col_chosen,"Gene"], how="inner")
414
-
415
- # Order the dataframe on ascending categories
416
- expression_means = expression_means.sort(col_chosen, descending=True)
417
-
418
- #expression_means = expression_means.select(["batch", "Gene", "Expression"] + condition3_chosen)
419
- category_counts = category_counts.sort(col_chosen)
420
-
421
- fig_pie_db2 = px.pie(category_counts, values="normalized_count", names=col_chosen, labels=col_chosen, hole=.3, title=pie_title, template="plotly_white")
422
-
423
- #labels = category_counts[col_chosen].to_list()
424
- #values = category_counts["normalized_count"].to_list()
425
-
426
- # Create the scatter plots
427
- fig_scatter_db2 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_chosen,
428
- labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
429
- hover_name='batch',template="plotly_white")
430
-
431
- fig_scatter_db2_2 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_mt,
432
- labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
433
- hover_name='batch',template="plotly_white")
434
-
435
- fig_scatter_db2_3 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_features,
436
- labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
437
- hover_name='batch',template="plotly_white")
438
-
439
-
440
- fig_scatter_db2_4 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_counts,
441
- labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
442
- hover_name='batch',template="plotly_white")
443
 
444
  fig_scatter_db2_5 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=s_chosen,
445
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
446
- hover_name='batch', title="S-cycle gene:",template="plotly_white")
447
 
448
  fig_scatter_db2_6 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=g2m_chosen,
449
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
450
- hover_name='batch', title="G2M-cycle gene:",template="plotly_white")
451
 
452
  fig_scatter_db2_7 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="S_score",
453
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
454
- hover_name='batch', title="S score:",template="plotly_white")
455
 
456
  fig_scatter_db2_8 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="G2M_score",
457
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
458
- hover_name='batch', title="G2M score:",template="plotly_white")
459
 
460
  # Sort values of custom in-between
461
  dff = dff.sort(condition1_chosen)
462
 
463
  fig_scatter_db2_9 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition1_chosen,
464
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
465
- hover_name='batch',template="plotly_white")
 
 
466
 
467
  fig_scatter_db2_10 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition2_chosen,
468
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
469
- hover_name='batch',template="plotly_white")
470
 
471
  fig_scatter_db2_11 = px.scatter(data_frame=dff, x=condition1_chosen, y=condition2_chosen, color=condition1_chosen,
472
  #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
473
- hover_name='batch',template="plotly_white")
474
-
475
- fig_scatter_db2_12 = px.scatter(data_frame=expression_means, x="Gene", y=col_chosen, color="Mean expression",
476
- size="percentage", size_max = 20,
477
- #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
478
- hover_name=col_chosen,template="plotly_white")
 
 
 
 
 
 
 
479
 
480
  fig_violin_db22 = px.violin(data_frame=dff, x=condition1_chosen, y=condition2_chosen, box=True, points="all",
481
- color=condition1_chosen, hover_name=condition1_chosen,template="plotly_white")
482
 
483
 
484
- return fig_violin_db2, fig_pie_db2, fig_scatter_db2, fig_scatter_db2_2, fig_scatter_db2_3, fig_scatter_db2_4, fig_scatter_db2_5, fig_scatter_db2_6, fig_scatter_db2_7, fig_scatter_db2_8, fig_scatter_db2_9, fig_scatter_db2_10, fig_scatter_db2_11, fig_scatter_db2_12, fig_violin_db22
485
 
486
  # Set http://localhost:5000/ in web browser
487
  # Now create your regular FASTAPI application
 
9
  import yaml
10
  import polars as pl
11
  import os
12
+ from natsort import natsorted
13
+ #pl.enable_string_cache(False)
14
 
15
  dash.register_page(__name__, location="sidebar")
16
 
 
49
 
50
  #filepath = f"az://{path_parquet}"
51
 
52
+ storage_options={'account_name': AZURE_STORAGE_ACCOUNT, 'account_key': AZURE_STORAGE_ACCESS_KEY} #,'anon': False
 
53
 
54
  # Load in multiple dataframes
55
  df = pl.scan_parquet(f"az://{dataset}.parquet", storage_options=storage_options).collect()
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  # Create the second tab content with scatter-plot_db2-5 and scatter-plot_db2-6
58
  tab2_content = html.Div([
59
  html.Div([
60
  html.Label("S-cycle genes"),
61
  dcc.Dropdown(id='dpdn3', value="MCM5", multi=False,
62
+ options=["MCM5","PCNA","TYMS","FEN1","MCM2","MCM4","RRM1","UNG","GINS2","MCM6","CDCA7","DTL",
63
+ "PRIM1","UHRF1","HELLS","RFC2","RPA2","NASP","RAD51AP1","GMNN","WDR76","SLBP","CCNE2","UBR7",
64
+ "POLD3","MSH2","ATAD2","RAD51","RRM2","CDC45","CDC6","EXO1","TIPIN","DSCC1","BLM","CASP8AP2",
65
+ "USP1","CLSPN","POLA1","CHAF1B","BRIP1","E2F8"]),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  html.Label("G2M-cycle genes"),
67
  dcc.Dropdown(id='dpdn4', value="TOP2A", multi=False,
68
+ options=["HMGB2","CDK1","NUSAP1","UBE2C","BIRC5","TPX2","TOP2A","NDC80","CKS2","NUF2","CKS1B","MKI67",
69
+ "TMPO","CENPF","TACC3","SMC4","CCNB2","CKAP2L","CKAP2","AURKB","BUB1","KIF11","ANP32E","TUBB4B",
70
+ "GTSE1","KIF20B","HJURP","CDCA3","CDC20","TTK","CDC25C","KIF2C","RANGAP1","NCAPD2","DLGAP5","CDCA2",
71
+ "CDCA8","ECT2","KIF23","HMMR","AURKA","PSRC1","ANLN","LBR","CKAP5","CENPE","CTCF","NEK2","G2E3",
72
+ "GAS2L3","CBX5","CENPA"]),
73
  ]),
74
  html.Div([
75
  dcc.Graph(id='scatter-plot_db2-5', figure={}, className='three columns',config=config_fig)
 
92
  dcc.Dropdown(id='dpdn5', value="batch", multi=False,
93
  options=df.columns),
94
  html.Label("UMAP condition 2"),
95
+ dcc.Dropdown(id='dpdn6', value="PAX6", multi=False,
96
  options=df.columns),
97
  html.Div([
98
+ dcc.Graph(id='scatter-plot_db2-9', figure={}, className='four columns', hoverData=None ,config=config_fig)
99
  ]),
100
  html.Div([
101
+ dcc.Graph(id='scatter-plot_db2-10', figure={}, className='four columns', hoverData=None, config=config_fig)
102
  ]),
103
  html.Div([
104
  dcc.Graph(id='scatter-plot_db2-11', figure={}, className='four columns',config=config_fig)
 
110
  ]),
111
  ]),
112
  ])
 
 
 
 
113
 
114
  tab4_content = html.Div([
115
+ html.Label("Column chosen"),
116
+ dcc.Dropdown(id='dpdn2', value="integrated_clusters", multi=False,
117
+ options=df.columns),
118
  html.Div([
119
  html.Label("Multi gene"),
120
  dcc.Dropdown(id='dpdn7', value=["PAX6","TP63","S100A9","KRT5","KRT14","KRT10"], multi=True,
 
132
  'font-size': '100%',
133
  'height': 50}, value='tab1',children=[
134
  #dcc.Tab(label='Dataset', value='tab0', children=tab0_content),
135
+ #dcc.Tab(label='QC', value='tab1', children=tab1_content),
136
+ dcc.Tab(label='UMAP visualisation', value='tab3', children=tab3_content),
 
137
  dcc.Tab(label='Multi dot', value='tab4', children=tab4_content),
138
+ dcc.Tab(label='Cell cycle', value='tab2', children=tab2_content),
139
  ]),
140
  ])
141
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  @callback(
 
 
 
 
 
 
143
  Output(component_id='scatter-plot_db2-5', component_property='figure'),
144
  Output(component_id='scatter-plot_db2-6', component_property='figure'),
145
  Output(component_id='scatter-plot_db2-7', component_property='figure'),
 
155
  Input(component_id='dpdn5', component_property='value'),
156
  Input(component_id='dpdn6', component_property='value'),
157
  Input(component_id='dpdn7', component_property='value'),
 
 
 
158
 
159
  )
160
 
161
+ 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,
162
  batch_chosen = df[col_chosen].unique().to_list()
163
  dff = df.filter(
164
+ (pl.col(col_chosen).cast(str).is_in(batch_chosen)) #&
 
 
 
 
 
 
165
  )
166
+ # Select ordering of plots
167
+ if condition1_chosen == "leiden_0.45":
168
+ cat_ord= {condition1_chosen: ["1","2","3","4"]}
169
+ else:
170
+ cat_ord= {condition1_chosen: natsorted(dff[condition1_chosen].unique())}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
 
172
  # Calculate the mean expression
173
 
 
179
 
180
  # Melt wide format DataFrame into long format
181
  dff_long = dff_pre.melt(id_vars=col_chosen, variable_name="Gene", value_name="Mean expression")
182
+
183
  # Calculate the mean expression levels for each gene in each region
184
+ expression_means = dff_long.lazy().group_by([col_chosen, "Gene"]).agg(pl.mean("Mean expression")).collect() #
185
 
186
  # Calculate the percentage total expressed
187
  dff_long1 = dff_pre.melt(id_vars=col_chosen, variable_name="Gene")#.group_by(pl.all()).agg(pl.len())
 
200
  dff_5 = dff_5.select(pl.col(col_chosen,"Gene","percentage"))
201
 
202
  # Final part to join the percentage expressed and mean expression levels
 
203
  expression_means = expression_means.join(dff_5, on=[col_chosen,"Gene"], how="inner")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
 
205
  fig_scatter_db2_5 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=s_chosen,
206
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
207
+ hover_name=None, title="S-cycle gene:",template="seaborn")
208
 
209
  fig_scatter_db2_6 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=g2m_chosen,
210
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
211
+ hover_name='batch', title="G2M-cycle gene:",template="seaborn")
212
 
213
  fig_scatter_db2_7 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="S_score",
214
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
215
+ hover_name='batch', title="S score:",template="seaborn")
216
 
217
  fig_scatter_db2_8 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="G2M_score",
218
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
219
+ hover_name='batch', title="G2M score:",template="seaborn")
220
 
221
  # Sort values of custom in-between
222
  dff = dff.sort(condition1_chosen)
223
 
224
  fig_scatter_db2_9 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition1_chosen,
225
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
226
+ hover_name=None,hover_data = None, template="seaborn",category_orders=cat_ord)
227
+ fig_scatter_db2_9.update_traces(hoverinfo='none', hovertemplate=None)
228
+ fig_scatter_db2_9.update_layout(hovermode=False)
229
 
230
  fig_scatter_db2_10 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition2_chosen,
231
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
232
+ hover_name='batch',template="seaborn")
233
 
234
  fig_scatter_db2_11 = px.scatter(data_frame=dff, x=condition1_chosen, y=condition2_chosen, color=condition1_chosen,
235
  #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
236
+ hover_name='batch',template="seaborn",category_orders=cat_ord)
237
+
238
+ # Reorder categories on natural sorting or on the integrated cell state order of the paper
239
+ if col_chosen == "leiden_0.45":
240
+ fig_scatter_db2_12 = px.scatter(data_frame=expression_means, x="Gene", y=col_chosen, color="Mean expression",
241
+ size="percentage", size_max = 20,
242
+ #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
243
+ hover_name=col_chosen,template="seaborn",category_orders={col_chosen: ["1","2","3","4"],"Gene": condition3_chosen})
244
+ else:
245
+ fig_scatter_db2_12 = px.scatter(data_frame=expression_means, x="Gene", y=col_chosen, color="Mean expression",
246
+ size="percentage", size_max = 20,
247
+ #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
248
+ hover_name=col_chosen,template="seaborn",category_orders={col_chosen: natsorted(expression_means[col_chosen].unique()),"Gene": condition3_chosen})
249
 
250
  fig_violin_db22 = px.violin(data_frame=dff, x=condition1_chosen, y=condition2_chosen, box=True, points="all",
251
+ color=condition1_chosen, hover_name=condition1_chosen,template="seaborn",category_orders=cat_ord)
252
 
253
 
254
+ return fig_scatter_db2_5, fig_scatter_db2_6, fig_scatter_db2_7, fig_scatter_db2_8, fig_scatter_db2_9, fig_scatter_db2_10, fig_scatter_db2_11, fig_scatter_db2_12, fig_violin_db22 #fig_violin_db2, fig_pie_db2, fig_scatter_db2, fig_scatter_db2_2, fig_scatter_db2_3, fig_scatter_db2_4,
255
 
256
  # Set http://localhost:5000/ in web browser
257
  # Now create your regular FASTAPI application