forked from willgryan/3PodR_bookdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
01-overview.Rmd
148 lines (126 loc) · 3.33 KB
/
01-overview.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Overview
This is an overview of the transcriptomic data.
<!-- ## Experimental Design -->
```{r, results='asis'}
if(global_state$using_counts) {
global_state$design %>%
knitr::knit_child(
text = c('',
'```{r}',
'make_table(.)',
'```',
''),
envir = environment(),
quiet = TRUE
) %>%
c("\n\n## Experimental Design\n\n", .) %>%
cat(sep = "\n")
}
```
<!-- ## Sample PCA -->
```{r, results='asis'}
#Input: global state
pca_plot <- function(X) {
plot_data = X$counts %>%
column_to_rownames("Symbol") %>%
t() %>%
prcomp(center = T, scale. = T)
plot = plot_data %>%
fviz_pca_ind(
repel = TRUE,
habillage = X$design %>% dplyr::pull(Group),
addEllipses = T) + ggtitle(NULL)
plot
}
if (global_state$using_counts) {
global_state %>%
knitr::knit_child(
text = c('',
'```{r}',
'pca_plot(.)',
'```',
''),
envir = environment(),
quiet = TRUE) %>%
c("\n\n## Sample PCA\n\n", .) %>%
cat(sep = "\n")
}
```
<!-- ## Gene Expression Heatmap -->
```{r, results='asis'}
#Input: global_state
variable_genes_heatmap <- function(X, n = 500) {
mat = X$counts %>%
column_to_rownames(var = "Symbol") %>%
as.matrix()
indices = apply(mat, 1, var) %>%
order(decreasing = T)
mat = mat[indices[1:500], ]
mat = t(scale(t(mat)))
row_order = seriate(dist(mat), method = "TSP") %>% get_order()
min = min(mat, na.rm = T)
max = max(mat, na.rm = T)
lgd = ComplexHeatmap::Legend(
title = NULL,
col_fun = circlize::colorRamp2(c(min, 0, max), c("blue", "white", "red")),
at = c(min, 0, max),
labels = c(round(min, 2), 0, round(max, 2)),
direction = "vertical",
labels_gp = grid::gpar(fontsize = 8)
)
group_data = X$design$Group %>% as.factor()
group_cols = distinctColorPalette(k = nlevels(group_data)) %>% set_names(levels(group_data))
annotation = ComplexHeatmap::HeatmapAnnotation(
Group = group_data,
show_annotation_name = F,
col = list(Group = group_cols),
annotation_legend_param = list(
Group = list(
color_bar = "discrete",
title = NULL,
direction = "horizontal",
title_position = "topcenter",
title_gp = grid::gpar(fontsize = 8),
labels_gp = grid::gpar(fontsize = 8),
nrow = 1
)
)
)
ht = ComplexHeatmap::Heatmap(
mat,
row_order = row_order,
top_annotation = annotation,
column_names_rot = 45,
column_names_gp = grid::gpar(fontsize = 8),
show_row_names = FALSE,
show_row_dend = FALSE,
show_heatmap_legend = FALSE
)
ComplexHeatmap::draw(
ht,
padding = unit(c(2, 15, 2, 2), "mm"),
heatmap_legend_list = lgd,
heatmap_legend_side = "right",
annotation_legend_side = "top"
)
}
if (global_state$using_counts) {
global_state %>%
knitr::knit_child(
text = c('',
'```{r}',
'variable_genes_heatmap(.)',
'```',
''),
envir = environment(),
quiet = TRUE
) %>%
c("\n\n## Gene Expression Heatmap\n\n", .) %>%
cat(sep = "\n")
}
```
## Comparisons
These are experimental comparisons analyzed in the report.
```{r}
make_table(tibble(Comparison = names(global_state$data)))
```