Commit dc070d46 authored by Holger Brandl's avatar Holger Brandl

added more debugging vis for batch correction util

parent c2046343
......@@ -302,6 +302,11 @@ beta[is.na(beta)] <- 0
# make sure that design bits and betas fit together
stopifnot(t(ncol(beta)) == ncol(design[,-c(1, condColIdx), drop=FALSE]))
# visualize effect of batch correction
load_pack(pheatmap)
# beta %>% pheatmap( show_rownames=F)
beta %*% t(design[,-c(1, condColIdx), drop=FALSE]) %>% { colnames(.)<-exDesign$replicate; . } %>% pheatmap( show_rownames=F, main="batch correction offsets")
bcMatrix <- countMatrix - beta %*% t(design[,-c(1, condColIdx), drop=FALSE])
......@@ -393,6 +398,34 @@ htmltools::tagList(lapply(list("condition"), function(batchFactor) {
}))
########################################################################################################################
#' ## Score distributions
#' Compare the effect of the no
rawLong = countMatrix %>%
as.data.frame() %>%
rownames_to_column("gene_id") %>%
gather(sample, raw_expr, - gene_id)
rawLong %>%ggplot(aes(raw_expr)) + geom_histogram() + ggtitle("unormalized scores")
bcLong= bcMatrix %>%
as.data.frame() %>%
rownames_to_column("gene_id") %>%
gather(sample, norm_expr, - gene_id)
bcLong %>% ggplot(aes(norm_expr)) + geom_histogram() + ggtitle("batch-corrected scores")
inner_join(rawLong, bcLong) %>% ggplot(aes(raw_expr, norm_expr)) +
geom_point(alpha = 0.3) +
geom_abline(slope = 1, color = "red")
#+ fig.height=2*ceiling(nrow(exDesign)/5)
inner_join(rawLong, bcLong) %>% ggplot(aes(raw_expr, norm_expr)) +
geom_point(alpha = 0.1) +
geom_abline(slope = 1, color = "red") +
# coord_equal() +
facet_wrap(~sample, ncol=5) +
ggtitle("correlation of raw vs batch-corrected scores")
########################################################################################################################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment