forked from YutingPKU/SingleCell-Multiomics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndividualBatchEffectExploration.Rmd
68 lines (47 loc) · 1.67 KB
/
IndividualBatchEffectExploration.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
# Seurat Individual Batch Effect Exploration
## Descripiton
Explore the individual batch effect by
* Dimplot split by individual
* Fractions of individuals per cluster
## Load seurat object
```{r, cache=TRUE}
combined <- get(load('data/Demo_CombinedSeurat_SCT_Preprocess.RData'))
```
## Explore individual distribution by `Dimplot`
```{r Dimplot, cache=TRUE}
Idents(object = combined) <- 'Individual'
DimPlot(object = combined, reduction = "umap", label = T)
DimPlot(object = combined, reduction = "tsne", label = T)
```
## Calculate individual distribution per cluster with different resolution
```{r histogram, cache=TRUE}
df <- data.table([email protected])
sel.meta <- c("Individual", str_c('SCT_snn_res.', c(1, 1.5, 1.8)))
df <- df[, sel.meta, with = FALSE]
df[, 2:4] %>% imap(~ {
freq1 <- df[, .N, keyby = .(.x, Individual)]
freq1[, total := sum(N), by = .(.x)]
freq1[, ratio := N / total]
linesize = .35
fontsize = 8
ggplot(freq1, aes(fill = Individual, y = ratio, x = .x)) +
geom_bar(position = "stack", stat = "identity") +
scale_fill_brewer(palette = "Dark2") +
xlab('Clsuter') +
ggtitle(.y) +
scale_y_continuous(breaks = seq(0, 1, 0.1),
expand = c(0, 0),
name = 'Percentage') +
theme_bw() +
theme(
panel.grid.major.x = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor = element_blank(),
strip.background = element_blank(),
panel.border = element_rect(size = linesize),
axis.ticks = element_blank(),
axis.text.x = element_text(size = 5)
) +
coord_flip()
})
```