Arts-of-coding commited on
Commit
223b238
·
verified ·
1 Parent(s): 95f8948

Rename pages/dul_suture.py to pages/Suture.py

Browse files
Files changed (1) hide show
  1. pages/{dul_suture.py → Suture.py} +78 -270
pages/{dul_suture.py → Suture.py} RENAMED
@@ -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 = "datasuture/dul/sc_liu_suture_dul"
17
 
18
  # Set custom resolution for plots:
19
  config_fig = {
@@ -48,116 +49,13 @@ 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_db8-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_db8-1', type='number', value=min_value, debounce=True),
122
- dcc.Input(id='max-slider_db8-1', type='number', value=max_value, debounce=True),
123
- html.Label("Total Counts"),
124
- dcc.RangeSlider(
125
- id='range-slider_db8-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_db8-2', type='number', value=min_value_2, debounce=True),
131
- dcc.Input(id='max-slider_db8-2', type='number', value=max_value_2, debounce=True),
132
- html.Label("Percent Mitochondrial Genes"),
133
- dcc.RangeSlider(
134
- id='range-slider_db8-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_db8-3', type='number', value=min_value_3, debounce=True),
141
- dcc.Input(id='max-slider_db8-3', type='number', value=max_value_3, debounce=True),
142
- html.Div([
143
- dcc.Graph(id='pie-graph_db8', figure={}, className='four columns',config=config_fig),
144
- dcc.Graph(id='my-graph_db8', figure={}, clickData=None, hoverData=None,
145
- className='four columns',config=config_fig
146
- ),
147
- dcc.Graph(id='scatter-plot_db8', figure={}, className='four columns',config=config_fig)
148
- ]),
149
- html.Div([
150
- dcc.Graph(id='scatter-plot_db8-2', figure={}, className='four columns',config=config_fig)
151
- ]),
152
- html.Div([
153
- dcc.Graph(id='scatter-plot_db8-3', figure={}, className='four columns',config=config_fig)
154
- ]),
155
- html.Div([
156
- dcc.Graph(id='scatter-plot_db8-4', figure={}, className='four columns',config=config_fig)
157
- ]),
158
- ])
159
-
160
- # Create the second tab content with scatter-plot_db8-5 and scatter-plot_db8-6
161
  tab2_content = html.Div([
162
  html.Div([
163
  html.Label("S-cycle genes"),
@@ -264,60 +162,62 @@ tab2_content = html.Div([
264
  "Psrc1",
265
  "Gas2l3"
266
  ]),
267
-
268
  ]),
269
  html.Div([
270
- dcc.Graph(id='scatter-plot_db8-5', figure={}, className='three columns',config=config_fig)
271
  ]),
272
  html.Div([
273
- dcc.Graph(id='scatter-plot_db8-6', figure={}, className='three columns',config=config_fig)
274
  ]),
275
  html.Div([
276
- dcc.Graph(id='scatter-plot_db8-7', figure={}, className='three columns',config=config_fig)
277
  ]),
278
  html.Div([
279
- dcc.Graph(id='scatter-plot_db8-8', figure={}, className='three columns',config=config_fig)
280
  ]),
281
  ])
282
 
283
- # Create the second tab content with scatter-plot_db8-5 and scatter-plot_db8-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_db8-9', figure={}, className='four columns',config=config_fig)
294
  ]),
295
  html.Div([
296
- dcc.Graph(id='scatter-plot_db8-10', figure={}, className='four columns',config=config_fig)
297
  ]),
298
  html.Div([
299
- dcc.Graph(id='scatter-plot_db8-11', figure={}, className='four columns',config=config_fig)
300
  ]),
301
  html.Div([
302
- dcc.Graph(id='my-graph_db82', 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_db8-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_db8-12', figure={}, className='row',style={'width': '100vh', 'height': '90vh'}), # px)
321
  ]),
322
  ])
323
 
