Arts-of-coding commited on
Commit
8cefd09
·
verified ·
1 Parent(s): c891b73

Update pages/integratedsuture.py

Browse files
Files changed (1) hide show
  1. pages/integratedsuture.py +73 -266
pages/integratedsuture.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 = "datasuture/integrated/sc_liu_suture_integrated_processed"
17
 
18
  # Set custom resolution for plots:
19
  config_fig = {
@@ -54,114 +55,11 @@ storage_options={'account_name': AZURE_STORAGE_ACCOUNT, 'account_key': AZURE_STO
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-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-1', type='number', value=min_value, debounce=True),
122
- dcc.Input(id='max-slider-1', type='number', value=max_value, debounce=True),
123
- html.Label("Total Counts"),
124
- dcc.RangeSlider(
125
- id='range-slider-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-2', type='number', value=min_value_2, debounce=True),
131
- dcc.Input(id='max-slider-2', type='number', value=max_value_2, debounce=True),
132
- html.Label("Percent Mitochondrial Genes"),
133
- dcc.RangeSlider(
134
- id='range-slider-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-3', type='number', value=min_value_3, debounce=True),
141
- dcc.Input(id='max-slider-3', type='number', value=max_value_3, debounce=True),
142
- html.Div([
143
- dcc.Graph(id='pie-graph', figure={}, className='four columns',config=config_fig),
144
- dcc.Graph(id='my-graph', figure={}, clickData=None, hoverData=None,
145
- className='four columns',config=config_fig
146
- ),
147
- dcc.Graph(id='scatter-plot', figure={}, className='four columns',config=config_fig)
148
- ]),
149
- html.Div([
150
- dcc.Graph(id='scatter-plot-2', figure={}, className='four columns',config=config_fig)
151
- ]),
152
- html.Div([
153
- dcc.Graph(id='scatter-plot-3', figure={}, className='four columns',config=config_fig)
154
- ]),
155
- html.Div([
156
- dcc.Graph(id='scatter-plot-4', figure={}, className='four columns',config=config_fig)
157
- ]),
158
- ])
159
-
160
- # Create the second tab content with scatter-plot-5 and scatter-plot-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",
@@ -208,7 +106,7 @@ tab2_content = html.Div([
208
  "Cdca7"
209
  ]),
210
  html.Label("G2M-cycle genes"),
211
- dcc.Dropdown(id='dpdn4', value="Top2a", multi=False,
212
  options=[
213
  "Ube2c",
214
  "Lbr",
@@ -266,57 +164,56 @@ tab2_content = html.Div([
266
  ]),
267
  ]),
268
  html.Div([
269
- dcc.Graph(id='scatter-plot-5', figure={}, className='three columns',config=config_fig)
270
  ]),
271
  html.Div([
272
- dcc.Graph(id='scatter-plot-6', figure={}, className='three columns',config=config_fig)
273
  ]),
274
  html.Div([
275
- dcc.Graph(id='scatter-plot-7', figure={}, className='three columns',config=config_fig)
276
  ]),
277
  html.Div([
278
- dcc.Graph(id='scatter-plot-8', figure={}, className='three columns',config=config_fig)
279
  ]),
280
  ])
281
 
282
- # Create the second tab content with scatter-plot-5 and scatter-plot-6
283
  tab3_content = html.Div([
284
  html.Div([
285
  html.Label("UMAP condition 1"),
286
- dcc.Dropdown(id='dpdn5', value="batch", multi=False,
287
  options=df.columns),
288
  html.Label("UMAP condition 2"),
289
- dcc.Dropdown(id='dpdn6', value="n_genes_by_counts", multi=False,
290
  options=df.columns),
291
  html.Div([
292
- dcc.Graph(id='scatter-plot-9', figure={}, className='four columns',config=config_fig)
293
  ]),
294
  html.Div([
295
- dcc.Graph(id='scatter-plot-10', figure={}, className='four columns',config=config_fig)
296
  ]),
297
  html.Div([
298
- dcc.Graph(id='scatter-plot-11', figure={}, className='four columns',config=config_fig)
299
  ]),
300
  html.Div([
301
- dcc.Graph(id='my-graph2', figure={}, clickData=None, hoverData=None,
302
  className='four columns',config=config_fig
303
  )
304
  ]),
305
  ]),
306
  ])
