From a1d3c5efa375fe345a6ab6c341f309f26a43109d Mon Sep 17 00:00:00 2001 From: Max Schubach Date: Tue, 17 Dec 2024 09:05:22 +0100 Subject: [PATCH] fix: experiment countplots --- workflow/rules/qc_report.smk | 10 ++++---- workflow/rules/statistic/correlation.smk | 1 + .../count/plot_perInsertCounts_stats.R | 19 +++++++++------ workflow/scripts/report/qc_report_count.qmd | 23 +++++++++++++++---- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/workflow/rules/qc_report.smk b/workflow/rules/qc_report.smk index 8221a7b..ea4e575 100644 --- a/workflow/rules/qc_report.smk +++ b/workflow/rules/qc_report.smk @@ -83,8 +83,9 @@ rule qc_report_count: statistics_all_single="results/experiments/{project}/statistic/statistic_assigned_counts_single_{assignment}_{config}.tsv", statistics_all_oligo_cor_all="results/experiments/{project}/statistic/assigned_counts/{assignment}/{config}/{condition}_correlation.tsv", statistics_all_oligo_cor_thresh="results/experiments/{project}/statistic/assigned_counts/{assignment}/{config}/{condition}_correlation_minThreshold.tsv", - counts_per_oligo_dna="results/experiments/{project}/statistic/barcode/assigned_counts/{assignment}/{condition}_{config}_DNA_perBarcode.png", - counts_per_oligo_rna="results/experiments/{project}/statistic/barcode/assigned_counts/{assignment}/{condition}_{config}_RNA_perBarcode.png", + counts_per_oligo="results/experiments/{project}/statistic/assigned_counts/{assignment}/{config}/{condition}_barcodesPerInsert.png", + counts_per_bc_dna="results/experiments/{project}/statistic/barcode/assigned_counts/{assignment}/{condition}_{config}_DNA_perBarcode.png", + counts_per_bc_rna="results/experiments/{project}/statistic/barcode/assigned_counts/{assignment}/{condition}_{config}_RNA_perBarcode.png", activity_thresh="results/experiments/{project}/statistic/assigned_counts/{assignment}/{config}/{condition}_group_barcodesPerInsert_box.png", activity_all="results/experiments/{project}/statistic/assigned_counts/{assignment}/{config}/{condition}_group_barcodesPerInsert_box_minThreshold.png", dna_over_rna="results/experiments/{project}/statistic/assigned_counts/{assignment}/{config}/{condition}_dna_vs_rna.png", @@ -121,8 +122,9 @@ rule qc_report_count: -P "ratio_oligo_coor_plot:{input.ratio_oligo_coor_plot}" \ -P "ratio_oligo_min_thre_plot:{input.ratio_oligo_min_thre_plot}" \ -P "statistics_all_merged:{input.statistics_all_merged}" \ - -P "counts_per_oligo_dna:{input.counts_per_oligo_dna}" \ - -P "counts_per_oligo_rna:{input.counts_per_oligo_rna}" \ + -P "counts_per_oligo:{input.counts_per_oligo}" \ + -P "counts_per_bc_dna:{input.counts_per_bc_dna}" \ + -P "counts_per_bc_rna:{input.counts_per_bc_rna}" \ -P "statistics_all_single:{input.statistics_all_single}" \ -P "activity_all:{input.activity_all}" \ -P "activity_thresh:{input.activity_thresh}" \ diff --git a/workflow/rules/statistic/correlation.smk b/workflow/rules/statistic/correlation.smk index 90eb1d5..4fb5cc5 100644 --- a/workflow/rules/statistic/correlation.smk +++ b/workflow/rules/statistic/correlation.smk @@ -354,6 +354,7 @@ rule statistic_correlation_hist_box_plots: ), script=getScript("count/plot_perInsertCounts_stats.R"), output: + "results/experiments/{project}/statistic/assigned_counts/{assignment}/{config}/{condition}_barcodesPerInsert.png", "results/experiments/{project}/statistic/assigned_counts/{assignment}/{config}/{condition}_group_barcodesPerInsert_box.png", "results/experiments/{project}/statistic/assigned_counts/{assignment}/{config}/{condition}_group_barcodesPerInsert_box_minThreshold.png", "results/experiments/{project}/statistic/assigned_counts/{assignment}/{config}/{condition}_dna_vs_rna.png", diff --git a/workflow/scripts/count/plot_perInsertCounts_stats.R b/workflow/scripts/count/plot_perInsertCounts_stats.R index 0052829..02f5b1e 100644 --- a/workflow/scripts/count/plot_perInsertCounts_stats.R +++ b/workflow/scripts/count/plot_perInsertCounts_stats.R @@ -195,12 +195,17 @@ for (n in 1:(data %>% nrow())) { assigned_counts <- all %>% filter(replicate == rep) # Histograms - intercept <- median(assigned_counts$n_bc) + x_lim_n_bc <- min(max(assigned_counts$n_bc), 300) + intercept_median <- median(assigned_counts$n_bc) + intercept_mean <- mean(assigned_counts$n_bc) hist_plot_list[[n]] <- ggplot(assigned_counts, aes(x = n_bc)) + - geom_histogram(bins = 300) + - geom_vline(xintercept = intercept, colour = "red") + - xlim(0, 300) + + geom_histogram(bins = x_lim_n_bc) + + geom_vline(xintercept = intercept_median, colour = "red") + + geom_vline(xintercept = intercept_mean, colour = "blue") + + xlim(0, x_lim_n_bc) + + ylab("Frequency") + + xlab("Barcodes per oligo") + ggtitle(paste("replicate", rep, sep = " ")) # Boxplots @@ -214,14 +219,14 @@ for (n in 1:(data %>% nrow())) { } hist_plot <- do.call("plot_grid", c(hist_plot_list)) -ggsave(sprintf("%s_barcodesPerInsert.png", outdir), hist_plot, width = 30, height = 30) +ggsave(sprintf("%s_barcodesPerInsert.png", outdir), hist_plot, dpi = 300, type = "cairo") box_plot_insert <- do.call("plot_grid", c(box_plot_insert_list)) ggsave(sprintf("%s_group_barcodesPerInsert_box.png", outdir), box_plot_insert, - width = 30, height = 30 + dpi = 300, type = "cairo" ) box_plot_insert_thresh <- @@ -229,7 +234,7 @@ box_plot_insert_thresh <- ggsave( sprintf("%s_group_barcodesPerInsert_box_minThreshold.png", outdir), box_plot_insert_thresh, - width = 30, height = 30 + dpi = 300, type = "cairo" ) print("Script done") diff --git a/workflow/scripts/report/qc_report_count.qmd b/workflow/scripts/report/qc_report_count.qmd index 4d96eed..232a4e4 100644 --- a/workflow/scripts/report/qc_report_count.qmd +++ b/workflow/scripts/report/qc_report_count.qmd @@ -229,20 +229,33 @@ df_single.style.hide(axis="index").format( precision=2) # Number of barcodes per oligo -Histogramm of number of barcodes per oligo. Median is blue, mean is red. + Median is red, mean is blue. + + +# Histograms barcodes per oligo, counts per barcode + +Histogramm of number of barcodes per oligo and the number of counts per barcode devidied by DNA and RNA. Median is red, mean is blue. + ::: {.panel-tabset} -# DNA +# Number of barcodes per oligo +```{python} +#| echo: false +display(Image(f"{workdir}/{counts_per_oligo}")) +``` + + +# Number of counts per DNA barcode ```{python} #| echo: false -display(Image(f"{workdir}/{counts_per_oligo_dna}")) +display(Image(f"{workdir}/{counts_per_bc_dna}")) ``` -# RNA +# Number of counts per DNA barcode ```{python} #| echo: false -display(Image(f"{workdir}/{counts_per_oligo_rna}")) +display(Image(f"{workdir}/{counts_per_bc_rna}")) ``` :::