@@ -328,107 +228,42 @@ layout = html.Div([
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_db8-1", "value"),
341
- Output("max-slider_db8-1", "value"),
342
- Output("min-slider_db8-2", "value"),
343
- Output("max-slider_db8-2", "value"),
344
- Output("min-slider_db8-3", "value"),
345
- Output("max-slider_db8-3", "value"),
346
- Input("min-slider_db8-1", "value"),
347
- Input("max-slider_db8-1", "value"),
348
- Input("min-slider_db8-2", "value"),
349
- Input("max-slider_db8-2", "value"),
350
- Input("min-slider_db8-3", "value"),
351
- Input("max-slider_db8-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_db8-1', 'value'),
359
- Output('range-slider_db8-2', 'value'),
360
- Output('range-slider_db8-3', 'value'),
361
- Input('min-slider_db8-1', 'value'),
362
- Input('max-slider_db8-1', 'value'),
363
- Input('min-slider_db8-2', 'value'),
364
- Input('max-slider_db8-2', 'value'),
365
- Input('min-slider_db8-3', 'value'),
366
- Input('max-slider_db8-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_db8', component_property='figure'),
374
- Output(component_id='pie-graph_db8', component_property='figure'),
375
- Output(component_id='scatter-plot_db8', component_property='figure'),
376
- Output(component_id='scatter-plot_db8-2', component_property='figure'),
377
- Output(component_id='scatter-plot_db8-3', component_property='figure'),
378
- Output(component_id='scatter-plot_db8-4', component_property='figure'), # Add this new scatter plot
379
- Output(component_id='scatter-plot_db8-5', component_property='figure'),
380
- Output(component_id='scatter-plot_db8-6', component_property='figure'),
381
- Output(component_id='scatter-plot_db8-7', component_property='figure'),
382
- Output(component_id='scatter-plot_db8-8', component_property='figure'),
383
- Output(component_id='scatter-plot_db8-9', component_property='figure'),
384
- Output(component_id='scatter-plot_db8-10', component_property='figure'),
385
- Output(component_id='scatter-plot_db8-11', component_property='figure'),
386
- Output(component_id='scatter-plot_db8-12', component_property='figure'),
387
- Output(component_id='my-graph_db82', 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_db8-1', component_property='value'),
395
- Input(component_id='range-slider_db8-2', component_property='value'),
396
- Input(component_id='range-slider_db8-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_db8 = 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
 
@@ -440,9 +275,9 @@ def update_graph_and_pie_chart(col_chosen, s_chosen, g2m_chosen, condition1_chos
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())
@@ -461,82 +296,55 @@ def update_graph_and_pie_chart(col_chosen, s_chosen, g2m_chosen, condition1_chos
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_db8 = 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_db8 = 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_db8_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_db8_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_db8_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_db8_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_db8_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_db8_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_db8_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_db8_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_db8_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_db8_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_db8_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_db82 = 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_db8, fig_pie_db8, fig_scatter_db8, fig_scatter_db8_2, fig_scatter_db8_3, fig_scatter_db8_4, fig_scatter_db8_5, fig_scatter_db8_6, fig_scatter_db8_7, fig_scatter_db8_8, fig_scatter_db8_9, fig_scatter_db8_10, fig_scatter_db8_11, fig_scatter_db8_12, fig_violin_db82
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) #
 
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 = "datasuture/pbs/Suture_polars"
18
 
19
  # Set custom resolution for plots:
20
  config_fig = {
 
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
  #azfs = AzureBlobFileSystem(**storage_options )
54
 
55
  # Load in multiple dataframes
56
+ df = pl.scan_parquet(f"az://{dataset}.parquet", storage_options=storage_options).collect()
57
 
58
+ # Create the second tab content with scatter-plot_db0-5 and scatter-plot_db0-6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  tab2_content = html.Div([
60
  html.Div([
61
  html.Label("S-cycle genes"),
 
162
  "Psrc1",
163
  "Gas2l3"
164
  ]),
 
165
  ]),
166
  html.Div([
167
+ dcc.Graph(id='scatter-plot_db0-5', figure={}, className='three columns',config=config_fig)
168
  ]),
169
  html.Div([
170
+ dcc.Graph(id='scatter-plot_db0-6', figure={}, className='three columns',config=config_fig)
171
  ]),
172
  html.Div([
173
+ dcc.Graph(id='scatter-plot_db0-7', figure={}, className='three columns',config=config_fig)
174
  ]),
175
  html.Div([
176
+ dcc.Graph(id='scatter-plot_db0-8', figure={}, className='three columns',config=config_fig)
177
  ]),
178
  ])
179
 
180
+ # Create the second tab content with scatter-plot_db0-5 and scatter-plot_db0-6
181
  tab3_content = html.Div([
182
  html.Div([
183
  html.Label("UMAP condition 1"),
184
+ dcc.Dropdown(id='dpdn5', value="condition", multi=False,
185
  options=df.columns),
186
  html.Label("UMAP condition 2"),
187
+ dcc.Dropdown(id='dpdn6', value="Pax6", multi=False,
188
  options=df.columns),
189
  html.Div([
190
+ dcc.Graph(id='scatter-plot_db0-9', figure={}, className='four columns', hoverData=None ,config=config_fig)
191
  ]),
192
  html.Div([
193
+ dcc.Graph(id='scatter-plot_db0-10', figure={}, className='four columns', hoverData=None, config=config_fig)
194
  ]),
195
  html.Div([
196
+ dcc.Graph(id='scatter-plot_db0-11', figure={}, className='four columns',config=config_fig)
197
  ]),
198
  html.Div([
199
+ dcc.Graph(id='my-graph_db02', figure={}, clickData=None, hoverData=None,
200
  className='four columns',config=config_fig
201
  )
202
  ]),
203
  ]),
204
  ])
 
 
 
 
205
 
206
  tab4_content = html.Div([
207
+ html.Label("Column chosen"),
208
+ dcc.Dropdown(id='dpdn2', value="cell states", multi=False,
209
+ options=df.columns),
210
  html.Div([
211
  html.Label("Multi gene"),
212
+ dcc.Dropdown(id='dpdn7', value=["Pax6","Sox9","Cdk8","Il31ra","Gpha2",
213
+ "Areg","Krt13","Krt19","Psca","Muc20",
214
+ "S100a9","Lama3","Itgb4","Itga6","Thy1","Dcn","Scn7a",
215
+ "Cdh19","Mpz","Ptprc","Cd52","Cd69","Cd86","Rgs5","Des","Myh11","Cd93","Pecam1",
216
+ "Abcg2","Lyve1","Mki67"], multi=True,
217
  options=df.columns),
218
  ]),
219
  html.Div([
220
+ dcc.Graph(id='scatter-plot_db0-12', figure={}, className='row',style={'width': '100vh', 'height': '90vh'})
221
  ]),
222
  ])
223
 
 
228
  'font-size': '100%',
229
  'height': 50}, value='tab1',children=[
230
  #dcc.Tab(label='Dataset', value='tab0', children=tab0_content),
231
+ #dcc.Tab(label='QC', value='tab1', children=tab1_content),
232
+ dcc.Tab(label='UMAP visualisation', value='tab3', children=tab3_content),
 
233
  dcc.Tab(label='Multi dot', value='tab4', children=tab4_content),
234
+ dcc.Tab(label='Cell cycle', value='tab2', children=tab2_content),
235
  ]),