307
- # html.Div([
308
- # dcc.Graph(id='scatter-plot-12', figure={}, className='four columns',config=config_fig)
309
- # ]),
310
-
311
 
312
  tab4_content = html.Div([
 
 
 
313
  html.Div([
314
  html.Label("Multi gene"),
315
  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,
316
  options=df.columns),
317
  ]),
318
  html.Div([
319
- dcc.Graph(id='scatter-plot-12', figure={}, className='row',style={'width': '100vh', 'height': '90vh'}), # px)
320
  ]),
321
  ])
322
 
@@ -327,105 +224,42 @@ layout = html.Div([
327
  'font-size': '100%',
328
  'height': 50}, value='tab1',children=[
329
  #dcc.Tab(label='Dataset', value='tab0', children=tab0_content),
330
- dcc.Tab(label='QC', value='tab1', children=tab1_content),
331
- dcc.Tab(label='Cell cycle', value='tab2', children=tab2_content),
332
- dcc.Tab(label='Custom', value='tab3', children=tab3_content),
333
  dcc.Tab(label='Multi dot', value='tab4', children=tab4_content),
 
334
  ]),
335
  ])
336
 
337
- # Define the circular callback
338
  @callback(
339
- Output("min-slider-1", "value"),
340
- Output("max-slider-1", "value"),
341
- Output("min-slider-2", "value"),
342
- Output("max-slider-2", "value"),
343
- Output("min-slider-3", "value"),
344
- Output("max-slider-3", "value"),
345
- Input("min-slider-1", "value"),
346
- Input("max-slider-1", "value"),
347
- Input("min-slider-2", "value"),
348
- Input("max-slider-2", "value"),
349
- Input("min-slider-3", "value"),
350
- Input("max-slider-3", "value"),
351
- )
352
- def circular_callback(min_1, max_1, min_2, max_2, min_3, max_3):
353
- return min_1, max_1, min_2, max_2, min_3, max_3
354
-
355
- @callback(
356
- Output('range-slider-1', 'value'),
357
- Output('range-slider-2', 'value'),
358
- Output('range-slider-3', 'value'),
359
- Input('min-slider-1', 'value'),
360
- Input('max-slider-1', 'value'),
361
- Input('min-slider-2', 'value'),
362
- Input('max-slider-2', 'value'),
363
- Input('min-slider-3', 'value'),
364
- Input('max-slider-3', 'value'),
365
- )
366
- def update_slider_values(min_1, max_1, min_2, max_2, min_3, max_3):
367
- return [min_1, max_1], [min_2, max_2], [min_3, max_3]
368
-
369
- @callback(
370
- Output(component_id='my-graph', component_property='figure'),
371
- Output(component_id='pie-graph', component_property='figure'),
372
- Output(component_id='scatter-plot', component_property='figure'),
373
- Output(component_id='scatter-plot-2', component_property='figure'),
374
- Output(component_id='scatter-plot-3', component_property='figure'),
375
- Output(component_id='scatter-plot-4', component_property='figure'), # Add this new scatter plot
376
- Output(component_id='scatter-plot-5', component_property='figure'),
377
- Output(component_id='scatter-plot-6', component_property='figure'),
378
- Output(component_id='scatter-plot-7', component_property='figure'),
379
- Output(component_id='scatter-plot-8', component_property='figure'),
380
- Output(component_id='scatter-plot-9', component_property='figure'),
381
- Output(component_id='scatter-plot-10', component_property='figure'),
382
- Output(component_id='scatter-plot-11', component_property='figure'),
383
- Output(component_id='scatter-plot-12', component_property='figure'),
384
- Output(component_id='my-graph2', component_property='figure'),
385
  Input(component_id='dpdn2', component_property='value'),
386
  Input(component_id='dpdn3', component_property='value'),
387
  Input(component_id='dpdn4', component_property='value'),
388
  Input(component_id='dpdn5', component_property='value'),
389
  Input(component_id='dpdn6', component_property='value'),
390
  Input(component_id='dpdn7', component_property='value'),
391
- Input(component_id='range-slider-1', component_property='value'),
392
- Input(component_id='range-slider-2', component_property='value'),
393
- Input(component_id='range-slider-3', component_property='value'),
394
 
395
  )
