Spaces:
Sleeping
Sleeping
Delete pages/integratedaniridia.py
Browse files- pages/integratedaniridia.py +0 -539
pages/integratedaniridia.py
DELETED
@@ -1,539 +0,0 @@
|
|
1 |
-
# Dash app to visualize scRNA-seq data quality control metrics from scanpy objects
|
2 |
-
# Shoutout to Coding-with-Adam for the initial template of the project:
|
3 |
-
# https://github.com/Coding-with-Adam/Dash-by-Plotly/blob/master/Dash%20Components/Graph/dash-graph.py
|
4 |
-
|
5 |
-
import dash
|
6 |
-
from dash import dcc, html, Output, Input, callback
|
7 |
-
import plotly.express as px
|
8 |
-
import dash_callback_chain
|
9 |
-
import yaml
|
10 |
-
import polars as pl
|
11 |
-
import os
|
12 |
-
pl.enable_string_cache(False)
|
13 |
-
|
14 |
-
dash.register_page(__name__, location="sidebar")
|
15 |
-
|
16 |
-
dataset = "dataaniridia/integrated/sc_liu_aniridia_integrated_processed"
|
17 |
-
|
18 |
-
# Set custom resolution for plots:
|
19 |
-
config_fig = {
|
20 |
-
'toImageButtonOptions': {
|
21 |
-
'format': 'svg',
|
22 |
-
'filename': 'custom_image',
|
23 |
-
'height': 600,
|
24 |
-
'width': 700,
|
25 |
-
'scale': 1,
|
26 |
-
}
|
27 |
-
}
|
28 |
-
from adlfs import AzureBlobFileSystem
|
29 |
-
mountpount=os.environ['AZURE_MOUNT_POINT'],
|
30 |
-
AZURE_STORAGE_ACCESS_KEY=os.getenv('AZURE_STORAGE_ACCESS_KEY')
|
31 |
-
AZURE_STORAGE_ACCOUNT=os.getenv('AZURE_STORAGE_ACCOUNT')
|
32 |
-
|
33 |
-
# Load in config file
|
34 |
-
config_path = "./data/config.yaml"
|
35 |
-
|
36 |
-
# Add the read-in data from the yaml file
|
37 |
-
def read_config(filename):
|
38 |
-
with open(filename, 'r') as yaml_file:
|
39 |
-
config = yaml.safe_load(yaml_file)
|
40 |
-
return config
|
41 |
-
|
42 |
-
config = read_config(config_path)
|
43 |
-
path_parquet = config.get("path_parquet")
|
44 |
-
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-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",
|
168 |
-
"Mcm2",
|
169 |
-
"Slbp",
|
170 |
-
"Mcm5",
|
171 |
-
"Pola1",
|
172 |
-
"Gmnn",
|
173 |
-
"Cdc6",
|
174 |
-
"Rrm2",
|
175 |
-
"Atad2",
|
176 |
-
"Dscc1",
|
177 |
-
"Mcm4",
|
178 |
-
"Chaf1b",
|
179 |
-
"Rfc2",
|
180 |
-
"Msh2",
|
181 |
-
"Fen1",
|
182 |
-
"Hells",
|
183 |
-
"Prim1",
|
184 |
-
"Tyms",
|
185 |
-
"Mcm6",
|
186 |
-
"Wdr76",
|
187 |
-
"Rad51",
|
188 |
-
"Pcna",
|
189 |
-
"Ccne2",
|
190 |
-
"Casp8ap2",
|
191 |
-
"Usp1",
|
192 |
-
"Nasp",
|
193 |
-
"Rpa2",
|
194 |
-
"Ung",
|
195 |
-
"Rad51ap1",
|
196 |
-
"Blm",
|
197 |
-
"Pold3",
|
198 |
-
"Rrm1",
|
199 |
-
"Cenpu",
|
200 |
-
"Gins2",
|
201 |
-
"Tipin",
|
202 |
-
"Brip1",
|
203 |
-
"Dtl",
|
204 |
-
"Exo1",
|
205 |
-
"Ubr7",
|
206 |
-
"Clspn",
|
207 |
-
"E2f8",
|
208 |
-
"Cdca7"
|
209 |
-
]),
|
210 |
-
html.Label("G2M-cycle genes"),
|
211 |
-
dcc.Dropdown(id='dpdn4', value="Top2a", multi=False,
|
212 |
-
options=[
|
213 |
-
"Ube2c",
|
214 |
-
"Lbr",
|
215 |
-
"Ctcf",
|
216 |
-
"Cdc20",
|
217 |
-
"Cbx5",
|
218 |
-
"Kif11",
|
219 |
-
"Anp32e",
|
220 |
-
"Birc5",
|
221 |
-
"Cdk1",
|
222 |
-
"Tmpo",
|
223 |
-
"Hmmr",
|
224 |
-
"Pimreg",
|
225 |
-
"Aurkb",
|
226 |
-
"Top2a",
|
227 |
-
"Gtse1",
|
228 |
-
"Rangap1",
|
229 |
-
"Cdca3",
|
230 |
-
"Ndc80",
|
231 |
-
"Kif20b",
|
232 |
-
"Cenpf",
|
233 |
-
"Nek2",
|
234 |
-
"Nuf2",
|
235 |
-
"Nusap1",
|
236 |
-
"Bub1",
|
237 |
-
"Tpx2",
|
238 |
-
"Aurka",
|
239 |
-
"Ect2",
|
240 |
-
"Cks1b",
|
241 |
-
"Kif2c",
|
242 |
-
"Cdca8",
|
243 |
-
"Cenpa",
|
244 |
-
"Mki67",
|
245 |
-
"Ccnb2",
|
246 |
-
"Kif23",
|
247 |
-
"Smc4",
|
248 |
-
"G2e3",
|
249 |
-
"Tubb4b",
|
250 |
-
"Anln",
|
251 |
-
"Tacc3",
|
252 |
-
"Dlgap5",
|
253 |
-
"Ckap2",
|
254 |
-
"Ncapd2",
|
255 |
-
"Ttk",
|
256 |
-
"Ckap5",
|
257 |
-
"Cdc25c",
|
258 |
-
"Hjurp",
|
259 |
-
"Cenpe",
|
260 |
-
"Ckap2l",
|
261 |
-
"Cdca2",
|
262 |
-
"Hmgb2",
|
263 |
-
"Cks2",
|
264 |
-
"Psrc1",
|
265 |
-
"Gas2l3"
|
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 |
-
|
323 |
-
# Define the tabs layout
|
324 |
-
layout = html.Div([
|
325 |
-
html.H1(f'Dataset analysis dashboard: {dataset}'),
|
326 |
-
dcc.Tabs(id='tabs', style= {'width': 600,
|
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 |
-
|
432 |
-
# Melt wide format DataFrame into long format
|
433 |
-
# Specify batch column as string type and gene columns as float type
|
434 |
-
list_conds = condition3_chosen
|
435 |
-
list_conds += [col_chosen]
|
436 |
-
dff_pre = dff.select(list_conds)
|
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())
|
446 |
-
count = 1
|
447 |
-
dff_long2 = dff_long1.with_columns(pl.lit(count).alias("len"))
|
448 |
-
dff_long3 = dff_long2.filter(pl.col("value") > 0).group_by([col_chosen, "Gene"]).agg(pl.sum("len").alias("len"))
|
449 |
-
dff_long4 = dff_long2.group_by([col_chosen, "Gene"]).agg(pl.sum("len").alias("total"))
|
450 |
-
dff_5 = dff_long4.join(dff_long3, on=[col_chosen,"Gene"], how="outer")
|
451 |
-
result = dff_5.select([
|
452 |
-
pl.when((pl.col('len').is_not_null()) & (pl.col('total').is_not_null()))
|
453 |
-
.then(pl.col('len') / pl.col('total')*100)
|
454 |
-
.otherwise(None).alias("%"),
|
455 |
-
])
|
456 |
-
result = result.with_columns(pl.col("%").fill_null(0))
|
457 |
-
dff_5[["percentage"]] = result[["%"]]
|
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) #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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