Arts-of-coding commited on
Commit
d7e8dc5
·
verified ·
1 Parent(s): 2ac7773

Update pages/DLC_corg_week12.py

Browse files
Files changed (1) hide show
  1. pages/DLC_corg_week12.py +84 -321
pages/DLC_corg_week12.py CHANGED
@@ -9,11 +9,12 @@ 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 = "corg/DLC_corg_w12"
17
 
18
  # Set custom resolution for plots:
19
  config_fig = {
@@ -45,230 +46,84 @@ 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_db3-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_db3-1', type='number', value=min_value, debounce=True),
122
- dcc.Input(id='max-slider_db3-1', type='number', value=max_value, debounce=True),
123
- html.Label("Total Counts"),
124
- dcc.RangeSlider(
125
- id='range-slider_db3-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_db3-2', type='number', value=min_value_2, debounce=True),
131
- dcc.Input(id='max-slider_db3-2', type='number', value=max_value_2, debounce=True),
132
- html.Label("Percent Mitochondrial Genes"),
133
- dcc.RangeSlider(
134
- id='range-slider_db3-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_db3-3', type='number', value=min_value_3, debounce=True),
141
- dcc.Input(id='max-slider_db3-3', type='number', value=max_value_3, debounce=True),
142
- html.Div([
143
- dcc.Graph(id='pie-graph_db3', figure={}, className='four columns',config=config_fig),
144
- dcc.Graph(id='my-graph_db3', figure={}, clickData=None, hoverData=None,
145
- className='four columns',config=config_fig
146
- ),
147
- dcc.Graph(id='scatter-plot_db3', figure={}, className='four columns',config=config_fig)
148
- ]),
149
- html.Div([
150
- dcc.Graph(id='scatter-plot_db3-2', figure={}, className='four columns',config=config_fig)
151
- ]),
152
- html.Div([
153
- dcc.Graph(id='scatter-plot_db3-3', figure={}, className='four columns',config=config_fig)
154
- ]),
155
- html.Div([
156
- dcc.Graph(id='scatter-plot_db3-4', figure={}, className='four columns',config=config_fig)
157
- ]),
158
- ])
159
-
160
- # Create the second tab content with scatter-plot_db3-5 and scatter-plot_db3-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_db3-5', figure={}, className='three columns',config=config_fig)
219
  ]),
220
  html.Div([
221
- dcc.Graph(id='scatter-plot_db3-6', figure={}, className='three columns',config=config_fig)
222
  ]),
223
  html.Div([
224
- dcc.Graph(id='scatter-plot_db3-7', figure={}, className='three columns',config=config_fig)
225
  ]),
226
  html.Div([
227
- dcc.Graph(id='scatter-plot_db3-8', figure={}, className='three columns',config=config_fig)
228
  ]),
229
  ])
230
 
231
- # Create the second tab content with scatter-plot_db3-5 and scatter-plot_db3-6
232
  tab3_content = html.Div([
233
  html.Div([
234
  html.Label("UMAP condition 1"),
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_db3-9', figure={}, className='four columns',config=config_fig)
242
  ]),
243
  html.Div([
244
- dcc.Graph(id='scatter-plot_db3-10', figure={}, className='four columns',config=config_fig)
245
  ]),
246
  html.Div([
247
- dcc.Graph(id='scatter-plot_db3-11', figure={}, className='four columns',config=config_fig)
248
  ]),
249
  html.Div([
250
- dcc.Graph(id='my-graph_db32', figure={}, clickData=None, hoverData=None,
251
  className='four columns',config=config_fig
252
  )
253
  ]),
254
  ]),
255
  ])
256
- # html.Div([
257
- # dcc.Graph(id='scatter-plot_db3-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', 'OTX2', 'SIX3', 'LHX2', 'SIX6', 'SOX2', 'PMEL',
265
- 'RAX', 'LIN28A', 'ABCG2', 'KRT8', 'KRT7',
266
- 'KRT19', 'COL1A2', 'AQP1', 'LUM', 'TFAP2A', 'HAND1', 'S100A9',
267
- 'SPP1', 'TEK', 'FOXC2', 'PECAM1', 'SOX9'], multi=True,
268
  options=df.columns),
269
  ]),
270
  html.Div([
271
- dcc.Graph(id='scatter-plot_db3-12', figure={}, className='row',style={'width': '100vh', 'height': '90vh'})
272
  ]),
273
  ])
274
 
