Arts-of-coding commited on
Commit
a5eafbc
·
verified ·
1 Parent(s): d10a30f

Update dash_plotly_QC_scRNA.py

Browse files
Files changed (1) hide show
  1. dash_plotly_QC_scRNA.py +14 -14
dash_plotly_QC_scRNA.py CHANGED
@@ -380,7 +380,7 @@ def update_graph_and_pie_chart(batch_chosen, s_chosen, g2m_chosen, condition1_ch
380
 
381
  # Cache commonly used subexpressions
382
  total_count = pl.lit(len(dff))
383
- category_counts = dff.groupby("batch").agg(pl.col("batch").count().alias("count"))
384
  category_counts = category_counts.with_columns(((pl.col("count") / total_count * 100).round(decimals=2)).alias("normalized_count"))
385
 
386
  # Display the result
@@ -402,21 +402,21 @@ def update_graph_and_pie_chart(batch_chosen, s_chosen, g2m_chosen, condition1_ch
402
  dff_long = dff_pre.melt(id_vars="batch", variable_name="Gene", value_name="Mean expression")
403
 
404
  # Calculate the mean expression levels for each gene in each region
405
- expression_means = dff_long.lazy().groupby(["batch", "Gene"]).agg(pl.mean("Mean expression")).collect()
406
 
407
  # Calculate the percentage total expressed
408
- dff_long2 = dff_pre.melt(id_vars="batch", variable_name="Gene").group_by(pl.all()).len()
409
- dff_long3 = dff_long2.filter(value = 0).group_by(["batch", "Gene"]).agg(pl.sum("len").alias("total"))
410
- dff_long4 = dff_long2.group_by(["batch", "Gene"]).agg(pl.sum("len").alias("total"))
411
- dff_5 = dff_long4.join(dff_long3, on=["batch","Gene"], how="outer")
412
- result = dff_5.select([
413
- pl.when((pl.col('total_right').is_not_null()) & (pl.col('total').is_not_null()))
414
- .then(pl.col('total_right') / pl.col('total'))
415
- .otherwise(None).alias("%"),
416
- ])
417
- result = result.with_columns(pl.col("%").fill_null(1.0))
418
- dff_5[["percentage"]] = result[["%"]]
419
- dff_5 = dff_5.select(pl.col("batch","Gene","percentage"))
420
 
421
  # Final part to join the percentage expressed and mean expression levels
422
  # TO DO
 
380
 
381
  # Cache commonly used subexpressions
382
  total_count = pl.lit(len(dff))
383
+ category_counts = dff.group_by("batch").agg(pl.col("batch").count().alias("count"))
384
  category_counts = category_counts.with_columns(((pl.col("count") / total_count * 100).round(decimals=2)).alias("normalized_count"))
385
 
386
  # Display the result
 
402
  dff_long = dff_pre.melt(id_vars="batch", variable_name="Gene", value_name="Mean expression")
403
 
404
  # Calculate the mean expression levels for each gene in each region
405
+ expression_means = dff_long.lazy().group_by(["batch", "Gene"]).agg(pl.mean("Mean expression")).collect()
406
 
407
  # Calculate the percentage total expressed
408
+ #dff_long2 = dff_pre.melt(id_vars="batch", variable_name="Gene").group_by(pl.all()).len()
409
+ #dff_long3 = dff_long2.filter(value = 0).group_by(["batch", "Gene"]).agg(pl.sum("len").alias("total"))
410
+ #dff_long4 = dff_long2.group_by(["batch", "Gene"]).agg(pl.sum("len").alias("total"))
411
+ #dff_5 = dff_long4.join(dff_long3, on=["batch","Gene"], how="outer")
412
+ #result = dff_5.select([
413
+ # pl.when((pl.col('total_right').is_not_null()) & (pl.col('total').is_not_null()))
414
+ # .then(pl.col('total_right') / pl.col('total'))
415
+ # .otherwise(None).alias("%"),
416
+ #])
417
+ #result = result.with_columns(pl.col("%").fill_null(1.0))
418
+ #dff_5[["percentage"]] = result[["%"]]
419
+ #dff_5 = dff_5.select(pl.col("batch","Gene","percentage"))
420
 
421
  # Final part to join the percentage expressed and mean expression levels
422
  # TO DO