Spaces:
Sleeping
Sleeping
Update pages/No_suture.py
Browse files- pages/No_suture.py +0 -533
pages/No_suture.py
CHANGED
|
@@ -348,536 +348,3 @@ def update_graph_and_pie_chart(col_chosen, s_chosen, g2m_chosen, condition1_chos
|
|
| 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
|
| 351 |
-
import polars as pl
|
| 352 |
-
import os
|
| 353 |
-
pl.enable_string_cache(False)
|
| 354 |
-
|
| 355 |
-
dash.register_page(__name__, location="sidebar")
|
| 356 |
-
|
| 357 |
-
dataset = "datasuture/ctrl/sc_liu_suture_ctrl"
|
| 358 |
-
|
| 359 |
-
# Set custom resolution for plots:
|
| 360 |
-
config_fig = {
|
| 361 |
-
'toImageButtonOptions': {
|
| 362 |
-
'format': 'svg',
|
| 363 |
-
'filename': 'custom_image',
|
| 364 |
-
'height': 600,
|
| 365 |
-
'width': 700,
|
| 366 |
-
'scale': 1,
|
| 367 |
-
}
|
| 368 |
-
}
|
| 369 |
-
from adlfs import AzureBlobFileSystem
|
| 370 |
-
mountpount=os.environ['AZURE_MOUNT_POINT'],
|
| 371 |
-
AZURE_STORAGE_ACCESS_KEY=os.getenv('AZURE_STORAGE_ACCESS_KEY')
|
| 372 |
-
AZURE_STORAGE_ACCOUNT=os.getenv('AZURE_STORAGE_ACCOUNT')
|
| 373 |
-
|
| 374 |
-
# Load in config file
|
| 375 |
-
config_path = "./data/config.yaml"
|
| 376 |
-
|
| 377 |
-
# Add the read-in data from the yaml file
|
| 378 |
-
def read_config(filename):
|
| 379 |
-
with open(filename, 'r') as yaml_file:
|
| 380 |
-
config = yaml.safe_load(yaml_file)
|
| 381 |
-
return config
|
| 382 |
-
|
| 383 |
-
config = read_config(config_path)
|
| 384 |
-
path_parquet = config.get("path_parquet")
|
| 385 |
-
col_batch = config.get("col_batch")
|
| 386 |
-
col_features = config.get("col_features")
|
| 387 |
-
col_counts = config.get("col_counts")
|
| 388 |
-
col_mt = config.get("col_mt")
|
| 389 |
-
|
| 390 |
-
#filepath = f"az://{path_parquet}"
|
| 391 |
-
|
| 392 |
-
storage_options={'account_name': AZURE_STORAGE_ACCOUNT, 'account_key': AZURE_STORAGE_ACCESS_KEY,'anon': False}
|
| 393 |
-
#azfs = AzureBlobFileSystem(**storage_options )
|
| 394 |
-
|
| 395 |
-
# Load in multiple dataframes
|
| 396 |
-
df = pl.read_parquet(f"az://{dataset}.parquet", storage_options=storage_options)
|
| 397 |
-
|
| 398 |
-
# Setup the app
|
| 399 |
-
#external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
|
| 400 |
-
#app = dash.Dash(__name__, use_pages=True) #, requests_pathname_prefix='/dashboard1/'
|
| 401 |
-
|
| 402 |
-
#df = pl.read_parquet(filepath,storage_options=storage_options)
|
| 403 |
-
#df = pl.DataFrame()
|
| 404 |
-
#abfs = AzureBlobFileSystem(account_name=accountname,account_key=accountkey)
|
| 405 |
-
#df = df.rename({"__index_level_0__": "Unnamed: 0"})
|
| 406 |
-
|
| 407 |
-
#df1 = pl.read_parquet(filepath, storage_options=storage_options)
|
| 408 |
-
|
| 409 |
-
#df2 = pl.read_parquet(f"az://data10xflex/{dataset_chosen}.parquet", storage_options=storage_options)
|
| 410 |
-
|
| 411 |
-
#tab0_content = html.Div([
|
| 412 |
-
# html.Label("Dataset chosen"),
|
| 413 |
-
# dcc.Dropdown(id='dpdn1', value="corg/10xflexcorg_umap_clusres", multi=False,
|
| 414 |
-
# options=["corg/10xflexcorg_umap_clusres","d1011/10xflexd1011_umap_clusres"])
|
| 415 |
-
#])
|
| 416 |
-
|
| 417 |
-
#@app.callback(
|
| 418 |
-
# Input(component_id='dpdn1', component_property='value')
|
| 419 |
-
#)
|
| 420 |
-
|
| 421 |
-
#def update_filepath(dpdn1):
|
| 422 |
-
# global df
|
| 423 |
-
# if str(f"az://data10xflex/{dpdn1}.parquet") != str(filepath):
|
| 424 |
-
# print("not identical filepath, chosing other")
|
| 425 |
-
# df2 = pl.read_parquet(f"az://data10xflex/{dpdn1}.parquet", storage_options=storage_options)
|
| 426 |
-
# df = df2
|
| 427 |
-
# return
|
| 428 |
-
|
| 429 |
-
#df = pl.read_parquet(filepath, storage_options=storage_options)
|
| 430 |
-
min_value = df[col_features].min()
|
| 431 |
-
max_value = df[col_features].max()
|
| 432 |
-
|
| 433 |
-
min_value_2 = df[col_counts].min()
|
| 434 |
-
min_value_2 = round(min_value_2)
|
| 435 |
-
max_value_2 = df[col_counts].max()
|
| 436 |
-
max_value_2 = round(max_value_2)
|
| 437 |
-
|
| 438 |
-
min_value_3 = df[col_mt].min()
|
| 439 |
-
min_value_3 = round(min_value_3, 1)
|
| 440 |
-
max_value_3 = df[col_mt].max()
|
| 441 |
-
max_value_3 = round(max_value_3, 1)
|
| 442 |
-
|
| 443 |
-
# Loads in the conditions specified in the yaml file
|
| 444 |
-
|
| 445 |
-
# Note: Future version perhaps all values from a column in the dataframe of the parquet file
|
| 446 |
-
# Note 2: This could also be a tsv of the categories and own specified colors
|
| 447 |
-
#conditions = df[col_batch].unique().to_list()
|
| 448 |
-
# Create the first tab content
|
| 449 |
-
# Add Sliders for three QC params: N genes by counts, total amount of reads and pct MT reads
|
| 450 |
-
|
| 451 |
-
tab1_content = html.Div([
|
| 452 |
-
html.Label("Column chosen"),
|
| 453 |
-
dcc.Dropdown(id='dpdn2', value="batch", multi=False,
|
| 454 |
-
options=df.columns),
|
| 455 |
-
html.Label("N Genes by Counts"),
|
| 456 |
-
dcc.RangeSlider(
|
| 457 |
-
id='range-slider_db0-1',
|
| 458 |
-
step=250,
|
| 459 |
-
value=[min_value, max_value],
|
| 460 |
-
marks={i: str(i) for i in range(min_value, max_value + 1, 250)},
|
| 461 |
-
),
|
| 462 |
-
dcc.Input(id='min-slider_db0-1', type='number', value=min_value, debounce=True),
|
| 463 |
-
dcc.Input(id='max-slider_db0-1', type='number', value=max_value, debounce=True),
|
| 464 |
-
html.Label("Total Counts"),
|
| 465 |
-
dcc.RangeSlider(
|
| 466 |
-
id='range-slider_db0-2',
|
| 467 |
-
step=7500,
|
| 468 |
-
value=[min_value_2, max_value_2],
|
| 469 |
-
marks={i: str(i) for i in range(min_value_2, max_value_2 + 1, 7500)},
|
| 470 |
-
),
|
| 471 |
-
dcc.Input(id='min-slider_db0-2', type='number', value=min_value_2, debounce=True),
|
| 472 |
-
dcc.Input(id='max-slider_db0-2', type='number', value=max_value_2, debounce=True),
|
| 473 |
-
html.Label("Percent Mitochondrial Genes"),
|
| 474 |
-
dcc.RangeSlider(
|
| 475 |
-
id='range-slider_db0-3',
|
| 476 |
-
step=5,
|
| 477 |
-
min=0,
|
| 478 |
-
max=100,
|
| 479 |
-
value=[min_value_3, max_value_3],
|
| 480 |
-
),
|
| 481 |
-
dcc.Input(id='min-slider_db0-3', type='number', value=min_value_3, debounce=True),
|
| 482 |
-
dcc.Input(id='max-slider_db0-3', type='number', value=max_value_3, debounce=True),
|
| 483 |
-
html.Div([
|
| 484 |
-
dcc.Graph(id='pie-graph_db0', figure={}, className='four columns',config=config_fig),
|
| 485 |
-
dcc.Graph(id='my-graph_db0', figure={}, clickData=None, hoverData=None,
|
| 486 |
-
className='four columns',config=config_fig
|
| 487 |
-
),
|
| 488 |
-
dcc.Graph(id='scatter-plot_db0', figure={}, className='four columns',config=config_fig)
|
| 489 |
-
]),
|
| 490 |
-
html.Div([
|
| 491 |
-
dcc.Graph(id='scatter-plot_db0-2', figure={}, className='four columns',config=config_fig)
|
| 492 |
-
]),
|
| 493 |
-
html.Div([
|
| 494 |
-
dcc.Graph(id='scatter-plot_db0-3', figure={}, className='four columns',config=config_fig)
|
| 495 |
-
]),
|
| 496 |
-
html.Div([
|
| 497 |
-
dcc.Graph(id='scatter-plot_db0-4', figure={}, className='four columns',config=config_fig)
|
| 498 |
-
]),
|
| 499 |
-
])
|
| 500 |
-
|
| 501 |
-
# Create the second tab content with scatter-plot_db0-5 and scatter-plot_db0-6
|
| 502 |
-
tab2_content = html.Div([
|
| 503 |
-
html.Div([
|
| 504 |
-
html.Label("S-cycle genes"),
|
| 505 |
-
dcc.Dropdown(id='dpdn3', value="Mcm5", multi=False,
|
| 506 |
-
options=[
|
| 507 |
-
"Cdc45",
|
| 508 |
-
"Uhrf1",
|
| 509 |
-
"Mcm2",
|
| 510 |
-
"Slbp",
|
| 511 |
-
"Mcm5",
|
| 512 |
-
"Pola1",
|
| 513 |
-
"Gmnn",
|
| 514 |
-
"Cdc6",
|
| 515 |
-
"Rrm2",
|
| 516 |
-
"Atad2",
|
| 517 |
-
"Dscc1",
|
| 518 |
-
"Mcm4",
|
| 519 |
-
"Chaf1b",
|
| 520 |
-
"Rfc2",
|
| 521 |
-
"Msh2",
|
| 522 |
-
"Fen1",
|
| 523 |
-
"Hells",
|
| 524 |
-
"Prim1",
|
| 525 |
-
"Tyms",
|
| 526 |
-
"Mcm6",
|
| 527 |
-
"Wdr76",
|
| 528 |
-
"Rad51",
|
| 529 |
-
"Pcna",
|
| 530 |
-
"Ccne2",
|
| 531 |
-
"Casp8ap2",
|
| 532 |
-
"Usp1",
|
| 533 |
-
"Nasp",
|
| 534 |
-
"Rpa2",
|
| 535 |
-
"Ung",
|
| 536 |
-
"Rad51ap1",
|
| 537 |
-
"Blm",
|
| 538 |
-
"Pold3",
|
| 539 |
-
"Rrm1",
|
| 540 |
-
"Cenpu",
|
| 541 |
-
"Gins2",
|
| 542 |
-
"Tipin",
|
| 543 |
-
"Brip1",
|
| 544 |
-
"Dtl",
|
| 545 |
-
"Exo1",
|
| 546 |
-
"Ubr7",
|
| 547 |
-
"Clspn",
|
| 548 |
-
"E2f8",
|
| 549 |
-
"Cdca7"
|
| 550 |
-
]),
|
| 551 |
-
html.Label("G2M-cycle genes"),
|
| 552 |
-
dcc.Dropdown(id='dpdn4', value="Top2a", multi=False,
|
| 553 |
-
options=[
|
| 554 |
-
"Ube2c",
|
| 555 |
-
"Lbr",
|
| 556 |
-
"Ctcf",
|
| 557 |
-
"Cdc20",
|
| 558 |
-
"Cbx5",
|
| 559 |
-
"Kif11",
|
| 560 |
-
"Anp32e",
|
| 561 |
-
"Birc5",
|
| 562 |
-
"Cdk1",
|
| 563 |
-
"Tmpo",
|
| 564 |
-
"Hmmr",
|
| 565 |
-
"Pimreg",
|
| 566 |
-
"Aurkb",
|
| 567 |
-
"Top2a",
|
| 568 |
-
"Gtse1",
|
| 569 |
-
"Rangap1",
|
| 570 |
-
"Cdca3",
|
| 571 |
-
"Ndc80",
|
| 572 |
-
"Kif20b",
|
| 573 |
-
"Cenpf",
|
| 574 |
-
"Nek2",
|
| 575 |
-
"Nuf2",
|
| 576 |
-
"Nusap1",
|
| 577 |
-
"Bub1",
|
| 578 |
-
"Tpx2",
|
| 579 |
-
"Aurka",
|
| 580 |
-
"Ect2",
|
| 581 |
-
"Cks1b",
|
| 582 |
-
"Kif2c",
|
| 583 |
-
"Cdca8",
|
| 584 |
-
"Cenpa",
|
| 585 |
-
"Mki67",
|
| 586 |
-
"Ccnb2",
|
| 587 |
-
"Kif23",
|
| 588 |
-
"Smc4",
|
| 589 |
-
"G2e3",
|
| 590 |
-
"Tubb4b",
|
| 591 |
-
"Anln",
|
| 592 |
-
"Tacc3",
|
| 593 |
-
"Dlgap5",
|
| 594 |
-
"Ckap2",
|
| 595 |
-
"Ncapd2",
|
| 596 |
-
"Ttk",
|
| 597 |
-
"Ckap5",
|
| 598 |
-
"Cdc25c",
|
| 599 |
-
"Hjurp",
|
| 600 |
-
"Cenpe",
|
| 601 |
-
"Ckap2l",
|
| 602 |
-
"Cdca2",
|
| 603 |
-
"Hmgb2",
|
| 604 |
-
"Cks2",
|
| 605 |
-
"Psrc1",
|
| 606 |
-
"Gas2l3"
|
| 607 |
-
]),
|
| 608 |
-
|
| 609 |
-
]),
|
| 610 |
-
html.Div([
|
| 611 |
-
dcc.Graph(id='scatter-plot_db0-5', figure={}, className='three columns',config=config_fig)
|
| 612 |
-
]),
|
| 613 |
-
html.Div([
|
| 614 |
-
dcc.Graph(id='scatter-plot_db0-6', figure={}, className='three columns',config=config_fig)
|
| 615 |
-
]),
|
| 616 |
-
html.Div([
|
| 617 |
-
dcc.Graph(id='scatter-plot_db0-7', figure={}, className='three columns',config=config_fig)
|
| 618 |
-
]),
|
| 619 |
-
html.Div([
|
| 620 |
-
dcc.Graph(id='scatter-plot_db0-8', figure={}, className='three columns',config=config_fig)
|
| 621 |
-
]),
|
| 622 |
-
])
|
| 623 |
-
|
| 624 |
-
# Create the second tab content with scatter-plot_db0-5 and scatter-plot_db0-6
|
| 625 |
-
tab3_content = html.Div([
|
| 626 |
-
html.Div([
|
| 627 |
-
html.Label("UMAP condition 1"),
|
| 628 |
-
dcc.Dropdown(id='dpdn5', value="batch", multi=False,
|
| 629 |
-
options=df.columns),
|
| 630 |
-
html.Label("UMAP condition 2"),
|
| 631 |
-
dcc.Dropdown(id='dpdn6', value="n_genes_by_counts", multi=False,
|
| 632 |
-
options=df.columns),
|
| 633 |
-
html.Div([
|
| 634 |
-
dcc.Graph(id='scatter-plot_db0-9', figure={}, className='four columns',config=config_fig)
|
| 635 |
-
]),
|
| 636 |
-
html.Div([
|
| 637 |
-
dcc.Graph(id='scatter-plot_db0-10', figure={}, className='four columns',config=config_fig)
|
| 638 |
-
]),
|
| 639 |
-
html.Div([
|
| 640 |
-
dcc.Graph(id='scatter-plot_db0-11', figure={}, className='four columns',config=config_fig)
|
| 641 |
-
]),
|
| 642 |
-
html.Div([
|
| 643 |
-
dcc.Graph(id='my-graph_db02', figure={}, clickData=None, hoverData=None,
|
| 644 |
-
className='four columns',config=config_fig
|
| 645 |
-
)
|
| 646 |
-
]),
|
| 647 |
-
]),
|
| 648 |
-
])
|
| 649 |
-
# html.Div([
|
| 650 |
-
# dcc.Graph(id='scatter-plot_db0-12', figure={}, className='four columns',config=config_fig)
|
| 651 |
-
# ]),
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
tab4_content = html.Div([
|
| 655 |
-
html.Div([
|
| 656 |
-
html.Label("Multi gene"),
|
| 657 |
-
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,
|
| 658 |
-
options=df.columns),
|
| 659 |
-
]),
|
| 660 |
-
html.Div([
|
| 661 |
-
dcc.Graph(id='scatter-plot_db0-12', figure={}, className='row',style={'width': '100vh', 'height': '90vh'}), # px)
|
| 662 |
-
]),
|
| 663 |
-
])
|
| 664 |
-
|
| 665 |
-
# Define the tabs layout
|
| 666 |
-
layout = html.Div([
|
| 667 |
-
html.H1(f'Dataset analysis dashboard: {dataset}'),
|
| 668 |
-
dcc.Tabs(id='tabs', style= {'width': 600,
|
| 669 |
-
'font-size': '100%',
|
| 670 |
-
'height': 50}, value='tab1',children=[
|
| 671 |
-
#dcc.Tab(label='Dataset', value='tab0', children=tab0_content),
|
| 672 |
-
dcc.Tab(label='QC', value='tab1', children=tab1_content),
|
| 673 |
-
dcc.Tab(label='Cell cycle', value='tab2', children=tab2_content),
|
| 674 |
-
dcc.Tab(label='Custom', value='tab3', children=tab3_content),
|
| 675 |
-
dcc.Tab(label='Multi dot', value='tab4', children=tab4_content),
|
| 676 |
-
]),
|
| 677 |
-
])
|
| 678 |
-
|
| 679 |
-
# Define the circular callback
|
| 680 |
-
@callback(
|
| 681 |
-
Output("min-slider_db0-1", "value"),
|
| 682 |
-
Output("max-slider_db0-1", "value"),
|
| 683 |
-
Output("min-slider_db0-2", "value"),
|
| 684 |
-
Output("max-slider_db0-2", "value"),
|
| 685 |
-
Output("min-slider_db0-3", "value"),
|
| 686 |
-
Output("max-slider_db0-3", "value"),
|
| 687 |
-
Input("min-slider_db0-1", "value"),
|
| 688 |
-
Input("max-slider_db0-1", "value"),
|
| 689 |
-
Input("min-slider_db0-2", "value"),
|
| 690 |
-
Input("max-slider_db0-2", "value"),
|
| 691 |
-
Input("min-slider_db0-3", "value"),
|
| 692 |
-
Input("max-slider_db0-3", "value"),
|
| 693 |
-
|
| 694 |
-
)
|
| 695 |
-
def circular_callback(min_1, max_1, min_2, max_2, min_3, max_3):
|
| 696 |
-
return min_1, max_1, min_2, max_2, min_3, max_3
|
| 697 |
-
|
| 698 |
-
@callback(
|
| 699 |
-
Output('range-slider_db0-1', 'value'),
|
| 700 |
-
Output('range-slider_db0-2', 'value'),
|
| 701 |
-
Output('range-slider_db0-3', 'value'),
|
| 702 |
-
Input('min-slider_db0-1', 'value'),
|
| 703 |
-
Input('max-slider_db0-1', 'value'),
|
| 704 |
-
Input('min-slider_db0-2', 'value'),
|
| 705 |
-
Input('max-slider_db0-2', 'value'),
|
| 706 |
-
Input('min-slider_db0-3', 'value'),
|
| 707 |
-
Input('max-slider_db0-3', 'value'),
|
| 708 |
-
|
| 709 |
-
)
|
| 710 |
-
def update_slider_values(min_1, max_1, min_2, max_2, min_3, max_3):
|
| 711 |
-
return [min_1, max_1], [min_2, max_2], [min_3, max_3]
|
| 712 |
-
|
| 713 |
-
@callback(
|
| 714 |
-
Output(component_id='my-graph_db0', component_property='figure'),
|
| 715 |
-
Output(component_id='pie-graph_db0', component_property='figure'),
|
| 716 |
-
Output(component_id='scatter-plot_db0', component_property='figure'),
|
| 717 |
-
Output(component_id='scatter-plot_db0-2', component_property='figure'),
|
| 718 |
-
Output(component_id='scatter-plot_db0-3', component_property='figure'),
|
| 719 |
-
Output(component_id='scatter-plot_db0-4', component_property='figure'), # Add this new scatter plot
|
| 720 |
-
Output(component_id='scatter-plot_db0-5', component_property='figure'),
|
| 721 |
-
Output(component_id='scatter-plot_db0-6', component_property='figure'),
|
| 722 |
-
Output(component_id='scatter-plot_db0-7', component_property='figure'),
|
| 723 |
-
Output(component_id='scatter-plot_db0-8', component_property='figure'),
|
| 724 |
-
Output(component_id='scatter-plot_db0-9', component_property='figure'),
|
| 725 |
-
Output(component_id='scatter-plot_db0-10', component_property='figure'),
|
| 726 |
-
Output(component_id='scatter-plot_db0-11', component_property='figure'),
|
| 727 |
-
Output(component_id='scatter-plot_db0-12', component_property='figure'),
|
| 728 |
-
Output(component_id='my-graph_db02', component_property='figure'),
|
| 729 |
-
Input(component_id='dpdn2', component_property='value'),
|
| 730 |
-
Input(component_id='dpdn3', component_property='value'),
|
| 731 |
-
Input(component_id='dpdn4', component_property='value'),
|
| 732 |
-
Input(component_id='dpdn5', component_property='value'),
|
| 733 |
-
Input(component_id='dpdn6', component_property='value'),
|
| 734 |
-
Input(component_id='dpdn7', component_property='value'),
|
| 735 |
-
Input(component_id='range-slider_db0-1', component_property='value'),
|
| 736 |
-
Input(component_id='range-slider_db0-2', component_property='value'),
|
| 737 |
-
Input(component_id='range-slider_db0-3', component_property='value'),
|
| 738 |
-
|
| 739 |
-
)
|
| 740 |
-
|
| 741 |
-
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,
|
| 742 |
-
batch_chosen = df[col_chosen].unique().to_list()
|
| 743 |
-
dff = df.filter(
|
| 744 |
-
(pl.col(col_chosen).cast(str).is_in(batch_chosen)) &
|
| 745 |
-
(pl.col(col_features) >= range_value_1[0]) &
|
| 746 |
-
(pl.col(col_features) <= range_value_1[1]) &
|
| 747 |
-
(pl.col(col_counts) >= range_value_2[0]) &
|
| 748 |
-
(pl.col(col_counts) <= range_value_2[1]) &
|
| 749 |
-
(pl.col(col_mt) >= range_value_3[0]) &
|
| 750 |
-
(pl.col(col_mt) <= range_value_3[1])
|
| 751 |
-
)
|
| 752 |
-
|
| 753 |
-
#Drop categories that are not in the filtered data
|
| 754 |
-
dff = dff.with_columns(dff[col_chosen].cast(pl.Categorical))
|
| 755 |
-
|
| 756 |
-
dff = dff.sort(col_chosen)
|
| 757 |
-
|
| 758 |
-
# Plot figures
|
| 759 |
-
fig_violin_db0 = px.violin(data_frame=dff, x=col_chosen, y=col_features, box=True, points="all",
|
| 760 |
-
color=col_chosen, hover_name=col_chosen,template="seaborn")
|
| 761 |
-
|
| 762 |
-
# Cache commonly used subexpressions
|
| 763 |
-
total_count = pl.lit(len(dff))
|
| 764 |
-
category_counts = dff.group_by(col_chosen).agg(pl.col(col_chosen).count().alias("count"))
|
| 765 |
-
category_counts = category_counts.with_columns(((pl.col("count") / total_count * 100).round(decimals=2)).alias("normalized_count"))
|
| 766 |
-
|
| 767 |
-
# Sort the dataframe
|
| 768 |
-
#category_counts = category_counts.sort(col_chosen) does not work check if the names are different ...
|
| 769 |
-
|
| 770 |
-
# Display the result
|
| 771 |
-
total_cells = total_count # Calculate total number of cells
|
| 772 |
-
pie_title = f'Percentage of Total Cells: {total_cells}' # Include total cells in the title
|
| 773 |
-
|
| 774 |
-
# Calculate the mean expression
|
| 775 |
-
|
| 776 |
-
# Melt wide format DataFrame into long format
|
| 777 |
-
# Specify batch column as string type and gene columns as float type
|
| 778 |
-
list_conds = condition3_chosen
|
| 779 |
-
list_conds += [col_chosen]
|
| 780 |
-
dff_pre = dff.select(list_conds)
|
| 781 |
-
|
| 782 |
-
# Melt wide format DataFrame into long format
|
| 783 |
-
dff_long = dff_pre.melt(id_vars=col_chosen, variable_name="Gene", value_name="Mean expression")
|
| 784 |
-
|
| 785 |
-
# Calculate the mean expression levels for each gene in each region
|
| 786 |
-
expression_means = dff_long.lazy().group_by([col_chosen, "Gene"]).agg(pl.mean("Mean expression")).collect()
|
| 787 |
-
|
| 788 |
-
# Calculate the percentage total expressed
|
| 789 |
-
dff_long1 = dff_pre.melt(id_vars=col_chosen, variable_name="Gene")#.group_by(pl.all()).agg(pl.len())
|
| 790 |
-
count = 1
|
| 791 |
-
dff_long2 = dff_long1.with_columns(pl.lit(count).alias("len"))
|
| 792 |
-
dff_long3 = dff_long2.filter(pl.col("value") > 0).group_by([col_chosen, "Gene"]).agg(pl.sum("len").alias("len"))
|
| 793 |
-
dff_long4 = dff_long2.group_by([col_chosen, "Gene"]).agg(pl.sum("len").alias("total"))
|
| 794 |
-
dff_5 = dff_long4.join(dff_long3, on=[col_chosen,"Gene"], how="outer")
|
| 795 |
-
result = dff_5.select([
|
| 796 |
-
pl.when((pl.col('len').is_not_null()) & (pl.col('total').is_not_null()))
|
| 797 |
-
.then(pl.col('len') / pl.col('total')*100)
|
| 798 |
-
.otherwise(None).alias("%"),
|
| 799 |
-
])
|
| 800 |
-
result = result.with_columns(pl.col("%").fill_null(0))
|
| 801 |
-
dff_5[["percentage"]] = result[["%"]]
|
| 802 |
-
dff_5 = dff_5.select(pl.col(col_chosen,"Gene","percentage"))
|
| 803 |
-
|
| 804 |
-
# Final part to join the percentage expressed and mean expression levels
|
| 805 |
-
# TO DO
|
| 806 |
-
expression_means = expression_means.join(dff_5, on=[col_chosen,"Gene"], how="inner")
|
| 807 |
-
|
| 808 |
-
# Order the dataframe on ascending categories
|
| 809 |
-
expression_means = expression_means.sort(col_chosen, descending=True)
|
| 810 |
-
|
| 811 |
-
#expression_means = expression_means.select(["batch", "Gene", "Expression"] + condition3_chosen)
|
| 812 |
-
category_counts = category_counts.sort(col_chosen)
|
| 813 |
-
|
| 814 |
-
fig_pie_db0 = px.pie(category_counts, values="normalized_count", names=col_chosen, labels=col_chosen, hole=.3, title=pie_title, template="seaborn")
|
| 815 |
-
|
| 816 |
-
#labels = category_counts[col_chosen].to_list()
|
| 817 |
-
#values = category_counts["normalized_count"].to_list()
|
| 818 |
-
|
| 819 |
-
# Create the scatter plots
|
| 820 |
-
fig_scatter_db0 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_chosen,
|
| 821 |
-
labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
|
| 822 |
-
hover_name='batch',template="seaborn")
|
| 823 |
-
|
| 824 |
-
fig_scatter_db0_2 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_mt,
|
| 825 |
-
labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
|
| 826 |
-
hover_name='batch',template="seaborn")
|
| 827 |
-
|
| 828 |
-
fig_scatter_db0_3 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_features,
|
| 829 |
-
labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
|
| 830 |
-
hover_name='batch',template="seaborn")
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
fig_scatter_db0_4 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=col_counts,
|
| 834 |
-
labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
|
| 835 |
-
hover_name='batch',template="seaborn")
|
| 836 |
-
|
| 837 |
-
fig_scatter_db0_5 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=s_chosen,
|
| 838 |
-
labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
|
| 839 |
-
hover_name='batch', title="S-cycle gene:",template="seaborn")
|
| 840 |
-
|
| 841 |
-
fig_scatter_db0_6 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=g2m_chosen,
|
| 842 |
-
labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
|
| 843 |
-
hover_name='batch', title="G2M-cycle gene:",template="seaborn")
|
| 844 |
-
|
| 845 |
-
fig_scatter_db0_7 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="S_score",
|
| 846 |
-
labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
|
| 847 |
-
hover_name='batch', title="S score:",template="seaborn")
|
| 848 |
-
|
| 849 |
-
fig_scatter_db0_8 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color="G2M_score",
|
| 850 |
-
labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
|
| 851 |
-
hover_name='batch', title="G2M score:",template="seaborn")
|
| 852 |
-
|
| 853 |
-
# Sort values of custom in-between
|
| 854 |
-
dff = dff.sort(condition1_chosen)
|
| 855 |
-
|
| 856 |
-
fig_scatter_db0_9 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition1_chosen,
|
| 857 |
-
labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
|
| 858 |
-
hover_name='batch',template="seaborn")
|
| 859 |
-
|
| 860 |
-
fig_scatter_db0_10 = px.scatter(data_frame=dff, x='X_umap-0', y='X_umap-1', color=condition2_chosen,
|
| 861 |
-
labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
|
| 862 |
-
hover_name='batch',template="seaborn")
|
| 863 |
-
|
| 864 |
-
fig_scatter_db0_11 = px.scatter(data_frame=dff, x=condition1_chosen, y=condition2_chosen, color=condition1_chosen,
|
| 865 |
-
#labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
|
| 866 |
-
hover_name='batch',template="seaborn")
|
| 867 |
-
|
| 868 |
-
fig_scatter_db0_12 = px.scatter(data_frame=expression_means, x="Gene", y=col_chosen, color="Mean expression",
|
| 869 |
-
size="percentage", size_max = 20,
|
| 870 |
-
#labels={'X_umap-0': 'umap1' , 'X_umap-1': 'umap2'},
|
| 871 |
-
hover_name=col_chosen,template="seaborn")
|
| 872 |
-
|
| 873 |
-
fig_violin_db02 = px.violin(data_frame=dff, x=condition1_chosen, y=condition2_chosen, box=True, points="all",
|
| 874 |
-
color=condition1_chosen, hover_name=condition1_chosen,template="seaborn")
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
return fig_violin_db0, fig_pie_db0, fig_scatter_db0, fig_scatter_db0_2, fig_scatter_db0_3, fig_scatter_db0_4, 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
|
| 878 |
-
|
| 879 |
-
# Set http://localhost:5000/ in web browser
|
| 880 |
-
# Now create your regular FASTAPI application
|
| 881 |
-
|
| 882 |
-
#if __name__ == '__main__':
|
| 883 |
-
# app.run_server(debug=False, use_reloader=False, host='0.0.0.0', port=5000) #
|
|
|
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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