@@ -279,107 +134,42 @@ layout = html.Div([
279
  'font-size': '100%',
280
  'height': 50}, value='tab1',children=[
281
  #dcc.Tab(label='Dataset', value='tab0', children=tab0_content),
282
- dcc.Tab(label='QC', value='tab1', children=tab1_content),
283
- dcc.Tab(label='Cell cycle', value='tab2', children=tab2_content),
284
- dcc.Tab(label='Custom', value='tab3', children=tab3_content),
285
  dcc.Tab(label='Multi dot', value='tab4', children=tab4_content),
 
286
  ]),
287
  ])
288
 
289
- # Define the circular callback
290
  @callback(
291
- Output("min-slider_db3-1", "value"),
292
- Output("max-slider_db3-1", "value"),
293
- Output("min-slider_db3-2", "value"),
294
- Output("max-slider_db3-2", "value"),
295
- Output("min-slider_db3-3", "value"),
296
- Output("max-slider_db3-3", "value"),
297
- Input("min-slider_db3-1", "value"),
298
- Input("max-slider_db3-1", "value"),
299
- Input("min-slider_db3-2", "value"),
300
- Input("max-slider_db3-2", "value"),
301
- Input("min-slider_db3-3", "value"),
302
- Input("max-slider_db3-3", "value"),
303
-
304
- )
305
- def circular_callback(min_1, max_1, min_2, max_2, min_3, max_3):
306
- return min_1, max_1, min_2, max_2, min_3, max_3
307
-
308
- @callback(
309
- Output('range-slider_db3-1', 'value'),
310
- Output('range-slider_db3-2', 'value'),
311
- Output('range-slider_db3-3', 'value'),
312
- Input('min-slider_db3-1', 'value'),
313
- Input('max-slider_db3-1', 'value'),
314
- Input('min-slider_db3-2', 'value'),
315
- Input('max-slider_db3-2', 'value'),
316
- Input('min-slider_db3-3', 'value'),
317
- Input('max-slider_db3-3', 'value'),
318
-
319
- )
320
- def update_slider_values(min_1, max_1, min_2, max_2, min_3, max_3):
321
- return [min_1, max_1], [min_2, max_2], [min_3, max_3]
322
-
323
- @callback(
324
- Output(component_id='my-graph_db3', component_property='figure'),
325
- Output(component_id='pie-graph_db3', component_property='figure'),
326
- Output(component_id='scatter-plot_db3', component_property='figure'),
327
- Output(component_id='scatter-plot_db3-2', component_property='figure'),
328
- Output(component_id='scatter-plot_db3-3', component_property='figure'),
329
- Output(component_id='scatter-plot_db3-4', component_property='figure'), # Add this new scatter plot
330
- Output(component_id='scatter-plot_db3-5', component_property='figure'),
331
- Output(component_id='scatter-plot_db3-6', component_property='figure'),
332
- Output(component_id='scatter-plot_db3-7', component_property='figure'),
333
- Output(component_id='scatter-plot_db3-8', component_property='figure'),
334
- Output(component_id='scatter-plot_db3-9', component_property='figure'),
335
- Output(component_id='scatter-plot_db3-10', component_property='figure'),
336
- Output(component_id='scatter-plot_db3-11', component_property='figure'),
337
- Output(component_id='scatter-plot_db3-12', component_property='figure'),
338
- Output(component_id='my-graph_db32', component_property='figure'),
339
  Input(component_id='dpdn2', component_property='value'),
340
  Input(component_id='dpdn3', component_property='value'),
341
  Input(component_id='dpdn4', component_property='value'),
342
  Input(component_id='dpdn5', component_property='value'),
343
  Input(component_id='dpdn6', component_property='value'),
344
  Input(component_id='dpdn7', component_property='value'),
345
- Input(component_id='range-slider_db3-1', component_property='value'),
346
- Input(component_id='range-slider_db3-2', component_property='value'),
347
- Input(component_id='range-slider_db3-3', component_property='value'),
348
 
349
  )
350
 
351
- 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,
352
  batch_chosen = df[col_chosen].unique().to_list()
353
  dff = df.filter(
354
- (pl.col(col_chosen).cast(str).is_in(batch_chosen)) &
355
- (pl.col(col_features) >= range_value_1[0]) &
356
- (pl.col(col_features) <= range_value_1[1]) &
357
- (pl.col(col_counts) >= range_value_2[0]) &
358
- (pl.col(col_counts) <= range_value_2[1]) &
359
- (pl.col(col_mt) >= range_value_3[0]) &
360
- (pl.col(col_mt) <= range_value_3[1])
361
  )
