forked from janschleicher/DICSIT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdifferential_expression_blish_S100A8.Rmd
111 lines (94 loc) · 4.24 KB
/
differential_expression_blish_S100A8.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
---
title: "Differential expression analysis for selected cells in the COVID S100A8 regression"
author: "Jan Schleicher"
output:
github_document:
toc: true
toc_depth: 2
---
```{r, include=FALSE}
knitr::opts_chunk$set(
collapse = FALSE,
message=FALSE
)
```
```{r setup, message=FALSE, warning=FALSE}
library(Seurat)
library(dplyr)
library(reshape2)
library(ggplot2)
library(introdataviz)
library(future)
plan("multisession", workers = 4)
library(data.table)
```
```{r, include=FALSE}
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
```
## Loading the data
For this analysis, we load the Seurat object containing the COVID-19 data from [Wilk et al. 2021](https://doi.org/10.1084/jem.20210582) and the extracted filter response from the S100A8 regression.
```{r loading}
blish <- readRDS("../data/blish_seurat.rds")
filter_response <- read.csv("../output/filter_responses/blish_S100A8_filter_response.csv",
row.names = 1)
```
## Identifying selected cells
We add selected cells, i.e., cells with a filter response that is larger than $0.3 \times (\text{maximum filter response})$.
```{r selected_cells}
threshold = .3
filter_response$selected_filter_0 <- filter_response$response_filter_0 > threshold *
max(filter_response$response_filter_0)
cat("Number of selected cells for filter 0:", sum(filter_response$selected_filter_0))
blish <- AddMetaData(blish, filter_response)
DimPlot(blish, cells.highlight = WhichCells(blish, expression = selected_filter_0), reduction = "umap")
coarse_cell_type_selected_0 <- paste([email protected]$cell.type.coarse, [email protected]$selected_filter_0)
names(coarse_cell_type_selected_0) <- row.names([email protected])
blish <- AddMetaData(blish, coarse_cell_type_selected_0, col.name = "coarse_cell_type_selected_0")
```
## Analysing differential expression between selected and unselected cells
For a detailed characterization of selected cells, we determined differentially expressed genes between selected and unselected cells of the same type. We did this analysis for the most highly enriched selected cell types.
```{r functions}
extract_data_for_violin <- function(adata, genes, cell_type_field, cell_types) {
selected_cells <- row.names([email protected][apply(adata[[cell_type_field]], 1, function(x) x %in% cell_types),])
data <- FetchData(adata, vars = c(genes, cell_type_field), cells = selected_cells, slot = "data")
return(reshape2::melt(data, id.vars = cell_type_field, variable.name = "gene", value.name = "expression"))
}
make_violin_plot <- function(adata, genes, cell_type_field, cell_types, title, base_size=12, palette="Set2") {
p <- ggplot(extract_data_for_violin(adata, genes, cell_type_field, cell_types),
aes(x = gene, y = expression, fill = get(cell_type_field))) +
geom_split_violin(scale = "width",
trim = T) +
scale_fill_brewer(name = "selected", labels = c("false", "true"), palette = palette) +
theme_classic(base_size = base_size) +
theme(plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title=title)
return(p)
}
```
```{r de_analysis}
filt <- "coarse_cell_type_selected_0"
cell_types <- c("Developing neutrophil", "PB")
cat("Identifying markers for", filt, "\n")
Idents(blish) <- filt
for (ct in cell_types) {
print(ct)
cat("...identifying markers for selected", ct, "cells \n")
markers <- FindMarkers(blish, ident.1 = paste(ct, "TRUE", sep = " "),
ident.2 = paste(ct, "FALSE", sep = " "))
markers <- markers[markers["p_val_adj"] < 0.05,]
markers <- cbind(gene = row.names(markers), markers)
fwrite(markers, file = paste("../output/tables/blish_S100A8", filt,
gsub(",*\\s|/", "_", ct), "deg.csv",
sep = "_"))
p <- make_violin_plot(blish,
row.names(head(markers[-grep('^MT-', rownames(markers)),], n = 6)),
filt, c(paste(ct, "TRUE", sep = " "), paste(ct, "FALSE", sep = " ")),
ct, base_size = 14, palette = "Paired")
print(p)
svg(paste("../output/figures/blish_S100A8/blish_S100A8", filt,
gsub(",*\\s|/", "_", ct), "deg.svg", sep = "_"), width = 4, height = 4)
print(p)
dev.off()
}
```