Arts-of-coding commited on
Commit
8433358
·
verified ·
1 Parent(s): a2dbf3f

Update dash_plotly_QC_scRNA.py

Browse files
Files changed (1) hide show
  1. dash_plotly_QC_scRNA.py +3 -5
dash_plotly_QC_scRNA.py CHANGED
@@ -394,13 +394,11 @@ def update_graph_and_pie_chart(batch_chosen, s_chosen, g2m_chosen, condition1_ch
394
  # Calculate the mean expression
395
 
396
  # Melt wide format DataFrame into long format
397
- dff_pre = dff.with_columns(pl.lit(None).cast(pl.Utf8), pl.col("*"))
 
398
 
399
- # Cast Cdc45, Uhrf1, Mcm2, Slbp, Mcm5, Pola1, Gmnn, Cdc6, Rrm2, Atad2 columns to float type
400
- for gene in ["Cdc45", "Uhrf1", "Mcm2", "Slbp", "Mcm5", "Pola1", "Gmnn", "Cdc6", "Rrm2", "Atad2"]:
401
- dff_pre = dff_pre.with_columns(pl.col(gene).cast(pl.Float64))
402
 
403
- dff_long = dff_pre.melt(id_vars="batch", variable_name="Gene", value_name="Expression")
404
  expression_means = dff_long.group_by(["Region", "Gene"]).agg(pl.mean("Expression"))
405
 
406
  fig_pie = px.pie(names=labels, values=values, title=pie_title,template="seaborn")
 
394
  # Calculate the mean expression
395
 
396
  # Melt wide format DataFrame into long format
397
+ # Specify batch column as string type and gene columns as float type
398
+ dff_pre = dff.with_columns(pl.lit(None).cast(pl.Utf8).alias("batch"), *[pl.col(col).cast(pl.Float64) for col in ["Cdc45", "Uhrf1", "Mcm2", "Slbp", "Mcm5", "Pola1", "Gmnn", "Cdc6", "Rrm2", "Atad2"]])
399
 
400
+ dff_long = dff_pre.melt(id_vars={"batch"}, variable_name="Gene", value_name="Expression").with_columns(pl.col("batch").cast(pl.Categorical))
 
 
401
 
 
402
  expression_means = dff_long.group_by(["Region", "Gene"]).agg(pl.mean("Expression"))
403
 
404
  fig_pie = px.pie(names=labels, values=values, title=pie_title,template="seaborn")