-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.R
executable file
·63 lines (49 loc) · 2.01 KB
/
run.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
60
61
62
63
#!/usr/local/bin/Rscript
task <- dyncli::main()
library(dplyr, warn.conflicts = FALSE)
library(purrr, warn.conflicts = FALSE)
library(rstan, warn.conflicts = FALSE)
library(coda, warn.conflicts = FALSE)
library(MCMCglmm, warn.conflicts = FALSE)
library(dyndimred, warn.conflicts = FALSE)
# ____________________________________________________________________________
# Load data ####
parameters <- task$parameters
expression <- task$expression
# ____________________________________________________________________________
# Infer trajectory ####
# perform dimreds
dimred_names <- parameters$dimreds
spaces <- map(dimred_names, ~ dyndimred::dimred(expression, method = ., ndim = 2)) # only 2 dimensions per dimred are allowed
# TIMING: done with preproc
checkpoints <- list(method_afterpreproc = as.numeric(Sys.time()))
# fit probabilistic pseudotime model
fit <- pseudogp::fitPseudotime(
X = spaces,
smoothing_alpha = parameters$smoothing_alpha,
smoothing_beta = parameters$smoothing_beta,
iter = parameters$iter,
chains = parameters$chains,
initialise_from = parameters$initialise_from,
pseudotime_var = parameters$pseudotime_var,
pseudotime_mean = parameters$pseudotime_mean
)
# TIMING: done with method
checkpoints$method_aftermethod <- as.numeric(Sys.time())
# extract pseudotime
pst <- rstan::extract(fit, pars = "t")$t
tmcmc <- coda::mcmc(pst)
pseudotime <- MCMCglmm::posterior.mode(tmcmc) %>%
setNames(rownames(expression))
# return output
output <- lst(
cell_ids = names(pseudotime),
pseudotime = pseudotime,
timings = checkpoints
)
# ____________________________________________________________________________
# Save output ####
dynwrap::wrap_data(cell_ids = names(pseudotime)) %>%
dynwrap::add_linear_trajectory(pseudotime = pseudotime) %>%
dynwrap::add_timings(checkpoints) %>%
dyncli::write_output(task$output)