-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconsistency.R
More file actions
132 lines (107 loc) · 4.29 KB
/
consistency.R
File metadata and controls
132 lines (107 loc) · 4.29 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
library(babelwhale)
library(rhdf5)
library(parallel)
library(RcppHungarian)
EX_SLOW_METHODS <- c("BayesCCE", "DAISM", "BayCount", "debCAM", "DeCompress", "BayesPrism")
SLOW_METHODS <- c("EMeth", "BayICE", "deconvSeq", "CPM", "DWLS", "DESeq2", "spatialDWLS", "deconf", "DecOT", "DeMixT", "digitalDLSorter", "ImmuCellAI", "Linseed", "MOMF", "AdRoit", "NITUMID", "quanTIseq", "scaden", "ARIC")
FAST_METHODS <- c("AutoGeneS", "BisqueMarker", "BisqueRef", "CellDistinguisher", "CIBERSORT", "Deblender", "DeconICA", "DeconPeaker", "DeconRNASeq", "DSA", "dtangle", "EPIC", "FARDEEP", "LinDeconSeq", "MCPcounter", "MethylResolver", "MIXTURE", "MuSic", "MySort", "PREDE", "ReFACTor", "RNA-Sieve", "SCDC", "TOAST", "BseqSC")
ALL_METHODS <- c(FAST_METHODS, SLOW_METHODS, EX_SLOW_METHODS)
PATH_TO_MATLAB_LICENSE <- "/path/to/matlab/license.lic"
DOCKER_TAG_PREFIX <- "deconvolution/"
DOCKER_TAG_SUFFIX <- ":latest"
nRep <- 10
dataFiles <- list.files('./data/sim-tsp') %>%
str_match('([^/]+).rds$') %>%
{ function(x) x[, 2] }()
allConfig <- expand.grid(dataset = dataFiles, method = methods, seed = seq(nRep), stringsAsFactors = F)
# 8 cores, 16GB per job, 12GB softlimit, 12 concurrent jobs, max runtime of 12 hours
dir.create('./results/consistency', showWarnings = F, recursive = T)
res <- lapply(seq_len(nrow(allConfig)), function(i) {
config <- allConfig[i,]
dataFile <- paste0('./data/sim-tsp/', as.character(config$dataset), '.rds')
method <- config$method
seed <- config$seed
resFile <- paste0('./results/consistency/', method, '_', config$dataset, '_', seed, '.rds')
if (file.exists(resFile)) {
res <- readRDS(resFile)
if (!is.null(res$P)) {
return(NULL)
}
}
data <- readRDS(dataFile)
groundTruth <- data$bulkRatio
data <- data[names(data) != "bulkRatio"]
#randomly remove markers and add noise
set.seed(seed)
data$markers <- lapply(data$markers, function(x) sample(x, size = round(length(x) * 0.95), replace = FALSE))
data$sigGenes <- unique(unlist(data$markers))
data$signature <- data$signature[data$sigGenes,]
data$cellTypeExpr <- apply(data$cellTypeExpr, 1, function(x) {
x <- x + rnorm(length(x), mean = 0, sd = sd(x) * 0.01)
x[x < 0] <- 0
x
}) %>% t()
data$signature <- apply(data$signature, 1, function(x) {
x <- x + rnorm(length(x), mean = 0, sd = sd(x) * 0.01)
x[x < 0] <- 0
x
}) %>% t()
data$singleCellExpr <- apply(data$singleCellExpr, 1, function(x) {
x <- x + rnorm(length(x), mean = 0, sd = sd(x) * 0.01)
x[x < 0] <- 0
round(x)
}) %>% t()
data$bulk <- apply(data$bulk, 1, function(x) {
x <- x + rnorm(length(x), mean = 0, sd = sd(x) * 0.01)
x[x < 0] <- 0
x
}) %>% t()
set.seed(i)
start <- Sys.time()
res <- do.call(
runDeconvolution,
c(
list(methods = method, verbose = T, seed = seed,
dockerArgs = c(
'--cpus=8.0',
'-m=16G',
'--memory-reservation=12G'
),
timeout = 12 * 3600,
matlabLicenseFile = PATH_TO_MATLAB_LICENSE),
data
)
)
runningTime <- Sys.time() - start
res <- res[[method]]
res$groundTruth <- groundTruth
res$runningTime <- runningTime
saveRDS(res, file = resFile)
NULL
})
# gather results
allRes <- lapply(seq_len(nrow(allConfig)), function(i) {
config <- allConfig[i,]
method <- config$method
seed <- config$seed
resFile <- paste0('./results/consistency/', method, '_', config$dataset, '_', seed, '.rds')
dataFile <- paste0('./data/sim-tsp/', as.character(config$dataset), '.rds')
if (!file.exists(resFile)) {
return(NULL)
}
res <- readRDS(resFile)
if (is.null(res$P)) return(NULL)
data <- readRDS(dataFile)
groundTruth <- data$bulkRatio
res$MAE <- evaluateResult(res$P, groundTruth, metric="MAE")
res$Corr <- evaluateResult(res$P, groundTruth, metric="Corr")
data.frame(
method = method,
dataset = config$dataset,
seed = seed,
MAE = res$MAE,
Corr = res$Corr,
sample = 1:nrow(res$P)
)
}) %>% do.call(what = rbind)
saveRDS(allRes, file = './results/consistency/allRes.rds')