396
 
397
- 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,
398
  batch_chosen = df[col_chosen].unique().to_list()
399
  dff = df.filter(
400
- (pl.col(col_chosen).cast(str).is_in(batch_chosen)) &
401
- (pl.col(col_features) >= range_value_1[0]) &
402
- (pl.col(col_features) <= range_value_1[1]) &
403
- (pl.col(col_counts) >= range_value_2[0]) &
404
- (pl.col(col_counts) <= range_value_2[1]) &
405
- (pl.col(col_mt) >= range_value_3[0]) &
406
- (pl.col(col_mt) <= range_value_3[1])
407
  )
408
-
409
- #Drop categories that are not in the filtered data
410
- dff = dff.with_columns(dff[col_chosen].cast(pl.Categorical))
411
-
412
- dff = dff.sort(col_chosen)
413
-
414
- # Plot figures
415
- fig_violin = px.violin(data_frame=dff, x=col_chosen, y=col_features, box=True, points="all",
416
- color=col_chosen, hover_name=col_chosen,template="seaborn")
417
-
418
- # Cache commonly used subexpressions
419
- total_count = pl.lit(len(dff))
420
- category_counts = dff.group_by(col_chosen).agg(pl.col(col_chosen).count().alias("count"))
421
- category_counts = category_counts.with_columns(((pl.col("count") / total_count * 100).round(decimals=2)).alias("normalized_count"))
422
-
423
- # Sort the dataframe
424
- #category_counts = category_counts.sort(col_chosen) does not work check if the names are different ...
425
-
426
- # Display the result
427
- total_cells = total_count # Calculate total number of cells
428
- pie_title = f'Percentage of Total Cells: {total_cells}' # Include total cells in the title
429
 
430
  # Calculate the mean expression
431
 
@@ -437,9 +271,9 @@ def update_graph_and_pie_chart(col_chosen, s_chosen, g2m_chosen, condition1_chos
437
 
438
  # Melt wide format DataFrame into long format
439
  dff_long = dff_pre.melt(id_vars=col_chosen, variable_name="Gene", value_name="Mean expression")
440
-
441
  # Calculate the mean expression levels for each gene in each region
442
- expression_means = dff_long.lazy().group_by([col_chosen, "Gene"]).agg(pl.mean("Mean expression")).collect()
443
 
444
  # Calculate the percentage total expressed
445
  dff_long1 = dff_pre.melt(id_vars=col_chosen, variable_name="Gene")#.group_by(pl.all()).agg(pl.len())
@@ -458,82 +292,55 @@ def update_graph_and_pie_chart(col_chosen, s_chosen, g2m_chosen, condition1_chos
458
  dff_5 = dff_5.select(pl.col(col_chosen,"Gene","percentage"))
459
 
460
  # Final part to join the percentage expressed and mean expression levels
461
- # TO DO
462
  expression_means = expression_means.join(dff_5, on=[col_chosen,"Gene"], how="inner")
463
-
464
- # Order the dataframe on ascending categories
465
- expression_means = expression_means.sort(col_chosen, descending=True)
466
-
467
- #expression_means = expression_means.select(["batch", "Gene", "Expression"] + condition3_chosen)
468
- category_counts = category_counts.sort(col_chosen)
469
 
470
- fig_pie = px.pie(category_counts, values="normalized_count", names=col_chosen, labels=col_chosen, hole=.3, title=pie_title, template="seaborn")
471
-
472
- #labels = category_counts[col_chosen].to_list()
473
- #values = category_counts["normalized_count"].to_list()
474
-
475
- # Create the scatter plots
476
- fig_scatter = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_chosen,
477
- labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
478
- hover_name='batch',template="seaborn")
479
-
480
- fig_scatter_2 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_mt,
481
- labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
482
- hover_name='batch',template="seaborn")
483
-
484
- fig_scatter_3 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_features,
485
- labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
486
- hover_name='batch',template="seaborn")
487
-
488
-
489
- fig_scatter_4 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_counts,
490
- labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
491
- hover_name='batch',template="seaborn")
492
-
493
- fig_scatter_5 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=s_chosen,
494
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
495
- hover_name='batch', title="S-cycle gene:",template="seaborn")
496
 