236
  ])
237
 
 
238
  @callback(
239
+ Output(component_id='scatter-plot_db0-5', component_property='figure'),
240
+ Output(component_id='scatter-plot_db0-6', component_property='figure'),
241
+ Output(component_id='scatter-plot_db0-7', component_property='figure'),
242
+ Output(component_id='scatter-plot_db0-8', component_property='figure'),
243
+ Output(component_id='scatter-plot_db0-9', component_property='figure'),
244
+ Output(component_id='scatter-plot_db0-10', component_property='figure'),
245
+ Output(component_id='scatter-plot_db0-11', component_property='figure'),
246
+ Output(component_id='scatter-plot_db0-12', component_property='figure'),
247
+ Output(component_id='my-graph_db02', component_property='figure'),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  Input(component_id='dpdn2', component_property='value'),
249
  Input(component_id='dpdn3', component_property='value'),
250
  Input(component_id='dpdn4', component_property='value'),
251
  Input(component_id='dpdn5', component_property='value'),
252
  Input(component_id='dpdn6', component_property='value'),
253
  Input(component_id='dpdn7', component_property='value'),
 
 
 
254
 
255
  )
256
 
257
+ 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,
258
  batch_chosen = df[col_chosen].unique().to_list()
259
  dff = df.filter(
260
+ (pl.col(col_chosen).cast(str).is_in(batch_chosen)) #&
 
 
 
 
 
 
261
  )
