-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsccomp.Rmd
More file actions
165 lines (129 loc) · 4.92 KB
/
sccomp.Rmd
File metadata and controls
165 lines (129 loc) · 4.92 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
---
title: "Celltype composition with scccomp"
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)
library(knitr)
# Load libraries
library(Seurat)
library(sccomp)
library(SummarizedExperiment)
library(SingleCellExperiment)
library(DEGreport)
library(rmarkdown)
library(tidyverse)
library(data.table)
library(DT)
library(patchwork)
library(pheatmap)
library(ggprism)
library(grafify)
library(future)
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)
}
```
## Load object and subset
```{r}
seurat <- readRDS("data.rds")
subset_seurat <- subset(x = seurat, subset = condition %in% c("Ctrl", "Treat"))
Idents(object = subset_seurat) <- "celltype"
DefaultAssay(subset_seurat) <- "RNA"
```
## Sccomp
To test for differential cell composition we use [sccomp](https://github.com/MangiolaLaboratory/sccomp) a method for differential composition and variability analyses that jointly models data count distribution, compositionality, group-specific variability, and proportion mean–variability association, being aware of outliers.
Our model includes condition (TN vs. cold). For each cell type we get results for the intercept and our factors. We can see the results of the fit, the effects of the factor on composition and variability. You also can see the uncertainty around those effects. In the output table, the estimate columns start with the prefix c_ indicate composition, or with v_ indicate variability (when formula_variability is set). We have not used formula_variability so we only have v_ estimates for our intercept.
```{r}
sccomp_result <-
subset_seurat |>
sccomp_estimate(
formula_composition = ~condition, # change to the right variable
.sample = sample,
.cell_group = celltype, # change to the right variable
bimodal_mean_variability_association = TRUE,
cores = 1
) |>
sccomp_remove_outliers(cores = 1, verbose = FALSE) |> # Optional
sccomp_test()
sccomp_result
```
### Fold Change
```{r}
sccomp_result |>
sccomp_proportional_fold_change(
formula_composition = ~condition,
from = "Ctrl",
to = "Treat"
) |>
select(celltype, statement)
```
### Boxplot of results
Here we see proportion of each cell type in our two groups (TN and cold7). The blue boxplots represent the posterior predictive check. If the model is likely to be descriptively adequate to the data, the blue box plot should roughly overlay with the black box plot, which represents the observed data. Dots indicate samples and outlier samples are coloured in red. Boxplots colored red indicate significant differences in proportion between our groups.
```{r}
sccomp_result |>
sccomp_boxplot(factor = "condition")
```
### 1-D visualization
A plot of estimates of differential composition (c_) on the x-axis. The error bars represent 95% credible intervals. The dashed lines represent the minimal effect that the hypothesis test is based on. An effect is labelled as significant if bigger than the minimal effect according to the 95% credible interval. We get figures for both factors in our model.
```{r}
sccomp_result |>
plot_1D_intervals()
```
# Conclusion
# R Session
Below is the output of the R session used to generate this report. Included is information on R version, OS, and versions of packages installed and used.
```{r sessionInfo}
# Get session information
sessionInfo()
```