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