362
-
363
- #Drop categories that are not in the filtered data
364
- dff = dff.with_columns(dff[col_chosen].cast(pl.Categorical))
365
-
366
- dff = dff.sort(col_chosen)
367
-
368
- # Plot figures
369
- fig_violin_db3 = px.violin(data_frame=dff, x=col_chosen, y=col_features, box=True, points="all",
370
- color=col_chosen, hover_name=col_chosen,template="seaborn")
371
-
372
- # Cache commonly used subexpressions
373
- total_count = pl.lit(len(dff))
374
- category_counts = dff.group_by(col_chosen).agg(pl.col(col_chosen).count().alias("count"))
375
- category_counts = category_counts.with_columns(((pl.col("count") / total_count * 100).round(decimals=2)).alias("normalized_count"))
376
-
377
- # Sort the dataframe
378
- #category_counts = category_counts.sort(col_chosen) does not work check if the names are different ...
379
-
380
- # Display the result
381
- total_cells = total_count # Calculate total number of cells
382
- pie_title = f'Percentage of Total Cells: {total_cells}' # Include total cells in the title
383
 
384
  # Calculate the mean expression
385
 
@@ -391,9 +181,9 @@ def update_graph_and_pie_chart(col_chosen, s_chosen, g2m_chosen, condition1_chos
391
 
392
  # Melt wide format DataFrame into long format
393
  dff_long = dff_pre.melt(id_vars=col_chosen, variable_name="Gene", value_name="Mean expression")
394
-
395
  # Calculate the mean expression levels for each gene in each region
396
- expression_means = dff_long.lazy().group_by([col_chosen, "Gene"]).agg(pl.mean("Mean expression")).collect()
397
 
398
  # Calculate the percentage total expressed
399
  dff_long1 = dff_pre.melt(id_vars=col_chosen, variable_name="Gene")#.group_by(pl.all()).agg(pl.len())
@@ -412,82 +202,55 @@ def update_graph_and_pie_chart(col_chosen, s_chosen, g2m_chosen, condition1_chos
412
  dff_5 = dff_5.select(pl.col(col_chosen,"Gene","percentage"))
413
 
414
  # Final part to join the percentage expressed and mean expression levels
415
- # TO DO
416
  expression_means = expression_means.join(dff_5, on=[col_chosen,"Gene"], how="inner")
417
-
418
- # Order the dataframe on ascending categories
419
- expression_means = expression_means.sort(col_chosen, descending=True)
420
-
421
- #expression_means = expression_means.select(["batch", "Gene", "Expression"] + condition3_chosen)
422
- category_counts = category_counts.sort(col_chosen)
423
-
424
- fig_pie_db3 = px.pie(category_counts, values="normalized_count", names=col_chosen, labels=col_chosen, hole=.3, title=pie_title, template="seaborn")
425
-
426
- #labels = category_counts[col_chosen].to_list()
427
- #values = category_counts["normalized_count"].to_list()
428
-
429
- # Create the scatter plots
430
- fig_scatter_db3 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_chosen,
431
- labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
432
- hover_name='batch',template="seaborn")
433
-
434
- fig_scatter_db3_2 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_mt,
435
- labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
436
- hover_name='batch',template="seaborn")
437
-
438
- fig_scatter_db3_3 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_features,
439
- labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
440
- hover_name='batch',template="seaborn")
441
-
442
-
443
- fig_scatter_db3_4 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_counts,
444
- labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
445
- hover_name='batch',template="seaborn")
446
 
447
- fig_scatter_db3_5 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=s_chosen,
448
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
449
- hover_name='batch', title="S-cycle gene:",template="seaborn")
450
 
451
- fig_scatter_db3_6 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=g2m_chosen,
452
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
453
- hover_name='batch', title="G2M-cycle gene:",template="seaborn")
454
 
455
- fig_scatter_db3_7 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="S_score",
456
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
457
- hover_name='batch', title="S score:",template="seaborn")
458
 
459
- fig_scatter_db3_8 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="G2M_score",
460
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
461
- hover_name='batch', title="G2M score:",template="seaborn")
462
 
463
  # Sort values of custom in-between
464
  dff = dff.sort(condition1_chosen)
465
 
466
- fig_scatter_db3_9 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition1_chosen,
467
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
468
- hover_name='batch',template="seaborn")
 
 
469
 
470
- fig_scatter_db3_10 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition2_chosen,
471
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
472
- hover_name='batch',template="seaborn")
473
 