497
- fig_scatter_6 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=g2m_chosen,
498
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
499
- hover_name='batch', title="G2M-cycle gene:",template="seaborn")
500
 
501
- fig_scatter_7 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="S_score",
502
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
503
- hover_name='batch', title="S score:",template="seaborn")
504
 
505
- fig_scatter_8 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="G2M_score",
506
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
507
- hover_name='batch', title="G2M score:",template="seaborn")
508
 
509
  # Sort values of custom in-between
510
  dff = dff.sort(condition1_chosen)
511
 
512
- fig_scatter_9 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition1_chosen,
513
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
514
- hover_name='batch',template="seaborn")
 
 
515
 
516
- fig_scatter_10 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition2_chosen,
517
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
518
- hover_name='batch',template="seaborn")
519
-
520
- fig_scatter_11 = px.scatter(data_frame=dff, x=condition1_chosen, y=condition2_chosen, color=condition1_chosen,
521
- #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
522
- hover_name='batch',template="seaborn")
523
 
524
- fig_scatter_12 = px.scatter(data_frame=expression_means, x="Gene", y=col_chosen, color="Mean expression",
525
- size="percentage", size_max = 20,
526
  #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
527
- hover_name=col_chosen,template="seaborn")
 
 
 
 
 
 
 
 
 
 
 
 
528
 
529
- fig_violin2 = px.violin(data_frame=dff, x=condition1_chosen, y=condition2_chosen, box=True, points="all",
530
- color=condition1_chosen, hover_name=condition1_chosen,template="seaborn")
531
-
532
-
533
- return fig_violin, fig_pie, fig_scatter, fig_scatter_2, fig_scatter_3, fig_scatter_4, fig_scatter_5, fig_scatter_6, fig_scatter_7, fig_scatter_8, fig_scatter_9, fig_scatter_10, fig_scatter_11, fig_scatter_12, fig_violin2
534
 
535
- # Set http://localhost:5000/ in web browser
536
- # Now create your regular FASTAPI application
537
 
538
- #if __name__ == '__main__':
539
- # 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 = "cornea_v1_umap_clusres_scVI_polars"
18
 
19
  # Set custom resolution for plots:
20
  config_fig = {
 
55
  # Load in multiple dataframes
56
  df = pl.read_parquet(f"az://{dataset}.parquet", storage_options=storage_options)
57
 
58
+ # Create the second tab content with scatter-plot_db4-5 and scatter-plot_db4-6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  tab2_content = html.Div([
60
  html.Div([
61
  html.Label("S-cycle genes"),
62
+ dcc.Dropdown(id='dpdn3', value="MCM5", multi=False,
63
  options=[
64
  "Cdc45",
65
  "Uhrf1",
 
106
  "Cdca7"
107
  ]),
108
  html.Label("G2M-cycle genes"),
109
+ dcc.Dropdown(id='dpdn4', value="TOP2A", multi=False,
110
  options=[
111
  "Ube2c",
112
  "Lbr",
 
164
  ]),
165
  ]),
166
  html.Div([
167
+ dcc.Graph(id='scatter-plot_db4-5', figure={}, className='three columns',config=config_fig)
168
  ]),
169
  html.Div([
170
+ dcc.Graph(id='scatter-plot_db4-6', figure={}, className='three columns',config=config_fig)
171
  ]),
172
  html.Div([
173
+ dcc.Graph(id='scatter-plot_db4-7', figure={}, className='three columns',config=config_fig)
174
  ]),
175
  html.Div([
176
+ dcc.Graph(id='scatter-plot_db4-8', figure={}, className='three columns',config=config_fig)
177
  ]),
178
  ])
179
 
180
+ # Create the second tab content with scatter-plot_db4-5 and scatter-plot_db4-6
181
  tab3_content = html.Div([
182
  html.Div([
183
  html.Label("UMAP condition 1"),
184
+ dcc.Dropdown(id='dpdn5', value="studies", 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_db4-9', figure={}, className='four columns', hoverData=None ,config=config_fig)
191
  ]),
192
  html.Div([
193
+ dcc.Graph(id='scatter-plot_db4-10', figure={}, className='four columns', hoverData=None, config=config_fig)
194
  ]),
195
  html.Div([
196
+ dcc.Graph(id='scatter-plot_db4-11', figure={}, className='four columns',config=config_fig)
197
  ]),
198
  html.Div([
199
+ dcc.Graph(id='my-graph_db42', 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="integrated_clusters", multi=False,
209
+ options=df.columns),
210
  html.Div([
211
  html.Label("Multi gene"),
212
  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,
213
  options=df.columns),
214
  ]),
215
  html.Div([
216
+ dcc.Graph(id='scatter-plot_db4-12', figure={}, className='row',style={'width': '100vh', 'height': '90vh'})
217
  ]),
218
  ])
219
 
 
224
  'font-size': '100%',
225
  'height': 50}, value='tab1',children=[
226
  #dcc.Tab(label='Dataset', value='tab0', children=tab0_content),
227
+ #dcc.Tab(label='QC', value='tab1', children=tab1_content),
228
+ dcc.Tab(label='UMAP visualisation', value='tab3', children=tab3_content),
 
229
  dcc.Tab(label='Multi dot', value='tab4', children=tab4_content),
230
+ dcc.Tab(label='Cell cycle', value='tab2', children=tab2_content),
231
  ]),
232
  ])
233
 
 
234
  @callback(
235
+ Output(component_id='scatter-plot_db4-5', component_property='figure'),
236
+ Output(component_id='scatter-plot_db4-6', component_property='figure'),
237
+ Output(component_id='scatter-plot_db4-7', component_property='figure'),
238
+ Output(component_id='scatter-plot_db4-8', component_property='figure'),
239
+ Output(component_id='scatter-plot_db4-9', component_property='figure'),
240
+ Output(component_id='scatter-plot_db4-10', component_property='figure'),
241
+ Output(component_id='scatter-plot_db4-11', component_property='figure'),
242
+ Output(component_id='scatter-plot_db4-12', component_property='figure'),
243
+ Output(component_id='my-graph_db42', component_property='figure'),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  Input(component_id='dpdn2', component_property='value'),
245
  Input(component_id='dpdn3', component_property='value'),
246
  Input(component_id='dpdn4', component_property='value'),
247
  Input(component_id='dpdn5', component_property='value'),
248
  Input(component_id='dpdn6', component_property='value'),
249
  Input(component_id='dpdn7', component_property='value'),
 
 
 
250
 
251
  )
252
 
253
+ 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,
254
  batch_chosen = df[col_chosen].unique().to_list()
255
  dff = df.filter(
256
+ (pl.col(col_chosen).cast(str).is_in(batch_chosen)) #&
 
 
 
 
 
 
257
  )
258
+ # Select ordering of plots
259
+ if condition1_chosen == "integrated_cell_states":
260
+ cat_ord= {condition1_chosen: natsorted(dff[condition1_chosen].unique())}
261
+ else:
262
+ cat_ord= {condition1_chosen: natsorted(dff[condition1_chosen].unique())}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
 
