-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnuc_06_backgroundmarkers.R
More file actions
73 lines (50 loc) · 1.64 KB
/
nuc_06_backgroundmarkers.R
File metadata and controls
73 lines (50 loc) · 1.64 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
# Copyright (c) [2024] [Ricardo O. Ramirez Flores]
# roramirezf@uni-heidelberg.de
#' In this script we calculate markers of cells
#' using edgeR and pseudobulk profiles of all samples
library(SingleCellExperiment)
library(scater)
library(edgeR)
library(tidyverse)
setwd("/mnt/sds-hd/sd22b002/projects/ines/heart_revremod")
# Importing pb data
pb_data <- read_csv("data/CRC_pseudobulk.csv") %>%
column_to_rownames("...1") %>%
as.matrix() %>%
t()
# Col-data
coldat <- read_csv("data/CRC_pseudobulk_coldata.csv") %>%
dplyr::select(colname, psbulk_n_cells, cell_type, ConditionSimplified, sample_id) %>%
column_to_rownames("colname")
pb_data <- pb_data[,rownames(coldat)]
# Defining cts
cts <- coldat$cell_type %>%
unique() %>%
set_names()
# Pipeline for differential expression
de_res <- map(cts, function(ct) {
print(ct)
ct_meta_data <- coldat %>%
mutate(test_column = ifelse(cell_type == ct, ct, "rest"))
dat <- DGEList(pb_data, samples = DataFrame(ct_meta_data))
keep <- filterByExpr(dat, group = ct_meta_data$test_column)
dat <- dat[keep,]
dat <- calcNormFactors(dat)
design <- model.matrix(~factor(test_column,
levels = c("rest",ct)), dat$samples)
colnames(design) <- c("int", ct)
dat <- estimateDisp(dat, design)
fit <- glmQLFit(dat, design, robust=TRUE)
res <- glmQLFTest(fit, coef=ncol(design))
de_res <- topTags(res, n = Inf) %>%
as.data.frame() %>%
rownames_to_column("gene")
return(de_res)
})
de_res <- de_res %>%
enframe() %>%
unnest()
de_res %>%
dplyr::filter(logFC > 0) %>%
arrange(name, FDR, - logFC) %>%
write_csv(file = "data/CRC_cellmarkers.csv")