annotate scripts/estimateprops.R @ 2:577435e5e6b2 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
author bgruening
date Sat, 29 Jan 2022 12:51:27 +0000
parents 817eb707bbf4
children 8c64a2da3869
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
1 suppressWarnings(suppressPackageStartupMessages(library(xbioc)))
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
2 suppressWarnings(suppressPackageStartupMessages(library(MuSiC)))
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
3 suppressWarnings(suppressPackageStartupMessages(library(reshape2)))
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
4 suppressWarnings(suppressPackageStartupMessages(library(cowplot)))
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
5 ## We use this script to estimate the effectiveness of proportion methods
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
6
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
7 ## Load Conf
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
8 args <- commandArgs(trailingOnly = TRUE)
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
9 source(args[1])
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
10
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
11 ## Estimate cell type proportions
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
12 est_prop <- music_prop(
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
13 bulk.eset = bulk_eset, sc.eset = scrna_eset,
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
14 clusters = celltypes_label,
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
15 samples = samples_label, select.ct = celltypes, verbose = T)
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
16
1
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
17 estimated_music_props <- est_prop$Est.prop.weighted
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
18 estimated_nnls_props <- est_prop$Est.prop.allgene
0
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
19
2
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
20 scale_yaxes <- function(gplot, value) {
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
21 if (is.na(value)) {
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
22 gplot
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
23 } else {
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
24 gplot + scale_y_continuous(lim = c(0, value))
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
25 }
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
26 }
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
27
0
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
28 ## Show different in estimation methods
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
29 ## Jitter plot of estimated cell type proportions
2
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
30 jitter_fig <- scale_yaxes(Jitter_Est(
1
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
31 list(data.matrix(estimated_music_props),
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
32 data.matrix(estimated_nnls_props)),
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
33 method.name = methods, title = "Jitter plot of Est Proportions",
2
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
34 size = 2, alpha = 0.7) + theme_minimal(), maxyscale)
0
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
35
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
36
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
37 ## Make a Plot
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
38 ## A more sophisticated jitter plot is provided as below. We separated
1
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
39 ## the T2D subjects and normal subjects by their disease factor levels.
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
40 estimated_music_props_flat <- melt(estimated_music_props)
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
41 estimated_nnls_props_flat <- melt(estimated_nnls_props)
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
42
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
43 m_prop <- rbind(estimated_music_props_flat,
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
44 estimated_nnls_props_flat)
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
45 colnames(m_prop) <- c("Sub", "CellType", "Prop")
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
46
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
47 if (is.null(celltypes)) {
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
48 celltypes <- levels(m_prop$CellType)
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
49 message("No celltypes declared, using:")
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
50 message(celltypes)
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
51 }
0
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
52
1
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
53 if (is.null(phenotype_factors)) {
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
54 phenotype_factors <- colnames(pData(bulk_eset))
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
55 }
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
56 ## filter out unwanted factors like "sampleID" and "subjectName"
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
57 phenotype_factors <- phenotype_factors[
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
58 !(phenotype_factors %in% phenotype_factors_always_exclude)]
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
59 message("Phenotype Factors to use:")
2
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
60 message(paste0(phenotype_factors, collapse = ", "))
0
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
61
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
62 m_prop$CellType <- factor(m_prop$CellType, levels = celltypes) # nolint
1
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
63 m_prop$Method <- factor(rep(methods, each = nrow(estimated_music_props_flat)), # nolint
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
64 levels = methods)
2
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
65
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
66 if (use_disease_factor) {
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
67
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
68 if (phenotype_target_threshold == -99) {
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
69 phenotype_target_threshold <- -Inf
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
70 message("phenotype target threshold set to -Inf")
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
71 }
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
72
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
73 m_prop$Disease_factor <- rep(bulk_eset[[phenotype_target]], 2 * length(celltypes)) # nolint
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
74 m_prop <- m_prop[!is.na(m_prop$Disease_factor), ]
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
75 ## Generate a TRUE/FALSE table of Normal == 1 and Disease == 2
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
76 sample_groups <- c("Normal", sample_disease_group)
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
77 m_prop$Disease <- factor(sample_groups[(m_prop$Disease_factor > phenotype_target_threshold) + 1], # nolint
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
78 levels = sample_groups)
0
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
79
2
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
80 ## Binary to scale: e.g. TRUE / 5 = 0.2
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
81 m_prop$D <- (m_prop$Disease == # nolint
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
82 sample_disease_group) / sample_disease_group_scale
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
83 ## NA's are not included in the comparison below
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
84 m_prop <- rbind(subset(m_prop, Disease != sample_disease_group),
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
85 subset(m_prop, Disease == sample_disease_group))
0
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
86
2
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
87 jitter_new <- scale_yaxes(ggplot(m_prop, aes(Method, Prop)) +
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
88 geom_point(aes(fill = Method, color = Disease, stroke = D, shape = Disease),
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
89 size = 2, alpha = 0.7,
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
90 position = position_jitter(width = 0.25, height = 0)) +
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
91 facet_wrap(~ CellType, scales = "free") +
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
92 scale_colour_manual(values = c("white", "gray20")) +
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
93 scale_shape_manual(values = c(21, 24)) + theme_minimal(), maxyscale)
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
94
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
95 }
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
96
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
97 if (use_disease_factor) {
0
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
98
2
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
99 ## Plot to compare method effectiveness
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
100 ## Create dataframe for beta cell proportions and Disease_factor levels
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
101 ## - Ugly code. Essentially, doubles the cell type proportions for each
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
102 ## set of MuSiC and NNLS methods
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
103 m_prop_ana <- data.frame(pData(bulk_eset)[rep(1:nrow(estimated_music_props), 2), #nolint
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
104 phenotype_factors],
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
105 ## get proportions of target cell type
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
106 ct.prop = c(estimated_music_props[, phenotype_scrna_target],
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
107 estimated_nnls_props[, phenotype_scrna_target]),
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
108 ##
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
109 Method = factor(rep(methods,
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
110 each = nrow(estimated_music_props)),
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
111 levels = methods))
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
112 ## - fix headers
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
113 colnames(m_prop_ana)[1:length(phenotype_factors)] <- phenotype_factors #nolint
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
114 ## - drop NA for target phenotype (e.g. hba1c)
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
115 m_prop_ana <- subset(m_prop_ana, !is.na(m_prop_ana[phenotype_target]))
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
116 m_prop_ana$Disease <- factor( # nolint
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
117 ## - Here we set Normal/Disease assignments across the two MuSiC and NNLS methods
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
118 sample_groups[(
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
119 m_prop_ana[phenotype_target] > phenotype_target_threshold) + 1
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
120 ],
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
121 sample_groups)
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
122 ## - Then we scale this binary assignment to a plotable factor
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
123 m_prop_ana$D <- (m_prop_ana$Disease == # nolint
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
124 sample_disease_group) / sample_disease_group_scale
0
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
125
2
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
126 jitt_compare <- scale_yaxes(ggplot(m_prop_ana, aes_string(phenotype_target, "ct.prop")) +
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
127 geom_smooth(method = "lm", se = FALSE, col = "black", lwd = 0.25) +
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
128 geom_point(aes(fill = Method, color = Disease, stroke = D, shape = Disease),
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
129 size = 2, alpha = 0.7) + facet_wrap(~ Method) +
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
130 ggtitle(paste0(toupper(phenotype_target), " vs. ",
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
131 toupper(phenotype_scrna_target), " Cell Type Proportion")) +
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
132 theme_minimal() +
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
133 ylab(paste0("Proportion of ",
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
134 phenotype_scrna_target, " cells")) +
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
135 xlab(paste0("Level of bulk factor (", phenotype_target, ")")) +
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
136 scale_colour_manual(values = c("white", "gray20")) +
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
137 scale_shape_manual(values = c(21, 24)), maxyscale)
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
138 }
0
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
139
1
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
140 ## BoxPlot
2
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
141 plot_box <- scale_yaxes(Boxplot_Est(list(
1
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
142 data.matrix(estimated_music_props),
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
143 data.matrix(estimated_nnls_props)),
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
144 method.name = c("MuSiC", "NNLS")) +
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
145 theme(axis.text.x = element_text(angle = -90),
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
146 axis.text.y = element_text(size = 8)) +
2
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
147 ggtitle(element_blank()) + theme_minimal(), maxyscale)
1
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
148
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
149 ## Heatmap
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
150 plot_hmap <- Prop_heat_Est(list(
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
151 data.matrix(estimated_music_props),
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
152 data.matrix(estimated_nnls_props)),
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
153 method.name = c("MuSiC", "NNLS")) +
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
154 theme(axis.text.x = element_text(angle = -90),
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
155 axis.text.y = element_text(size = 6))
0
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
156
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
157 pdf(file = outfile_pdf, width = 8, height = 8)
2
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
158 if (length(celltypes) <= 8) {
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
159 plot_grid(jitter_fig, plot_box, labels = "auto", ncol = 1, nrow = 2)
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
160 } else {
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
161 print(jitter_fig)
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
162 plot_box
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
163 }
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
164 if (use_disease_factor) {
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
165 plot_grid(jitter_new, jitt_compare, labels = "auto", ncol = 1, nrow = 2)
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
166 }
1
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
167 plot_hmap
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
168 message(dev.off())
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
169
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
170 ## Output Proportions
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
171
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
172 write.table(est_prop$Est.prop.weighted,
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
173 file = paste0("report_data/prop_",
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
174 "Music Estimated Proportions of Cell Types",
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
175 ".tabular"),
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
176 quote = F, sep = "\t", col.names = NA)
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
177 write.table(est_prop$Est.prop.allgene,
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
178 file = paste0("report_data/prop_",
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
179 "NNLS Estimated Proportions of Cell Types",
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
180 ".tabular"),
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
181 quote = F, sep = "\t", col.names = NA)
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
182 write.table(est_prop$Weight.gene,
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
183 file = paste0("report_data/weightgene_",
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
184 "Music Estimated Proportions of Cell Types (by Gene)",
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
185 ".tabular"),
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
186 quote = F, sep = "\t", col.names = NA)
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
187 write.table(est_prop$r.squared.full,
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
188 file = paste0("report_data/rsquared_",
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
189 "Music R-sqr Estimated Proportions of Each Subject",
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
190 ".tabular"),
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
191 quote = F, sep = "\t", col.names = NA)
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
192 write.table(est_prop$Var.prop,
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
193 file = paste0("report_data/varprop_",
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
194 "Matrix of Variance of MuSiC Estimates",
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
195 ".tabular"),
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
196 quote = F, sep = "\t", col.names = NA)
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
197
0
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
198
2
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
199 if (use_disease_factor) {
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
200 ## Summary table of linear regressions of disease factors
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
201 for (meth in methods) {
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
202 ##lm_beta_meth = lm(ct.prop ~ age + bmi + hba1c + gender, data =
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
203 sub_data <- subset(m_prop_ana, Method == meth)
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
204
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
205 ## We can only do regression where there are more than 1 factors
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
206 ## so we must find and exclude the ones which are not
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
207 gt1_facts <- sapply(phenotype_factors, function(facname) {
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
208 return(length(unique(sort(sub_data[[facname]]))) == 1)
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
209 })
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
210 form_factors <- phenotype_factors
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
211 exclude_facts <- names(gt1_facts)[gt1_facts]
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
212 if (length(exclude_facts) > 0) {
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
213 message("Factors with only one level will be excluded:")
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
214 message(exclude_facts)
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
215 form_factors <- phenotype_factors[
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
216 !(phenotype_factors %in% exclude_facts)]
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
217 }
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
218 lm_beta_meth <- lm(as.formula(
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
219 paste("ct.prop", paste(form_factors, collapse = " + "),
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
220 sep = " ~ ")), data = sub_data)
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
221 message(paste0("Summary: ", meth))
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
222 capture.output(summary(lm_beta_meth),
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
223 file = paste0("report_data/summ_Log of ",
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
224 meth,
577435e5e6b2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
225 " fitting.txt"))
1
817eb707bbf4 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
226 }
0
2fed32b5aa02 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
227 }