annotate scripts/estimateprops.R @ 3:fd7a16d073c5 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:49 +0000
parents 3ca0132c182a
children 56371b5a2da9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
224721e76869 "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)))
224721e76869 "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)))
224721e76869 "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)))
224721e76869 "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)))
224721e76869 "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
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
6
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
7 ## Load Conf
224721e76869 "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)
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
9 source(args[1])
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
10
224721e76869 "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
224721e76869 "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(
224721e76869 "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,
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
14 clusters = celltypes_label,
224721e76869 "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)
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
16
1
3ca0132c182a "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
3ca0132c182a "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
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
19
3
fd7a16d073c5 "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) {
fd7a16d073c5 "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)) {
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
22 gplot
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
23 } else {
fd7a16d073c5 "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))
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
25 }
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
26 }
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
27
0
224721e76869 "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
224721e76869 "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
3
fd7a16d073c5 "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
3ca0132c182a "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),
3ca0132c182a "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)),
3ca0132c182a "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",
3
fd7a16d073c5 "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
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
35
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
36
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
37 ## Make a Plot
224721e76869 "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
3ca0132c182a "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.
3ca0132c182a "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)
3ca0132c182a "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)
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
42
3ca0132c182a "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,
3ca0132c182a "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)
3ca0132c182a "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")
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
46
3ca0132c182a "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)) {
3ca0132c182a "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)
3ca0132c182a "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:")
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
50 message(celltypes)
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
51 }
0
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
52
1
3ca0132c182a "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)) {
3ca0132c182a "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))
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
55 }
3ca0132c182a "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"
3ca0132c182a "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[
3ca0132c182a "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)]
3ca0132c182a "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:")
3
fd7a16d073c5 "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
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
61
224721e76869 "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
3ca0132c182a "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
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
64 levels = methods)
3
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
65
fd7a16d073c5 "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) {
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
67
fd7a16d073c5 "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) {
fd7a16d073c5 "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
fd7a16d073c5 "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")
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
71 }
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
72
fd7a16d073c5 "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
fd7a16d073c5 "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), ]
fd7a16d073c5 "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
fd7a16d073c5 "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)
fd7a16d073c5 "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
fd7a16d073c5 "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
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
79
3
fd7a16d073c5 "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
fd7a16d073c5 "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
fd7a16d073c5 "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
fd7a16d073c5 "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
fd7a16d073c5 "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),
fd7a16d073c5 "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
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
86
3
fd7a16d073c5 "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)) +
fd7a16d073c5 "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),
fd7a16d073c5 "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,
fd7a16d073c5 "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)) +
fd7a16d073c5 "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") +
fd7a16d073c5 "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")) +
fd7a16d073c5 "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)
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
94
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
95 }
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
96
fd7a16d073c5 "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
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
98
3
fd7a16d073c5 "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
fd7a16d073c5 "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
fd7a16d073c5 "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
fd7a16d073c5 "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
fd7a16d073c5 "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
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
104 phenotype_factors],
fd7a16d073c5 "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
fd7a16d073c5 "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],
fd7a16d073c5 "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]),
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
108 ##
fd7a16d073c5 "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,
fd7a16d073c5 "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)),
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
111 levels = methods))
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
112 ## - fix headers
fd7a16d073c5 "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
fd7a16d073c5 "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)
fd7a16d073c5 "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]))
fd7a16d073c5 "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
fd7a16d073c5 "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
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
118 sample_groups[(
fd7a16d073c5 "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
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
120 ],
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
121 sample_groups)
fd7a16d073c5 "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
fd7a16d073c5 "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
fd7a16d073c5 "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
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
125
3
fd7a16d073c5 "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")) +
fd7a16d073c5 "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) +
fd7a16d073c5 "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),
fd7a16d073c5 "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) +
fd7a16d073c5 "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. ",
fd7a16d073c5 "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")) +
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
132 theme_minimal() +
fd7a16d073c5 "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 ",
fd7a16d073c5 "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")) +
fd7a16d073c5 "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, ")")) +
fd7a16d073c5 "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")) +
fd7a16d073c5 "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)
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
138 }
0
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
139
1
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
140 ## BoxPlot
3
fd7a16d073c5 "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
3ca0132c182a "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),
3ca0132c182a "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)),
3ca0132c182a "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")) +
3ca0132c182a "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),
3ca0132c182a "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)) +
3
fd7a16d073c5 "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
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
148
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
149 ## Heatmap
3ca0132c182a "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(
3ca0132c182a "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),
3ca0132c182a "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)),
3ca0132c182a "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")) +
3ca0132c182a "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),
3ca0132c182a "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
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
156
224721e76869 "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)
3
fd7a16d073c5 "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) {
fd7a16d073c5 "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)
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
160 } else {
fd7a16d073c5 "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)
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
162 plot_box
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
163 }
fd7a16d073c5 "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) {
fd7a16d073c5 "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)
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
166 }
1
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
167 plot_hmap
3ca0132c182a "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())
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
169
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
170 ## Output Proportions
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
171
3ca0132c182a "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,
3ca0132c182a "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_",
3ca0132c182a "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",
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
175 ".tabular"),
3ca0132c182a "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)
3ca0132c182a "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,
3ca0132c182a "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_",
3ca0132c182a "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",
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
180 ".tabular"),
3ca0132c182a "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)
3ca0132c182a "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,
3ca0132c182a "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_",
3ca0132c182a "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)",
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
185 ".tabular"),
3ca0132c182a "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)
3ca0132c182a "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,
3ca0132c182a "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_",
3ca0132c182a "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",
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
190 ".tabular"),
3ca0132c182a "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)
3ca0132c182a "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,
3ca0132c182a "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_",
3ca0132c182a "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",
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
195 ".tabular"),
3ca0132c182a "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)
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
197
0
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
198
3
fd7a16d073c5 "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) {
fd7a16d073c5 "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
fd7a16d073c5 "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) {
fd7a16d073c5 "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 =
fd7a16d073c5 "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)
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
204
fd7a16d073c5 "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
fd7a16d073c5 "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
fd7a16d073c5 "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) {
fd7a16d073c5 "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)
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
209 })
fd7a16d073c5 "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
fd7a16d073c5 "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]
fd7a16d073c5 "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) {
fd7a16d073c5 "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:")
fd7a16d073c5 "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)
fd7a16d073c5 "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[
fd7a16d073c5 "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)]
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
217 }
fd7a16d073c5 "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(
fd7a16d073c5 "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 = " + "),
fd7a16d073c5 "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)
fd7a16d073c5 "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))
fd7a16d073c5 "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),
fd7a16d073c5 "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 ",
fd7a16d073c5 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 20f8561478535013e111d982b99639f48f1bea79"
bgruening
parents: 1
diff changeset
224 meth,
fd7a16d073c5 "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
3ca0132c182a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 683bb72ae92b5759a239b7e3bf4c5a229ed35b54"
bgruening
parents: 0
diff changeset
226 }
0
224721e76869 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/music/ commit 08c6fd3885bdfbf8b5c3f4dcc2d04729b577e3e1"
bgruening
parents:
diff changeset
227 }