264
  # Calculate the mean expression
265
 
 
271
 
272
  # Melt wide format DataFrame into long format
273
  dff_long = dff_pre.melt(id_vars=col_chosen, variable_name="Gene", value_name="Mean expression")
274
+
275
  # Calculate the mean expression levels for each gene in each region
276
+ expression_means = dff_long.lazy().group_by([col_chosen, "Gene"]).agg(pl.mean("Mean expression")).collect() #
277
 
278
  # Calculate the percentage total expressed
279
  dff_long1 = dff_pre.melt(id_vars=col_chosen, variable_name="Gene")#.group_by(pl.all()).agg(pl.len())
 
292
  dff_5 = dff_5.select(pl.col(col_chosen,"Gene","percentage"))
293
 
294
  # Final part to join the percentage expressed and mean expression levels
 
295
  expression_means = expression_means.join(dff_5, on=[col_chosen,"Gene"], how="inner")
 
 
 
 
 
 
296
 
297
+ fig_scatter_db4_5 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=s_chosen,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
299
+ hover_name=None, title="S-cycle gene:",template="seaborn")
300
 
301
+ fig_scatter_db4_6 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=g2m_chosen,
302
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
303
+ hover_name='studies', title="G2M-cycle gene:",template="seaborn")
304
 
305
+ fig_scatter_db4_7 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="S_score",
306
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
307
+ hover_name='studies', title="S score:",template="seaborn")
308
 
309
+ fig_scatter_db4_8 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="G2M_score",
310
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
311
+ hover_name='studies', title="G2M score:",template="seaborn")
312
 
313
  # Sort values of custom in-between
314
  dff = dff.sort(condition1_chosen)
315
 
316
+ fig_scatter_db4_9 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition1_chosen,
317
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
318
+ hover_name=None,hover_data = None, template="seaborn",category_orders=cat_ord)
319
+ fig_scatter_db4_9.update_traces(hoverinfo='none', hovertemplate=None)
320
+ fig_scatter_db4_9.update_layout(hovermode=False)
321
 
322
+ fig_scatter_db4_10 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition2_chosen,
323
  labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
324
+ hover_name='studies',template="seaborn")
 
 
 
 
325
 
326
+ fig_scatter_db4_11 = px.scatter(data_frame=dff, x=condition1_chosen, y=condition2_chosen, color=condition1_chosen,
 
327
  #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
328
+ hover_name='studies',template="seaborn",category_orders=cat_ord)
329
+
330
+ # Reorder categories on natural sorting or on the integrated cell state order of the paper
331
+ if col_chosen == "integrated_cell_states":
332
+ fig_scatter_db4_12 = px.scatter(data_frame=expression_means, x="Gene", y=col_chosen, color="Mean expression",
333
+ size="percentage", size_max = 20,
334
+ #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
335
+ hover_name=col_chosen,template="seaborn",category_orders={col_chosen: natsorted(expression_means[col_chosen].unique())})
336
+ else:
337
+ fig_scatter_db4_12 = px.scatter(data_frame=expression_means, x="Gene", y=col_chosen, color="Mean expression",
338
+ size="percentage", size_max = 20,
339
+ #labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
340
+ hover_name=col_chosen,template="seaborn",category_orders={col_chosen: natsorted(expression_means[col_chosen].unique()),"Gene": condition3_chosen})
341
 
342
+ fig_violin_db42 = px.violin(data_frame=dff, x=condition1_chosen, y=condition2_chosen, box=True, points="all",
343
+ color=condition1_chosen, hover_name=condition1_chosen,template="seaborn",category_orders=cat_ord)
 
 
 
344
 
 
 
345
 
346
+ return fig_scatter_db4_5, fig_scatter_db4_6, fig_scatter_db4_7, fig_scatter_db4_8, fig_scatter_db4_9, fig_scatter_db4_10, fig_scatter_db4_11, fig_scatter_db4_12, fig_violin_db42