-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpropeller.Rmd
More file actions
180 lines (142 loc) · 4.28 KB
/
propeller.Rmd
File metadata and controls
180 lines (142 loc) · 4.28 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
---
title: "Celltype composition with Propeller"
author: "Harvard Chan Bioinformatics Core"
date: "`r Sys.Date()`"
output:
html_document:
code_folding: hide
df_print: paged
highlights: pygments
number_sections: true
self_contained: true
theme: default
toc: true
toc_float:
collapsed: true
smooth_scroll: true
params:
project_file: ../information.R
---
```{r, message=FALSE, warning=FALSE}
# This set up the working directory to this file so all files can be found
library(rstudioapi)
library(tidyverse)
setwd(fs::path_dir(getSourceEditorContext()$path))
# NOTE: This code will check version, this is our recommendation, it may work
# . other versions
stopifnot(R.version$major >= 4) # requires R4
if (compareVersion(R.version$minor, "3.1") < 0) warning("We recommend >= R4.3.1")
stopifnot(compareVersion(as.character(BiocManager::version()), "3.18") >= 0)
stopifnot(compareVersion(as.character(packageVersion("Seurat")), "5.0.0") >= 0)
```
This code is in this  revision.
```{r setup, cache=FALSE, message=FALSE, warning=FALSE, echo=FALSE}
# knitr::opts_chunk$set(echo = TRUE)
# Load libraries
library(knitr)
library(rmarkdown)
library(Seurat)
library(SummarizedExperiment)
library(SingleCellExperiment)
library(DEGreport)
library(pheatmap)
library(tidyverse)
library(data.table)
library(DT)
library(patchwork)
library(ggprism)
library(grafify)
library(future)
library(speckle)
# Set seed for reproducibility
set.seed(1454944673L)
opts_chunk[["set"]](
audodep = TRUE,
cache = FALSE,
cache.lazy = FALSE,
error = TRUE,
echo = FALSE,
fig.height = 5L,
fig.retina = 2L,
fig.width = 11,
message = FALSE,
tidy = TRUE,
warning = FALSE
)
ggplot2::theme_set(theme_prism(base_size = 12))
# https://grafify-vignettes.netlify.app/colour_palettes.html
# NOTE change colors here if you wish
scale_colour_discrete <- function(...) {
scale_colour_manual(..., values = as.vector(grafify:::graf_palettes[["kelly"]]))
}
if (future::supportsMulticore()) {
future::plan(future::multicore)
} else {
future::plan(future::multisession)
}
```
```{r sanitize_datatable}
sanitize_datatable <- function(df, ...) {
# remove dashes which cause wrapping
DT::datatable(df, ...,
rownames = gsub("-", "_", rownames(df)),
colnames = gsub("-", "_", colnames(df)),
options = list(scrollX = TRUE, ...)
)
}
```
## Load object and subset
Read in the full dataset Seurat object and subset to keep only cells from the conditions of interest (cold7 vs TN).
```{r load-data}
seurat <- readRDS("data.rds")
subset_seurat <- subset(x = seurat, subset = condition %in% c("Ctrl", "Treat"))
Idents(object = subset_seurat) <- "celltype"
DefaultAssay(subset_seurat) <- "RNA"
# Create metadata df and factor celltype
meta <- subset_seurat@meta.data
meta$celltype <- factor(meta$celltype)
```
## Check count numbers of cells
```{r cellnumbers}
meta$condition_sample <- paste0(meta$condition, "_", meta$sample)
table(meta$condition_sample, meta$celltype)
```
## Run propeller
```{r run-propeller}
# working code; takes into account cell numbers
# NOTE adapt with your variables of interest
propres <- propeller(subset_seurat,
sample = subset_seurat$sample,
clusters = subset_seurat$celltype,
group = subset_seurat$condition
)
sanitize_datatable(propres)
```
## Proportions of cells table
To understand discordance with sccomp results, let's evaluate proportions and variability within group.
```{r}
props <- getTransformedProps(meta$celltype,
meta$condition_sample,
transform = "logit"
)
props$Proportions
```
```{r extracode, eval=FALSE}
meta_propeller <- meta %>%
group_by(condition, sample) %>%
distinct(sample)
designAS <- model.matrix(~ meta_propeller$condition)
colnames(designAS) <- c("Ctrl", "Treat")
fit <- lmFit(props$TransformedProps, designAS)
fit <- eBayes(fit, robust = TRUE)
topTable(fit)
```
# Resources
* [Speckle vignette](http://127.0.0.1:29356/library/speckle/doc/speckle.html#finding-significant-differences-in-cell-type-proportions-using-propeller)
* [Application to mouse PBMC scRNA](https://phipsonlab.github.io/propeller-paper-analysis/RealDataAnalysis.html#Young_vs_Old)
# Conclusion
# R session
List and version of tools used for the QC report generation.
```{r}
sessionInfo()
```