From 4de7c62b16de42136475a611c26f3cfc13816d3d Mon Sep 17 00:00:00 2001 From: Sameet <208490+sameet@users.noreply.github.com> Date: Thu, 28 Sep 2023 15:20:46 -0400 Subject: [PATCH 1/4] trying more abstractions --- R/qmd_template_parts.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/R/qmd_template_parts.R b/R/qmd_template_parts.R index 984729f..5f199fb 100644 --- a/R/qmd_template_parts.R +++ b/R/qmd_template_parts.R @@ -3,6 +3,7 @@ #' @param title Title for the report #' @param author Author for the report #' @param email Email of the author for the report +#' @param ... Other parameters to set the yaml header #' #' @return opening_yaml string to be used to construct the report qmd #' @export @@ -13,7 +14,8 @@ #' } template_yaml <- function(title = "RNA-Seq Report", author = "Sameet", - email = "sameet.mehta@yale.edu") { + email = "sameet.mehta@yale.edu", + ...) { opening_yaml <- stringr::str_glue(" --- title: \"{title}\" @@ -34,11 +36,11 @@ execute: message: false echo: true params: - counts: \"gene_count_matrix.csv\" - meta_fn: \"sample-sheet.txt\" + counts: \"{count_fn}\" + meta_fn: \"{sample_fn}\" contrasts_fn: null metrics: null - outputs: \"report_output_dir\" + outputs: \"{outputdir}\" use_threshold: 0.05 --- ") From 370f58d45b5cf2a798bbe09f8f35c5b41591b901 Mon Sep 17 00:00:00 2001 From: Sameet Mehta Date: Thu, 28 Sep 2023 20:49:29 -0400 Subject: [PATCH 2/4] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b4e6542..bfd4707 100644 --- a/README.md +++ b/README.md @@ -113,4 +113,5 @@ contrasts_df <- get_contrasts(fn = "path/to/contrasts/file.txt") meta_df <- read_meta_data("path/to/sample-sheet.txt") compose_qmd(ofn = "path/to/output/directory/where/the/qmd_is_saved.qmd", contrasts_df = contrasts_df) +# As long as the object dds is available this compose_qmd call will work. ``` From 04241591f3c53af49bd2bd306f1660e7de4c6319 Mon Sep 17 00:00:00 2001 From: Sameet Mehta Date: Fri, 29 Sep 2023 12:25:27 -0400 Subject: [PATCH 3/4] Fixed most of the issues. --- R/deseq-related-functions.R | 4 +- R/plot-deseq.R | 6 +- R/qmd_template_parts.R | 4 +- renv.lock | 149 ++++++++++++++++++++++++++++++++++++ 4 files changed, 156 insertions(+), 7 deletions(-) diff --git a/R/deseq-related-functions.R b/R/deseq-related-functions.R index 15cfe4d..d4bfe17 100644 --- a/R/deseq-related-functions.R +++ b/R/deseq-related-functions.R @@ -63,7 +63,7 @@ get_results_from_dds <- function(dds = dds, res_df <- get_all_results(dds) } else { lapply(seq_len(nrow(df)), function(i) { - get_single_result(dds = dds, comp_df = df[1, ]) + get_single_result(dds = dds, comp_df = df[i, ]) }) %>% do.call("rbind", .) -> res_df } @@ -180,6 +180,6 @@ save_results <- function(res_df, op_dir, thresh = 0.05) { dplyr::filter(padj <= thresh) |> readr::write_delim(ofn_sig, delim = "\t") } else { - message("No significant gene detected for the comparison ", ofn_prefix) + message(paste("No significant gene detected for the comparison ", ofn_prefix)) } } diff --git a/R/plot-deseq.R b/R/plot-deseq.R index b6f36e4..cd366ab 100644 --- a/R/plot-deseq.R +++ b/R/plot-deseq.R @@ -256,16 +256,16 @@ make_upset_df <- function(dds, meta_df, contrasts_df = NULL, thresh = 0.05) { make_upset_plot <- function(upset_df) { upset_df |> ggplot2::ggplot(ggplot2::aes(x = comp_updown)) + - ggplot2::geom_bar() + + ggplot2::geom_bar(fill = "#5A5A5A") + ggplot2::geom_text(stat = "count", ggplot2::aes(label = ggplot2::after_stat(count)), - vjust = 1.1, color = "#F0F0F0", size = 2) + + vjust = 1.1, color = "#010101", size = 3) + ggplot2::labs(title = "Combined Gene Visualization", x = "Comparison and Up/Down Status", y = "Frequency (No. of Significant Genes)") + ggplot2::theme_minimal() + my_rnaseq_theme() + - ggupset::scale_x_upset(order_by = "degree") + + ggupset::scale_x_upset(order_by = "freq") + ggupset::theme_combmatrix( combmatrix.panel.point.color.empty = "grey90", combmatrix.panel.striped_background.color.one = "darkgrey", diff --git a/R/qmd_template_parts.R b/R/qmd_template_parts.R index 5f199fb..08b6c48 100644 --- a/R/qmd_template_parts.R +++ b/R/qmd_template_parts.R @@ -303,7 +303,7 @@ downreg_rows <- which(use_sig_df_{comp_n}$log2FoldChange < 0) use_sig_df_{comp_n} |> kableExtra::kbl(booktabs = TRUE) |> - kableExtra::kable_stying(bootstrap_options = c(\"condensed\"), + kableExtra::kable_styling(bootstrap_options = c(\"condensed\"), latex_options = c(\"striped\"), font_size = 8 ) |> @@ -388,7 +388,7 @@ Upset plot for the data in this analysis is given in @fig_upset upset_df <- make_upset_df(dds = dds, meta_df = meta_df, contrasts_df = contrasts_df, thresh = params$use_threshold) -upset_plot <- make_upset_plot(uset_df) +upset_plot <- make_upset_plot(upset_df) ``` In @fig_upset the number in the bars denotes number of genes satisfying that condition. ") diff --git a/renv.lock b/renv.lock index 6765a99..127e035 100644 --- a/renv.lock +++ b/renv.lock @@ -433,6 +433,13 @@ "Repository": "RSPM", "Hash": "b7d8d8ee39869c18d8846a184dd8a1af" }, + "brio": { + "Package": "brio", + "Version": "1.1.3", + "Source": "Repository", + "Repository": "RSPM", + "Hash": "976cf154dfb043c012d87cddd8bca363" + }, "bslib": { "Package": "bslib", "Version": "0.5.1", @@ -561,6 +568,35 @@ ], "Hash": "511bacbfa153a15251166b463b4da4f9" }, + "desc": { + "Package": "desc", + "Version": "1.4.2", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "R6", + "cli", + "rprojroot", + "utils" + ], + "Hash": "6b9602c7ebbe87101a9c8edb6e8b6d21" + }, + "diffobj": { + "Package": "diffobj", + "Version": "0.3.5", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "crayon", + "methods", + "stats", + "tools", + "utils" + ], + "Hash": "bcaa8b95f8d7d01a5dedfd959ce88ab8" + }, "digest": { "Package": "digest", "Version": "0.6.33", @@ -1172,6 +1208,24 @@ ], "Hash": "15da5a8412f317beeee6175fbc76f4bb" }, + "pkgbuild": { + "Package": "pkgbuild", + "Version": "1.4.2", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "R6", + "callr", + "cli", + "crayon", + "desc", + "prettyunits", + "processx", + "rprojroot" + ], + "Hash": "beb25b32a957a22a5c301a9e441190b3" + }, "pkgconfig": { "Package": "pkgconfig", "Version": "2.0.3", @@ -1182,6 +1236,34 @@ ], "Hash": "01f28d4278f15c76cddbea05899c5d6f" }, + "pkgload": { + "Package": "pkgload", + "Version": "1.3.3", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "cli", + "crayon", + "desc", + "fs", + "glue", + "methods", + "pkgbuild", + "rlang", + "rprojroot", + "utils", + "withr" + ], + "Hash": "903d68319ae9923fb2e2ee7fa8230b91" + }, + "praise": { + "Package": "praise", + "Version": "1.0.0", + "Source": "Repository", + "Repository": "RSPM", + "Hash": "a555924add98c99d2f411e37e7d25e9f" + }, "prettyunits": { "Package": "prettyunits", "Version": "1.2.0", @@ -1277,6 +1359,16 @@ ], "Hash": "b5047343b3825f37ad9d3b5d89aa1078" }, + "rematch2": { + "Package": "rematch2", + "Version": "2.1.2", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "tibble" + ], + "Hash": "76c9e04c712a05848ae7a23d2f170a40" + }, "renv": { "Package": "renv", "Version": "1.0.3", @@ -1322,6 +1414,16 @@ ], "Hash": "d65e35823c817f09f4de424fcdfa812a" }, + "rprojroot": { + "Package": "rprojroot", + "Version": "2.0.3", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R" + ], + "Hash": "1de7ab598047a87bba48434ba35d497d" + }, "rstudioapi": { "Package": "rstudioapi", "Version": "0.15.0", @@ -1465,6 +1567,36 @@ ], "Hash": "90b28393209827327de889f49935140a" }, + "testthat": { + "Package": "testthat", + "Version": "3.1.10", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "R6", + "brio", + "callr", + "cli", + "desc", + "digest", + "ellipsis", + "evaluate", + "jsonlite", + "lifecycle", + "magrittr", + "methods", + "pkgload", + "praise", + "processx", + "ps", + "rlang", + "utils", + "waldo", + "withr" + ], + "Hash": "6f403dc49295610a3a67ea1a9ca64346" + }, "tibble": { "Package": "tibble", "Version": "3.2.1", @@ -1604,6 +1736,23 @@ ], "Hash": "8318e64ffb3a70e652494017ec455561" }, + "waldo": { + "Package": "waldo", + "Version": "0.5.1", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "cli", + "diffobj", + "fansi", + "glue", + "methods", + "rematch2", + "rlang", + "tibble" + ], + "Hash": "2c993415154cdb94649d99ae138ff5e5" + }, "webshot": { "Package": "webshot", "Version": "0.5.5", From 88d5cef90405cdc3a1b8fa1a63e4080aac44f203 Mon Sep 17 00:00:00 2001 From: Sameet Mehta Date: Fri, 29 Sep 2023 12:29:51 -0400 Subject: [PATCH 4/4] Fixed some more typos. --- R/qmd_template_parts.R | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/R/qmd_template_parts.R b/R/qmd_template_parts.R index 08b6c48..2ca5b00 100644 --- a/R/qmd_template_parts.R +++ b/R/qmd_template_parts.R @@ -339,7 +339,7 @@ all_plot_{comp_n}$bp_s ``` ```{{r}} #| label: fig-hm_{comp_n} -#| fig-cap: Heatmp for all significant genes for {comparison_name}. There are total `r nrow(sig_df)` significant genes. +#| fig-cap: Heatmp for all significant genes for {comparison_name}. There are total {sig_genes} significant genes. ggplotify::as.ggplot(all_plot_{comp_n}$hm) ``` @@ -368,7 +368,11 @@ PCA plot is a potent dimensionality reduction method that can show the discrimin pca_p_l <- make_pca_plot_l(dds = dds, vs_data = vs_data, contrasts_df = contrasts_df, thresh = params$use_threshold) patchwork::wrap_plots(pca_p_l, nrow = 2, byrow = TRUE) + patchwork::plot_layout(guides = \"collect\") + - patchwork::plot_annotation(tag_levels = \"A\") + patchwork::plot_annotation(tag_levels = \"A\") -> pca_plot + +ofn_pca <- file.path(params$outputs, \"all-pca-plot.pdf\") +ggplot2::ggsave(filename = ofn_pca, device = \"pdf\", plot = pca_plot) +pca_plot ``` PCA plot for the data in this report is given in @fig-pca. @@ -389,6 +393,9 @@ Upset plot for the data in this analysis is given in @fig_upset upset_df <- make_upset_df(dds = dds, meta_df = meta_df, contrasts_df = contrasts_df, thresh = params$use_threshold) upset_plot <- make_upset_plot(upset_df) +ofn_upset <- file.path(params$outputs, \"upset-plot.pdf\") +ggplot2::ggsave(filname = ofn_upset, device = \"pdf\", plot = upset_plot) +upset_plot ``` In @fig_upset the number in the bars denotes number of genes satisfying that condition. ")