From 92215d9b302dde49bf45e96fa75a525c13b4ecc0 Mon Sep 17 00:00:00 2001 From: hertafeldsr Date: Tue, 12 May 2020 17:21:10 -0400 Subject: [PATCH 1/2] added helper function for no-replicate heatmaps --- workflows/rnaseq/downstream/helpers.Rmd | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/workflows/rnaseq/downstream/helpers.Rmd b/workflows/rnaseq/downstream/helpers.Rmd index 87740063f..351cd5efd 100644 --- a/workflows/rnaseq/downstream/helpers.Rmd +++ b/workflows/rnaseq/downstream/helpers.Rmd @@ -725,4 +725,42 @@ write.clusterprofiler.results <- function(res, cprof.folder, label){ write.table(res.split, file=filename.split, sep='\t', quote=FALSE, row.names=FALSE) return(list(orig=filename.orig, split=filename.split)) } + +#' Creates heatmap for ranking raw foldchange for no-replicate studies +#' +#' @param rld DESeqTransform object output by varianceStabilizingTransformation() or rlog() +#' @param cond.A Vector of sample or samples corresponding to first condition of desired contrast +#' @param cond.B Vector of sample or samples corresponding to second condition of desired contrast +#' @param symbol.mappings named character vector mapping gene symbols to each gene in rld +#' @param n Number of top and bottom genes to include in heatmap +#' @param ... Other arguments to are passed to heatmaply + +create.noreplicate.heatmap <- function(rld, cond.A, cond.B symbol.mappings, n=50){ + +m <- assay(rld) + +# if more than one replicate for cond.A or cond.B, use the rowMeans of those samples + +if (length(cond.A) == 1){ + x <- m[,cond.A] +} else { + x <- rowMeans(m[,cond.A]) +} + +if (length(cond.B) == 1){ + mn <- m[,cond.B] +} else { + mn <- rowMeans(m[,cond.B]) +} + +fc <- x/mn +o <- order(fc) +top <- o[1:n] +bot <- rev(o)[1:n] + +rownames(m) <- symbol.mappings + +heatmaply(m[c(top, bot),], scale='row', ...) + + ``` From 878a378795a69cc11ab473e98539a37a890e145a Mon Sep 17 00:00:00 2001 From: hertafeldsr Date: Mon, 18 May 2020 10:29:01 -0400 Subject: [PATCH 2/2] minor debugging --- workflows/rnaseq/downstream/helpers.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/workflows/rnaseq/downstream/helpers.Rmd b/workflows/rnaseq/downstream/helpers.Rmd index 351cd5efd..25116cefd 100644 --- a/workflows/rnaseq/downstream/helpers.Rmd +++ b/workflows/rnaseq/downstream/helpers.Rmd @@ -735,7 +735,7 @@ write.clusterprofiler.results <- function(res, cprof.folder, label){ #' @param n Number of top and bottom genes to include in heatmap #' @param ... Other arguments to are passed to heatmaply -create.noreplicate.heatmap <- function(rld, cond.A, cond.B symbol.mappings, n=50){ +create.noreplicate.heatmap <- function(rld, cond.A, cond., symbol.mappings, n=50){ m <- assay(rld) @@ -762,5 +762,5 @@ rownames(m) <- symbol.mappings heatmaply(m[c(top, bot),], scale='row', ...) - +} ```