Commit 3701a796 authored by Lena Hersemann's avatar Lena Hersemann

fixed norm count mean per condition

parent e49c69ea
......@@ -541,26 +541,28 @@ normCounts %>% write_tsv(paste0(resultsBase, "sizefac_normalized_counts_by_repli
# Calculation of the base means per condition
#https://stat.ethz.ch/R-manual/R-devel/library/base/html/attr.html
#conSamplesOrdered = levels(dds$sample)
conSamplesOrdered = as_df(exDesign)[, contrastAttribute] %>% unique
baseMeanPerLvl = sapply(conSamplesOrdered, function(lvl) rowMeans(counts(dds, normalized = TRUE)[, conSamplesOrdered == lvl, drop = FALSE])) %>%
meanNormCounts = counts(dds, normalized = TRUE) %>%
as_df %>%
rownames_to_column("ensembl_gene_id") %>%
tbl_df
tbl_df %>%
gather(replicate, norm_count, - ensembl_gene_id) %>%
inner_join(exDesign) %>%
group_by(ensembl_gene_id, condition) %>%
summarize(mean_norm_count = mean(norm_count))
## add base means to diff??ex summary
#numResultsBeforeMerge = nrow(deResults)
deResults = baseMeanPerLvl %>%
gather(condition, norm_count, - ensembl_gene_id) %>%
deResults = meanNormCounts %>%
# gather(condition, norm_count, - ensembl_gene_id) %>%
inner_join(., ., by = "ensembl_gene_id", suffix = c("_1", "_2")) %>%
# filter(ac(condition_1)<ac(condition_2)) %>%
# add diffex status
inner_join(deResults)
#+ fig.width=16, fig.height=14
deResults %>% ggplot(aes(0.5 * log2(norm_count_1 * norm_count_2), log2(norm_count_2 / norm_count_1), color = pvalue < 0.05)) +
deResults %>% ggplot(aes(0.5 * log2(mean_norm_count_1 * mean_norm_count_2), log2(mean_norm_count_2 / mean_norm_count_1), color = pvalue < 0.05)) +
geom_point(alpha = 0.1) +
geom_hline(yintercept = 0, color = "red") +
facet_grid(condition_1 ~ condition_2)
......
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