474
- fig_scatter_db3_11 = px.scatter(data_frame=dff, x=condition1_chosen, y=condition2_chosen, color=condition1_chosen,
475
  #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
476
- hover_name='batch',template="seaborn")
 
 
 
 
 
 
 
 
 
 
 
 
477
 
478
- fig_scatter_db3_12 = px.scatter(data_frame=expression_means, x="Gene", y=col_chosen, color="Mean expression",
479
- size="percentage", size_max = 20,
480
- #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
481
- hover_name=col_chosen,template="seaborn")
482
-
483
- fig_violin_db32 = px.violin(data_frame=dff, x=condition1_chosen, y=condition2_chosen, box=True, points="all",
484
- color=condition1_chosen, hover_name=condition1_chosen,template="seaborn")
485
-
486
-
487
- return fig_violin_db3, fig_pie_db3, fig_scatter_db3, fig_scatter_db3_2, fig_scatter_db3_3, fig_scatter_db3_4, fig_scatter_db3_5, fig_scatter_db3_6, fig_scatter_db3_7, fig_scatter_db3_8, fig_scatter_db3_9, fig_scatter_db3_10, fig_scatter_db3_11, fig_scatter_db3_12, fig_violin_db32
488
 
489
- # Set http://localhost:5000/ in web browser
490
- # Now create your regular FASTAPI application
491
 
492
- #if __name__ == '__main__':
493
- # app.run_server(debug=False, use_reloader=False, host='0.0.0.0', port=5000) #
 
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
 
17
+ dataset = "dataaniridia/integrated/separate/DLC_3D10WT2W12_clusres_scVI_polars"
18
 
19
  # Set custom resolution for plots:
20
  config_fig = {
 
46
  col_features = config.get("col_features")
47
  col_counts = config.get("col_counts")
48
  col_mt = config.get("col_mt")
49
+ interesting_genes = ["LIN28A", "KRT8", "ABCG2", "S100A9", "COL1A2", "AQP1", "LUM", "TEK", "PAX6", "PMEL"]
50
 
51
  #filepath = f"az://{path_parquet}"
52
 
53
+ storage_options={'account_name': AZURE_STORAGE_ACCOUNT, 'account_key': AZURE_STORAGE_ACCESS_KEY} #,'anon': False
54
  #azfs = AzureBlobFileSystem(**storage_options )
55
 
56
  # Load in multiple dataframes
57
+ df = pl.scan_parquet(f"az://{dataset}.parquet", storage_options=storage_options).collect()
58
 
59
+ # Create the second tab content with scatter-plot_dbw12-5 and scatter-plot_dbw12-6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  tab2_content = html.Div([
61
  html.Div([
62
  html.Label("S-cycle genes"),
63
  dcc.Dropdown(id='dpdn3', value="MCM5", multi=False,
64
+ options=["MCM5","PCNA","TYMS","FEN1","MCM2","MCM4","RRM1","UNG","GINS2","MCM6","CDCA7","DTL",
65
+ "PRIM1","UHRF1","HELLS","RFC2","RPA2","NASP","RAD51AP1","GMNN","WDR76","SLBP","CCNE2","UBR7",
66
+ "POLD3","MSH2","ATAD2","RAD51","RRM2","CDC45","CDC6","EXO1","TIPIN","DSCC1","BLM","CASP8AP2",
67
+ "USP1","CLSPN","POLA1","CHAF1B","BRIP1","E2F8"]),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  html.Label("G2M-cycle genes"),
69
  dcc.Dropdown(id='dpdn4', value="TOP2A", multi=False,
70
+ options=["HMGB2","CDK1","NUSAP1","UBE2C","BIRC5","TPX2","TOP2A","NDC80","CKS2","NUF2","CKS1B","MKI67",
71
+ "TMPO","CENPF","TACC3","SMC4","CCNB2","CKAP2L","CKAP2","AURKB","BUB1","KIF11","ANP32E","TUBB4B",
72
+ "GTSE1","KIF20B","HJURP","CDCA3","CDC20","TTK","CDC25C","KIF2C","RANGAP1","NCAPD2","DLGAP5","CDCA2",
73
+ "CDCA8","ECT2","KIF23","HMMR","AURKA","PSRC1","ANLN","LBR","CKAP5","CENPE","CTCF","NEK2","G2E3",
74
+ "GAS2L3","CBX5","CENPA"]),
75
  ]),
76
  html.Div([
77
+ dcc.Graph(id='scatter-plot_dbw12-5', figure={}, className='three columns',config=config_fig)
78
  ]),
79
  html.Div([
80
+ dcc.Graph(id='scatter-plot_dbw12-6', figure={}, className='three columns',config=config_fig)
81
  ]),
82
  html.Div([
83
+ dcc.Graph(id='scatter-plot_dbw12-7', figure={}, className='three columns',config=config_fig)
84
  ]),
85
  html.Div([
86
+ dcc.Graph(id='scatter-plot_dbw12-8', figure={}, className='three columns',config=config_fig)
87
  ]),
88
  ])
