-
Notifications
You must be signed in to change notification settings - Fork 0
/
bMIND_expr.R
59 lines (49 loc) · 1.68 KB
/
bMIND_expr.R
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
library(MIND)
library(Biobase)
library(dplyr)
library(rjson)
config <- fromJSON(file="configs/glob_config.json")
workdir <- paste(config[["experiment_folder"]], "/results/datasets", sep="")
setwd(workdir)
files <- list.files()
subject_path <- FALSE
for (i in 1:length(files)){
if (grepl("test", files[i], fixed=TRUE)){
test_path <- files[i]}
if (grepl("counts", files[i], fixed=TRUE)){
ref_counts_path <- files[i]
}
if (grepl("celltypes", files[i], fixed=TRUE)){
ref_celltypes_path <- files[i]
}
if (grepl("subject", files[i], fixed=TRUE)){
subject_path <- files[i]
}
}
# Bulk
df_bulk <- read.csv(test_path, row.names=1)
df_bulk <- as.matrix(df_bulk)
# single cell
df <- read.csv(ref_counts_path, row.names=1)
df <- as.matrix(df)
sc_meta <- read.csv(ref_celltypes_path, row.names=1)
subjects <- rep("donor1", dim(sc_meta)[1])
sc_meta$subject <- subjects
if (subject_path){
df_subjects <- read.csv(subject_path, row.names=1)
sc_meta$subject <- df_subjects[,1]
}
colnames(sc_meta) <- c("cellType", "SubjectName")
sc_meta$cellTypeID <- sc_meta$cellType
sc_meta$subjectID <- sc_meta$SubjectName
rownames(sc_meta) <- colnames(df)
prior = get_prior(sc = df, meta_sc = sc_meta)
frac = est_frac(sig = prior$profile, bulk = log2(1+df_bulk))
deconv = bMIND(bulk = log2(1+df_bulk[rownames(prior$profile),]),
frac = frac, profile = prior$profile, covariance = prior$covariance, ncore = 20)
for (i in 1:length(unique(sc_meta$cellType))){
cell_type_label <- unique(sc_meta$cellType)[i]
expr <- deconv$A[,i,]
savename = paste0("results", "bMIND_expr_", cell_type_label, ".csv")
write.csv(expr, savename)
}