annotate scripts/compare.R @ 4:282819d09a4f draft

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