89
 
90
+ # Create the second tab content with scatter-plot_dbw12-5 and scatter-plot_dbw12-6
91
  tab3_content = html.Div([
92
  html.Div([
93
  html.Label("UMAP condition 1"),
94
+ dcc.Dropdown(id='dpdn5', value="sample", multi=False,
95
  options=df.columns),
96
  html.Label("UMAP condition 2"),
97
+ dcc.Dropdown(id='dpdn6', value="PAX6", multi=False,
98
  options=df.columns),
99
  html.Div([
100
+ dcc.Graph(id='scatter-plot_dbw12-9', figure={}, className='four columns', hoverData=None ,config=config_fig)
101
  ]),
102
  html.Div([
103
+ dcc.Graph(id='scatter-plot_dbw12-10', figure={}, className='four columns', hoverData=None, config=config_fig)
104
  ]),
105
  html.Div([
106
+ dcc.Graph(id='scatter-plot_dbw12-11', figure={}, className='four columns',config=config_fig)
107
  ]),
108
  html.Div([
109
+ dcc.Graph(id='my-graph_dbw122', figure={}, clickData=None, hoverData=None,
110
  className='four columns',config=config_fig
111
  )
112
  ]),
113
  ]),
114
  ])
 
 
 
 
115
 
116
  tab4_content = html.Div([
117
+ html.Label("Column chosen"),
118
+ dcc.Dropdown(id='dpdn2', value="leiden_res_0.03", multi=False,
119
+ options=df.columns),
120
  html.Div([
121
  html.Label("Multi gene"),
122
+ dcc.Dropdown(id='dpdn7', value=interesting_genes, multi=True,
 
 
 
123
  options=df.columns),
124
  ]),
125
  html.Div([
126
+ dcc.Graph(id='scatter-plot_dbw12-12', figure={}, className='row',style={'width': '100vh', 'height': '90vh'})
127
  ]),
128
  ])
129
 
 
134
  'font-size': '100%',
135
  'height': 50}, value='tab1',children=[
136
  #dcc.Tab(label='Dataset', value='tab0', children=tab0_content),
137
+ #dcc.Tab(label='QC', value='tab1', children=tab1_content),
138
+ dcc.Tab(label='UMAP visualisation', value='tab3', children=tab3_content),
 
139
  dcc.Tab(label='Multi dot', value='tab4', children=tab4_content),
140
+ dcc.Tab(label='Cell cycle', value='tab2', children=tab2_content),
141
  ]),
142
  ])
143
 
 
144
  @callback(
145
+ Output(component_id='scatter-plot_dbw12-5', component_property='figure'),
146
+ Output(component_id='scatter-plot_dbw12-6', component_property='figure'),
147
+ Output(component_id='scatter-plot_dbw12-7', component_property='figure'),
148
+ Output(component_id='scatter-plot_dbw12-8', component_property='figure'),
149
+ Output(component_id='scatter-plot_dbw12-9', component_property='figure'),
150
+ Output(component_id='scatter-plot_dbw12-10', component_property='figure'),
151
+ Output(component_id='scatter-plot_dbw12-11', component_property='figure'),
152
+ Output(component_id='scatter-plot_dbw12-12', component_property='figure'),
153
+ Output(component_id='my-graph_dbw122', component_property='figure'),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  Input(component_id='dpdn2', component_property='value'),
155
  Input(component_id='dpdn3', component_property='value'),
156
  Input(component_id='dpdn4', component_property='value'),
157
  Input(component_id='dpdn5', component_property='value'),
158
  Input(component_id='dpdn6', component_property='value'),
159
  Input(component_id='dpdn7', component_property='value'),
 
 
 
160
 
161
  )
162
 
163
+ 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,
164
  batch_chosen = df[col_chosen].unique().to_list()
165
  dff = df.filter(
166
+ (pl.col(col_chosen).cast(str).is_in(batch_chosen)) #&
 
 
 
 
 
 
167
  )