262
+ # Select ordering of plots
263
+ if condition1_chosen == "integrated_cell_states":
264
+ cat_ord= {condition1_chosen: natsorted(dff[condition1_chosen].unique())}
265
+ else:
266
+ cat_ord= {condition1_chosen: natsorted(dff[condition1_chosen].unique())}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
 
268
  # Calculate the mean expression
269
 
 
275
 
276
  # Melt wide format DataFrame into long format
277
  dff_long = dff_pre.melt(id_vars=col_chosen, variable_name="Gene", value_name="Mean expression")
278
+
279
  # Calculate the mean expression levels for each gene in each region
280
+ expression_means = dff_long.lazy().group_by([col_chosen, "Gene"]).agg(pl.mean("Mean expression")).collect() #
281
 
282
  # Calculate the percentage total expressed
283
  dff_long1 = dff_pre.melt(id_vars=col_chosen, variable_name="Gene")#.group_by(pl.all()).agg(pl.len())
 
296
  dff_5 = dff_5.select(pl.col(col_chosen,"Gene","percentage"))
297
 
298
  # Final part to join the percentage expressed and mean expression levels
 
299
  expression_means = expression_means.join(dff_5, on=[col_chosen,"Gene"], how="inner")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
 
301
+ fig_scatter_db0_5 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=s_chosen,
302
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
303
+ hover_name=None, title="S-cycle gene:",template="seaborn")
304
 
305
+ fig_scatter_db0_6 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=g2m_chosen,
306
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
307
+ hover_name='condition', title="G2M-cycle gene:",template="seaborn")
308
 
309
+ fig_scatter_db0_7 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="S_score",
310
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
311
+ hover_name='condition', title="S score:",template="seaborn")
312
 
313
+ fig_scatter_db0_8 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="G2M_score",
314
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
315
+ hover_name='condition', title="G2M score:",template="seaborn")
316
 
317
  # Sort values of custom in-between
318
  dff = dff.sort(condition1_chosen)
319
 
320
+ fig_scatter_db0_9 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition1_chosen,
321
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
322
+ hover_name=None,hover_data = None, template="seaborn",category_orders=cat_ord)
323
+ fig_scatter_db0_9.update_traces(hoverinfo='none', hovertemplate=None)
324
+ fig_scatter_db0_9.update_layout(hovermode=False)
325
 
326
+ fig_scatter_db0_10 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition2_chosen,
327
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
328
+ hover_name='condition',template="seaborn")
329
 
330
+ fig_scatter_db0_11 = px.scatter(data_frame=dff, x=condition1_chosen, y=condition2_chosen, color=condition1_chosen,
331
  #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
332
+ hover_name='condition',template="seaborn",category_orders=cat_ord)
333
+
334
+ # Reorder categories on natural sorting or on the integrated cell state order of the paper
335
+ if col_chosen == "integrated_cell_states":
336
+ fig_scatter_db0_12 = px.scatter(data_frame=expression_means, x="Gene", y=col_chosen, color="Mean expression",
337
+ size="percentage", size_max = 20,
338
+ #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
339
+ hover_name=col_chosen,template="seaborn",category_orders={col_chosen: natsorted(expression_means[col_chosen].unique())})
340
+ else:
341
+ fig_scatter_db0_12 = px.scatter(data_frame=expression_means, x="Gene", y=col_chosen, color="Mean expression",
342
+ size="percentage", size_max = 20,
343
+ #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
344
+ hover_name=col_chosen,template="seaborn",category_orders={col_chosen: natsorted(expression_means[col_chosen].unique()),"Gene": condition3_chosen})
345
 
346
+ fig_violin_db02 = px.violin(data_frame=dff, x=condition1_chosen, y=condition2_chosen, box=True, points="all",
347
+ color=condition1_chosen, hover_name=condition1_chosen,template="seaborn",category_orders=cat_ord)
 
 
 
 
 
 
 
 
348
 
 
 
349
 
350
+ return fig_scatter_db0_5, fig_scatter_db0_6, fig_scatter_db0_7, fig_scatter_db0_8, fig_scatter_db0_9, fig_scatter_db0_10, fig_scatter_db0_11, fig_scatter_db0_12, fig_violin_db02