Skip to content

Commit

Permalink
show up/down-regulated DEGs in DEG count table
Browse files Browse the repository at this point in the history
  • Loading branch information
LMBradford committed Sep 27, 2024
1 parent 713d149 commit 26ac886
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
45 changes: 38 additions & 7 deletions Rmd/summary_report_new.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,8 @@ library(knitr)
library(kableExtra)
library(ggplot2)
library(formattable)
```



```{r paths}
############################################################################
# File paths in project directory
Expand Down Expand Up @@ -329,9 +326,11 @@ exp_contrasts <- R.ODAF.utils::get_contrasts(file.path(paths$contrasts, params$c
deg_counts <- read.delim(file.path(paths$summary, "DEG_counts.txt"), sep = "\t", stringsAsFactors = FALSE, header = FALSE)
if (!is.na(params$reports_facet)) {
colnames(deg_counts) <- c(params$reports_facet, "Contrast", "DEGs")
colnames(deg_counts) <- c(params$reports_facet, "Contrast", "DEGs", "Downregulated", "Upregulated")
deg_table_alignment <- c("l", "l", "l", "r", "l")
} else {
colnames(deg_counts) <- c("Contrast", "DEGs")
colnames(deg_counts) <- c("Contrast", "DEGs", "Downregulated", "Upregulated")
deg_table_alignment <- c("l", "l", "r", "l")
}
```

Expand All @@ -344,10 +343,42 @@ The number of significant DEGs (i.e., those passing all filters) in each contras
## Number of DEGs per Contrast

```{r DEG_table, }
# From https://github.com/renkun-ken/formattable/issues/106#issuecomment-792383056
bg = function(start, end, color, ...) {
paste("linear-gradient(90deg,transparent ",percent(start),",",
color, percent(start), ",", color, percent(end),
", transparent", percent(end),")")
}
# Colour bar with right-aligned text and bar
color_bar2 = function (color = "lightgray", fun = "proportion", ...)
{
fun <- match.fun(fun)
formatter("span", style = function(x) style(display = "inline-block",
`unicode-bidi` = "plaintext",
"background" = bg(1-fun(as.numeric(x), ...), 1, color), "width"="100%" ))
}
# Colour bar with left-aligned text and bar
color_bar3 = function(color = "lightgray", fun = "proportion", ...) {
fun <- match.fun(fun)
formatter("span", style = function(x) {
value <- fun(as.numeric(x), ...)
style(display = "inline-block",
`unicode-bidi` = "plaintext",
"background" = bg(0, value, color),
"width" = "100%",
"text-align" = "left")
})
}
deg_counts %>%
formattable(
align = c("l", "l", "l", "l"),
list(DEGs = color_bar("lightgreen"))) %>%
align = deg_table_alignment,
list(DEGs = color_tile("white", "lightgreen"),
Upregulated = color_bar3("pink"),
Downregulated = color_bar2("lightblue"))) %>%
formattable::as.htmlwidget(width = 500)
```

Expand Down
4 changes: 3 additions & 1 deletion scripts/run_DESeq2.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ if (is.na(params$deseq_facet)) {
for(comp in comparisons){ # by comparison
res <- resList[[comp]]
counts <- nrow(res)
row <- data.frame(facet=current_filter, comparison=comp, DEG=counts)
upreg <- nrow(res[res$log2FoldChange > 0,])
downreg <- nrow(res[res$log2FoldChange < 0,])
row <- data.frame(facet=current_filter, comparison=comp, DEG=counts, Downregulated=downreg, Upregulated=upreg)
summary_counts <- rbind(summary_counts, row)
}
}
Expand Down

0 comments on commit 26ac886

Please sign in to comment.