168
+ # Select ordering of plots
169
+ if condition1_chosen == "integrated_cell_states":
170
+ cat_ord= {condition1_chosen: natsorted(dff[condition1_chosen].unique())}
171
+ else:
172
+ cat_ord= {condition1_chosen: natsorted(dff[condition1_chosen].unique())}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
  # Calculate the mean expression
175
 
 
181
 
182
  # Melt wide format DataFrame into long format
183
  dff_long = dff_pre.melt(id_vars=col_chosen, variable_name="Gene", value_name="Mean expression")
184
+
185
  # Calculate the mean expression levels for each gene in each region
186
+ expression_means = dff_long.lazy().group_by([col_chosen, "Gene"]).agg(pl.mean("Mean expression")).collect() #
187
 
188
  # Calculate the percentage total expressed
189
  dff_long1 = dff_pre.melt(id_vars=col_chosen, variable_name="Gene")#.group_by(pl.all()).agg(pl.len())
 
202
  dff_5 = dff_5.select(pl.col(col_chosen,"Gene","percentage"))
203
 
204
  # Final part to join the percentage expressed and mean expression levels
 
205
  expression_means = expression_means.join(dff_5, on=[col_chosen,"Gene"], how="inner")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
 
207
+ fig_scatter_dbw12_5 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=s_chosen,
208
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
209
+ hover_name=None, title="S-cycle gene:",template="seaborn")
210
 
211
+ fig_scatter_dbw12_6 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=g2m_chosen,
212
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
213
+ hover_name='sample', title="G2M-cycle gene:",template="seaborn")
214
 
215
+ fig_scatter_dbw12_7 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="S_score",
216
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
217
+ hover_name='sample', title="S score:",template="seaborn")
218
 
219
+ fig_scatter_dbw12_8 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="G2M_score",
220
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
221
+ hover_name='sample', title="G2M score:",template="seaborn")
222
 
223
  # Sort values of custom in-between
224
  dff = dff.sort(condition1_chosen)
225
 
226
+ fig_scatter_dbw12_9 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition1_chosen,
227
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
228
+ hover_name=None,hover_data = None, template="seaborn",category_orders=cat_ord)
229
+ fig_scatter_dbw12_9.update_traces(hoverinfo='none', hovertemplate=None)
230
+ fig_scatter_dbw12_9.update_layout(hovermode=False)
231
 
232
+ fig_scatter_dbw12_10 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition2_chosen,
233
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
234
+ hover_name='sample',template="seaborn")
235
 
236
+ fig_scatter_dbw12_11 = px.scatter(data_frame=dff, x=condition1_chosen, y=condition2_chosen, color=condition1_chosen,
237
  #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
238
+ hover_name='sample',template="seaborn",category_orders=cat_ord)
239
+
240
+ # Reorder categories on natural sorting or on the integrated cell state order of the paper
241
+ if col_chosen == "integrated_cell_states":
242
+ fig_scatter_dbw12_12 = px.scatter(data_frame=expression_means, x="Gene", y=col_chosen, color="Mean expression",
243
+ size="percentage", size_max = 20,
244
+ #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
245
+ hover_name=col_chosen,template="seaborn",category_orders={col_chosen: natsorted(expression_means[col_chosen].unique()),"Gene": condition3_chosen})
246
+ else:
247
+ fig_scatter_dbw12_12 = px.scatter(data_frame=expression_means, x="Gene", y=col_chosen, color="Mean expression",
248
+ size="percentage", size_max = 20,
249
+ #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
250
+ hover_name=col_chosen,template="seaborn",category_orders={col_chosen: natsorted(expression_means[col_chosen].unique()),"Gene": condition3_chosen})
251
 
252
+ fig_violin_dbw122 = px.violin(data_frame=dff, x=condition1_chosen, y=condition2_chosen, box=True, points="all",
253
+ color=condition1_chosen, hover_name=condition1_chosen,template="seaborn",category_orders=cat_ord)
 
 
 
 
 
 
 
 
254
 
 
 
255
 
256
+ return fig_scatter_dbw12_5, fig_scatter_dbw12_6, fig_scatter_dbw12_7, fig_scatter_dbw12_8, fig_scatter_dbw12_9, fig_scatter_dbw12_10, fig_scatter_dbw12_11, fig_scatter_dbw12_12, fig_violin_dbw122 #fig_violin_dbw12, fig_pie_dbw12, fig_scatter_dbw12, fig_scatter_dbw12_2, fig_scatter_dbw12_3, fig_scatter_dbw12_4,