annotate scripts/compare.R @ 4:56371b5a2da9 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
author bgruening
date Thu, 10 Feb 2022 12:52:31 +0000
parents
children 2ba99a52bd44
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
1 suppressWarnings(suppressPackageStartupMessages(library(xbioc)))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
2 suppressWarnings(suppressPackageStartupMessages(library(MuSiC)))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
3 suppressWarnings(suppressPackageStartupMessages(library(reshape2)))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
4 suppressWarnings(suppressPackageStartupMessages(library(cowplot)))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
5 ## We use this script to estimate the effectiveness of proportion methods
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
6
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
7 ## Load Conf
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
8 args <- commandArgs(trailingOnly = TRUE)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
9 source(args[1])
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
10
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
11 method_key <- list("MuSiC" = "est_music",
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
12 "NNLS" = "est_nnls")[[est_method]]
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
13
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
14
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
15 scale_yaxes <- function(gplot, value) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
16 if (is.na(value)) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
17 gplot
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
18 } else {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
19 gplot + scale_y_continuous(lim = c(0, value))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
20 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
21 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
22
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
23
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
24 set_factor_data <- function(bulk_data, factor_name = NULL) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
25 if (is.null(factor_name)) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
26 factor_name <- "None" ## change to something plottable
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
27 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
28 pdat <- pData(bulk_data)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
29 sam_fact <- NULL
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
30 if (factor_name %in% colnames(pdat)) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
31 sam_fact <- cbind(rownames(pdat),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
32 as.character(pdat[[factor_name]]))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
33 cat(paste0(" - factor: ", factor_name,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
34 " found in phenotypes\n"))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
35 } else {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
36 ## We assign this as the factor for the entire dataset
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
37 sam_fact <- cbind(rownames(pdat),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
38 factor_name)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
39 cat(paste0(" - factor: assigning \"", factor_name,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
40 "\" to whole dataset\n"))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
41 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
42 colnames(sam_fact) <- c("Samples", "Factors")
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
43 return(as.data.frame(sam_fact))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
44 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
45
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
46 ## Due to limiting sizes, we need to load and unload
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
47 ## possibly very large datasets.
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
48 process_pair <- function(sc_data, bulk_data,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
49 ctypes_label, samples_label, ctypes,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
50 factor_group) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
51 ## - Generate
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
52 est_prop <- music_prop(
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
53 bulk.eset = bulk_data, sc.eset = sc_data,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
54 clusters = ctypes_label,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
55 samples = samples_label, select.ct = ctypes, verbose = T)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
56 ## -
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
57 estimated_music_props <- est_prop$Est.prop.weighted
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
58 estimated_nnls_props <- est_prop$Est.prop.allgene
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
59 ## -
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
60 fact_data <- set_factor_data(bulk_data, factor_group)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
61 ## -
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
62 return(list(est_music = estimated_music_props,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
63 est_nnls = estimated_nnls_props,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
64 bulk_sample_totals = colSums(exprs(bulk_data)),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
65 plot_groups = fact_data))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
66 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
67
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
68 music_on_all <- function(files) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
69 results <- list()
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
70 for (sc_name in names(files)) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
71 cat(paste0("sc-group:", sc_name, "\n"))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
72 scgroup <- files[[sc_name]]
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
73 ## - sc Data
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
74 sc_est <- readRDS(scgroup$dataset)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
75 ## - params
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
76 celltypes_label <- scgroup$label_cell
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
77 samples_label <- scgroup$label_sample
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
78 celltypes <- scgroup$celltype
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
79
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
80 results[[sc_name]] <- list()
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
81 for (bulk_name in names(scgroup$bulk)) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
82 cat(paste0(" - bulk-group:", bulk_name, "\n"))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
83 bulkgroup <- scgroup$bulk[[bulk_name]]
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
84 ## - bulk Data
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
85 bulk_est <- readRDS(bulkgroup$dataset)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
86 ## - bulk params
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
87 pheno_facts <- bulkgroup$pheno_facts
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
88 pheno_excl <- bulkgroup$pheno_excl
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
89 ##
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
90 results[[sc_name]][[bulk_name]] <- process_pair(
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
91 sc_est, bulk_est,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
92 celltypes_label, samples_label,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
93 celltypes, bulkgroup$factor_group)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
94 ##
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
95 rm(bulk_est) ## unload
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
96 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
97 rm(sc_est) ## unload
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
98 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
99 return(results)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
100 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
101
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
102 plot_all_individual_heatmaps <- function(results) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
103 pdf(out_heatmulti_pdf, width = 8, height = 8)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
104 for (sc_name in names(results)) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
105 for (bk_name in names(results[[sc_name]])) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
106 res <- results[[sc_name]][[bk_name]]
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
107 plot_hmap <- Prop_heat_Est(
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
108 data.matrix(res[[method_key]]), method.name = est_method) +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
109 ggtitle(paste0("[", est_method, "Cell type ",
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
110 "proportions in ",
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
111 bk_name, " (Bulk) based on ",
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
112 sc_name, " (scRNA)")) +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
113 xlab("Cell Types (scRNA)") +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
114 ylab("Samples (Bulk)") +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
115 theme(axis.text.x = element_text(angle = -90),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
116 axis.text.y = element_text(size = 6))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
117 print(plot_hmap)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
118 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
119 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
120 dev.off()
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
121 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
122
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
123 merge_factors_spread <- function(grudat_spread, factor_groups) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
124 ## Generated
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
125 merge_it <- function(matr, plot_groups, valname) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
126 ren <- melt(lapply(matr, function(mat) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
127 mat["ct"] <- rownames(mat); return(mat)}))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
128 ## - Grab factors and merge into list
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
129 ren_new <- merge(ren, plot_groups, by.x = "variable", by.y = "Samples")
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
130 colnames(ren_new) <- c("Sample", "Cell", valname, "Bulk", "Factors")
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
131 return(ren_new)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
132 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
133 tab <- merge(merge_it(grudat$spread$prop, factor_groups, "value.prop"),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
134 merge_it(grudat$spread$scale, factor_groups, "value.scale"),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
135 by = c("Sample", "Cell", "Bulk", "Factors"))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
136 return(tab)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
137 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
138
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
139
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
140 plot_grouped_heatmaps <- function(results) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
141 pdf(out_heatmulti_pdf, width = 8, height = 8)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
142 for (sc_name in names(results)) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
143 named_list <- sapply(
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
144 names(results[[sc_name]]),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
145 function(n) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
146 ## We transpose the data here, because
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
147 ## the plotting function omits by default
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
148 ## the Y-axis which are the samples.
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
149 ## Since the celltypes are the common factor
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
150 ## these should be the Y-axis instead.
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
151 t(data.matrix(results[[sc_name]][[n]][[method_key]]))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
152 }, simplify = F, USE.NAMES = T)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
153 named_methods <- names(results[[sc_name]])
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
154 ##
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
155 plot_hmap <- Prop_heat_Est(
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
156 named_list,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
157 method.name = named_methods) +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
158 ggtitle(paste0("[", est_method, "] Cell type ",
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
159 "proportions of ",
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
160 "Bulk Datasets based on ",
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
161 sc_name, " (scRNA)")) +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
162 xlab("Samples (Bulk)") +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
163 ylab("Cell Types (scRNA)") +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
164 theme(axis.text.x = element_text(angle = -90),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
165 axis.text.y = element_text(size = 6))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
166 print(plot_hmap)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
167 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
168 dev.off()
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
169 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
170
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
171 ## Desired plots
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
172 ## 1. Pie chart:
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
173 ## - Per Bulk dataset (using just normalised proportions)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
174 ## - Per Bulk dataset (multiplying proportions by nreads)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
175
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
176 unlist_names <- function(results, method, prepend_bkname=FALSE) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
177 unique(sort(
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
178 unlist(lapply(names(results), function(scname) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
179 lapply(names(results[[scname]]), function(bkname) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
180 res <- get(method)(results[[scname]][[bkname]][[method_key]])
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
181 if (prepend_bkname) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
182 ## We *do not* assume unique bulk sample names
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
183 ## across different bulk datasets.
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
184 res <- paste0(bkname, "::", res)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
185 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
186 return(res)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
187 })
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
188 }))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
189 ))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
190 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
191
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
192 summarized_matrix <- function(results) { # nolint
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
193 ## We assume that cell types MUST be unique, but that sample
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
194 ## names do not need to be. For this reason, we must prepend
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
195 ## the bulk dataset name to the individual sample names.
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
196 all_celltypes <- unlist_names(results, "colnames")
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
197 all_samples <- unlist_names(results, "rownames", prepend_bkname = TRUE)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
198
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
199 ## Iterate through all possible samples and populate a table.
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
200 ddff <- data.frame()
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
201 ddff_scale <- data.frame()
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
202 for (cell in all_celltypes) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
203 for (sample in all_samples) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
204 group_sname <- unlist(strsplit(sample, split = "::"))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
205 bulk <- group_sname[1]
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
206 id_sample <- group_sname[2]
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
207 for (scgroup in names(results)) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
208 if (bulk %in% names(results[[scgroup]])) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
209 mat_prop <- results[[scgroup]][[bulk]][[method_key]]
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
210 vec_counts <- results[[scgroup]][[bulk]]$bulk_sample_totals
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
211 ## - We use sample instead of id_sample because we need to
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
212 ## extract bulk sets from the complete matrix later. It's
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
213 ## messy, yes.
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
214 if (cell %in% colnames(mat_prop)) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
215 ddff[cell, sample] <- mat_prop[id_sample, cell]
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
216 ddff_scale[cell, sample] <- mat_prop[id_sample, cell] * vec_counts[[id_sample]] #nolint
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
217 } else {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
218 ddff[cell, sample] <- 0
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
219 ddff_scale[cell, sample] <- 0
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
220 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
221 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
222 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
223 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
224 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
225 return(list(prop = ddff, scaled = ddff_scale))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
226 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
227
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
228 flatten_factor_list <- function(results) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
229 ## Get a 2d DF of all factors across all bulk samples.
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
230 res <- c()
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
231 for (scgroup in names(results)) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
232 for (bulkgroup in names(results[[scgroup]])) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
233 dat <- results[[scgroup]][[bulkgroup]]$plot_groups
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
234 dat$Samples <- paste0(bulkgroup, "::", dat$Samples) #nolint
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
235 res <- rbind(res, dat)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
236 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
237 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
238 return(res)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
239 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
240
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
241 group_by_dataset <- function(summat) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
242 bulk_names <- unlist(
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
243 lapply(names(files), function(x) names(files[[x]]$bulk)))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
244 mat_names <- colnames(summat$prop)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
245 bd <- list()
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
246 bd_scale <- list()
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
247 bd_spread_scale <- list()
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
248 bd_spread_prop <- list()
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
249 for (bname in bulk_names) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
250 subs <- mat_names[startsWith(mat_names, paste0(bname, "::"))]
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
251 ## -
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
252 bd[[bname]] <- rowSums(summat$prop[, subs])
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
253 bd_scale[[bname]] <- rowSums(summat$scaled[, subs])
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
254 bd_spread_scale[[bname]] <- summat$scaled[, subs]
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
255 bd_spread_prop[[bname]] <- summat$prop[, subs]
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
256 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
257 return(list(prop = as.data.frame(bd),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
258 scaled = as.data.frame(bd_scale),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
259 spread = list(scale = bd_spread_scale,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
260 prop = bd_spread_prop)))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
261 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
262
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
263 summarize_heatmaps <- function(grudat_spread_melt, do_factors) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
264 ## -
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
265 do_single <- function(grudat_melted, yaxis, xaxis, fillval, title,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
266 ylabs = element_blank(), xlabs = element_blank(),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
267 use_log = TRUE, size = 11) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
268 ## Convert from matrix to long format
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
269 melted <- grudat_melted ## copy?
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
270 if (use_log) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
271 melted[[fillval]] <- log10(melted[[fillval]] + 1)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
272 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
273 return(ggplot(melted) +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
274 geom_tile(aes_string(y = yaxis, x = xaxis, fill = fillval),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
275 colour = "white") +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
276 scale_fill_gradient2(low = "steelblue", high = "red",
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
277 mid = "white", name = element_blank()) +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
278 theme(axis.text.x = element_text(angle = -90, hjust = 0,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
279 size = size)) +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
280 ggtitle(label = title) + xlab(xlabs) + ylab(ylabs))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
281 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
282
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
283 do_gridplot <- function(title, xvar, plot="both", ncol=2, size = 11) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
284 do_logged <- (plot %in% c("log", "both"))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
285 do_normal <- (plot %in% c("normal", "both"))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
286 plist <- list()
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
287 if (do_logged) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
288 plist[["1"]] <- do_single(grudat_spread_melt, "Cell", xvar,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
289 "value.scale", "Reads (log10+1)",
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
290 size = size)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
291 plist[["2"]] <- do_single(grudat_spread_melt, "Cell", xvar,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
292 "value.prop", "Sample (log10+1)",
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
293 size = size)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
294 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
295 if (do_normal) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
296 plist[["A"]] <- do_single(grudat_spread_melt, "Cell", xvar,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
297 "value.scale", "Reads", use_log = F,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
298 size = size)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
299 plist[["B"]] <- do_single(grudat_spread_melt, "Cell", xvar,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
300 "value.prop", "Sample", use_log = F,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
301 size = size)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
302 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
303 return(plot_grid(ggdraw() + draw_label(title, fontface = "bold"),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
304 plot_grid(plotlist = plist, ncol = ncol),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
305 ncol = 1, rel_heights = c(0.05, 0.95)))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
306
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
307 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
308 p1 <- do_gridplot("Cell Types vs Bulk Datasets", "Bulk", "both", )
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
309 p2a <- do_gridplot("Cell Types vs Samples", "Sample", "normal", 1,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
310 size = 8)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
311 p2b <- do_gridplot("Cell Types vs Samples (log10+1)", "Sample", "log", 1,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
312 size = 8)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
313 p3 <- ggplot + theme_void()
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
314 if (do_factors) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
315 p3 <- do_gridplot("Cell Types against Factors", "Factors", "both")
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
316 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
317 return(list(bulk = p1,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
318 samples = list(log = p2b, normal = p2a),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
319 factors = p3))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
320 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
321
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
322 summarize_boxplots <- function(grudat_spread, do_factors) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
323 common1 <- ggplot(grudat_spread, aes(x = value.prop)) + ggtitle("Sample") +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
324 xlab(element_blank()) + ylab(element_blank())
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
325 common2 <- ggplot(grudat_spread, aes(x = value.scale)) + ggtitle("Reads") +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
326 xlab(element_blank()) + ylab(element_blank())
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
327
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
328 A <- B <- list() #nolint
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
329 ## Cell type by sample
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
330 A$p1 <- common2 + geom_boxplot(aes(y = Cell, color = Bulk))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
331 A$p2 <- common1 + geom_boxplot(aes(y = Cell, color = Bulk))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
332 ## Sample by Cell type
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
333 B$p1 <- common2 + geom_boxplot(aes(y = Bulk, color = Cell)) +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
334 ylab("Bulk Dataset")
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
335 B$p2 <- common1 + geom_boxplot(aes(y = Bulk, color = Cell)) +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
336 ylab("Bulk Dataset")
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
337 ## -- Factor plots are optional
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
338 A$p3 <- B$p3 <- A$p4 <- B$p4 <- ggplot() + theme_void()
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
339
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
340 if (do_factors) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
341 A$p3 <- common1 + geom_boxplot(aes(y = Cell, color = Factors))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
342 A$p4 <- common2 + geom_boxplot(aes(y = Cell, color = Factors))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
343 B$p3 <- common1 + geom_boxplot(aes(y = Bulk, color = Factors)) +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
344 ylab("Bulk Dataset")
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
345 B$p4 <- common2 + geom_boxplot(aes(y = Bulk, color = Factors)) +
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
346 ylab("Bulk Dataset")
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
347 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
348
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
349 title_a <- "Cell Types against Bulk"
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
350 title_b <- "Bulk Datasets against Cells"
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
351 if (do_factors) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
352 title_a <- paste0(title_a, " and Factors")
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
353 title_b <- paste0(title_b, " and Factors")
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
354 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
355
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
356 a_all <- plot_grid(ggdraw() + draw_label(title_a, fontface = "bold"),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
357 plot_grid(plotlist = A, ncol = 2),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
358 ncol = 1, rel_heights = c(0.05, 0.95))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
359 b_all <- plot_grid(ggdraw() + draw_label(title_b, fontface = "bold"),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
360 plot_grid(plotlist = B, ncol = 2),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
361 ncol = 1, rel_heights = c(0.05, 0.95))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
362 return(list(cell = a_all, bulk = b_all))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
363 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
364
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
365 filter_output <- function(grudat_spread_melt, out_filt) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
366 print_red <- function(comment, red_list) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
367 cat(paste(comment, paste(red_list, collapse = ", "), "\n"))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
368 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
369 grudat_filt <- grudat_spread_melt
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
370 print_red("Total Cell types:", unique(grudat_filt$Cell))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
371 if (!is.null(out_filt$cells)) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
372 grudat_filt <- grudat_filt[grudat_filt$Cell %in% out_filt$cells, ]
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
373 print_red(" - selecting:", out_filt$cells)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
374 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
375 print_red("Total Factors:", unique(grudat_spread_melt$Factors))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
376 if (!is.null(out_filt$facts)) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
377 grudat_filt <- grudat_filt[grudat_filt$Factors %in% out_filt$facts, ]
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
378 print_red(" - selecting:", out_filt$facts)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
379 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
380 return(grudat_filt)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
381 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
382
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
383
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
384 results <- music_on_all(files)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
385
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
386 if (heat_grouped_p) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
387 plot_grouped_heatmaps(results)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
388 } else {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
389 plot_all_individual_heatmaps(results)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
390 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
391
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
392 save.image("/tmp/sesh.rds")
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
393
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
394 summat <- summarized_matrix(results)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
395 grudat <- group_by_dataset(summat)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
396 grudat_spread_melt <- merge_factors_spread(grudat$spread,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
397 flatten_factor_list(results))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
398
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
399
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
400
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
401 ## The output filters ONLY apply to boxplots, since these take
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
402 do_factors <- (length(unique(grudat_spread_melt[["Factors"]])) > 1)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
403
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
404 grudat_spread_melt_filt <- filter_output(grudat_spread_melt, out_filt)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
405
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
406 heat_maps <- summarize_heatmaps(grudat_spread_melt_filt, do_factors)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
407 box_plots <- summarize_boxplots(grudat_spread_melt_filt, do_factors)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
408
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
409 pdf(out_heatsumm_pdf, width = 14, height = 14)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
410 print(heat_maps)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
411 print(box_plots)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
412 dev.off()
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
413
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
414 ## Generate output tables
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
415 stats_prop <- lapply(grudat$spread$prop, function(x) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
416 t(apply(x, 1, summary))})
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
417 stats_scale <- lapply(grudat$spread$scale, function(x) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
418 t(apply(x, 1, summary))})
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
419
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
420 writable2 <- function(obj, prefix, title) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
421 write.table(obj,
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
422 file = paste0("report_data/", prefix, "_",
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
423 title, ".tabular"),
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
424 quote = F, sep = "\t", col.names = NA)
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
425 }
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
426 ## Make the value table printable
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
427 grudat_spread_melt$value.scale <- as.integer(grudat_spread_melt$value.scale) # nolint
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
428 colnames(grudat_spread_melt) <- c("Sample", "Cell", "Bulk", "Factors",
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
429 "CT Prop in Sample", "Number of Reads")
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
430
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
431 writable2(grudat_spread_melt, "values", "Data Table")
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
432 writable2(summat$prop, "values", "Matrix of Cell Type Sample Proportions")
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
433 writable2({
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
434 aa <- as.matrix(summat$scaled); mode(aa) <- "integer"; aa
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
435 }, "values", "Matrix of Cell Type Read Counts")
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
436
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
437 for (bname in names(stats_prop)) {
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
438 writable2(stats_prop[[bname]], "stats", paste0(bname, ": Sample Props"))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
439 writable2(stats_scale[[bname]], "stats", paste0(bname, ": Read Props"))
56371b5a2da9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 8beed1a19fcd9dc59f7746e1dfa735a2d5f29784"
bgruening
parents:
diff changeset
440 }