Skip to content

Commit 049b422

Browse files
authored
Merge pull request #35 from DocTeedee/fix-heatmap-syntax
capstoneanalysis_kweku.rmd
2 parents 28b0b19 + 8d7fd5f commit 049b422

1 file changed

Lines changed: 69 additions & 9 deletions

File tree

vignettes/capstoneanalysis_kweku.rmd

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,21 @@ names(dat)
3838
```
3939

4040
```{r}
41+
#library(tidyverse)
42+
#condition_of_interest <- c("irritable bowel syndrome")
43+
#efo <- bugsigdbr::getOntology("efo")
44+
#dat_condition <- bugsigdbr::subsetByOntology(dat, column = "Condition", "irritable bowel syndrome", efo) %>%
45+
# mutate(comparison1 = paste(`Group 0 name`, `Group 1 name`, sep = " vs "))
4146
library(tidyverse)
42-
condition_of_interest <- c("irritable bowel syndrome")
43-
efo <- bugsigdbr::getOntology("efo")
44-
dat_condition <- bugsigdbr::subsetByOntology(dat, column = "Condition", "irritable bowel syndrome", efo) %>%
47+
library(bugsigdbr)
48+
dat <- importBugSigDB(cache = TRUE)
49+
50+
dat_condition <- dat %>%
51+
filter(grepl("irritable bowel syndrome", Condition, ignore.case = TRUE)) %>%
4552
mutate(comparison1 = paste(`Group 0 name`, `Group 1 name`, sep = " vs "))
53+
54+
nrow(dat_condition)
55+
head(dat_condition)
4656
```
4757

4858

@@ -100,14 +110,18 @@ jmat <- BugSigDBStats::calcJaccardSimilarity(allsigs)
100110

101111
```{r, fig.width=20, fig.height=20}
102112
library(ComplexHeatmap)
113+
siglengths <- siglengths[rownames(jmat)]
114+
print(paste("jmat dimensions:", nrow(jmat), "x", ncol(jmat)))
115+
print(paste("siglengths length:", length(siglengths)))
103116
ha <- HeatmapAnnotation(`Signature Length` = anno_barplot(siglengths))
104117
hr <- rowAnnotation(`Signature Length` = anno_barplot(siglengths))
118+
105119
hm <- Heatmap(
106120
jmat,
107-
top_annotation = ha, left_annotation = hr,
121+
top_annotation = ha,
122+
left_annotation = hr,
108123
row_names_max_width = unit(20, "cm"),
109124
column_names_max_height = unit(20, "cm"),
110-
# row_labels = sub(".+:", "", rownames(jmat)), #get rid of study labels
111125
column_labels = sub(".+:", "", colnames(jmat))
112126
)
113127
hm
@@ -116,8 +130,26 @@ hm
116130
Use this interactively to make an interactive heatmap. Some expanding of the default size is required to see anything. Creating a sub-heatmap, then exporting it as a table, allows in-depth identification of the subgroups.
117131

118132
```{r, eval = FALSE}
133+
#library(InteractiveComplexHeatmap)
134+
#hm <- draw(hm)
135+
#htShiny(hm)
136+
# Interactive heatmap version
137+
library(ComplexHeatmap)
119138
library(InteractiveComplexHeatmap)
120-
hm <- draw(hm)
139+
siglengths <- siglengths[rownames(jmat)]
140+
141+
ha <- HeatmapAnnotation(`Signature Length` = anno_barplot(siglengths))
142+
hr <- rowAnnotation(`Signature Length` = anno_barplot(siglengths))
143+
144+
hm <- Heatmap(
145+
jmat,
146+
name = "Jaccard",
147+
top_annotation = ha,
148+
left_annotation = hr,
149+
show_row_names = FALSE,
150+
show_column_names = FALSE
151+
)
152+
121153
htShiny(hm)
122154
```
123155

@@ -155,25 +187,53 @@ table(cdf[["Bifidobacterium catenulatum"]])
155187
Create another heatmap on correlations of presence/absence of taxa. This is not necessary because the previous Jaccard Index heatmap is probably better, it is just a demonstration of doing something with the taxa presence/absence directly.
156188

157189
```{r, fig.width=20, fig.height=20}
190+
library(ComplexHeatmap)
191+
158192
sigcors <- cor(t(cmat))
159193
siglengths <- sapply(sigs, length)
194+
195+
# FIX: Ensure siglengths matches sigcors
196+
siglengths <- siglengths[rownames(sigcors)]
197+
160198
ha <- HeatmapAnnotation(`Signature Length` = anno_barplot(siglengths))
161199
hr <- rowAnnotation(`Signature Length` = anno_barplot(siglengths))
200+
162201
hm <- Heatmap(
163202
sigcors,
164-
top_annotation = ha, left_annotation = hr,
203+
top_annotation = ha,
204+
left_annotation = hr,
165205
row_names_max_width = unit(20, "cm"),
166206
column_names_max_height = unit(20, "cm"),
167-
# row_labels = sub(".+:", "", rownames(sigcors)), ##removing study just to make signature names legible
168207
column_labels = sub(".+:", "", colnames(sigcors))
169208
)
170209
hm
171210
```
172211

173212
Use this interactively to make an interactive heatmap:
174213
```{r, eval = FALSE}
214+
#library(InteractiveComplexHeatmap)
215+
#hm <- draw(hm)
216+
#htShiny(hm)
217+
library(ComplexHeatmap)
175218
library(InteractiveComplexHeatmap)
176-
hm <- draw(hm)
219+
220+
sigcors <- cor(t(cmat))
221+
siglengths <- sapply(sigs, length)
222+
223+
siglengths <- siglengths[rownames(sigcors)]
224+
225+
ha <- HeatmapAnnotation(`Signature Length` = anno_barplot(siglengths))
226+
hr <- rowAnnotation(`Signature Length` = anno_barplot(siglengths))
227+
228+
hm <- Heatmap(
229+
sigcors,
230+
name = "Correlation",
231+
top_annotation = ha,
232+
left_annotation = hr,
233+
show_row_names = FALSE,
234+
show_column_names = FALSE
235+
)
236+
177237
htShiny(hm)
178238
```
179239

0 commit comments

Comments
 (0)