-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.R
executable file
·87 lines (72 loc) · 2.62 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/local/bin/Rscript
task <- dyncli::main()
library(ElPiGraph.R)
library(dplyr)
library(purrr)
library(readr)
# ____________________________________________________________________________
# Load data ####
expression <- as.matrix(task$expression)
parameters <- task$parameters
checkpoints <- list()
checkpoints$method_afterpreproc <- as.numeric(Sys.time())
# ____________________________________________________________________________
# Infer the trajectory ####
principal_graph_function <- computeElasticPrincipalCurve
# infer the principal graph, from https://github.com/Albluca/ElPiGraph.R/blob/master/guides/base.md
principal_graph <- principal_graph_function(
X = expression,
NumNodes = parameters$NumNodes,
NumEdges = parameters$NumEdges,
InitNodes = parameters$InitNodes,
MaxNumberOfIterations = parameters$MaxNumberOfIterations,
eps = parameters$eps,
CenterData = parameters$CenterData,
Lambda = parameters$Lambda,
Mu = parameters$Mu,
drawAccuracyComplexity = FALSE,
drawEnergy = FALSE,
drawPCAView = FALSE,
n.cores = 1
)
# compute pseudotime, from https://github.com/Albluca/ElPiGraph.R/blob/master/guides/pseudo.md
PartStruct <- PartitionData(
X = expression,
NodePositions = principal_graph[[1]]$NodePositions,
nCores = 1
)
ProjStruct <- project_point_onto_graph(
X = expression,
NodePositions = principal_graph[[1]]$NodePositions,
Edges = principal_graph[[1]]$Edges$Edges,
Partition = PartStruct$Partition
)
checkpoints$method_aftermethod <- as.numeric(Sys.time())
# ____________________________________________________________________________
# Process & save the model ####
milestone_network <- ProjStruct$Edges %>%
as_tibble() %>%
rename(from = row, to = col) %>%
mutate(
from = paste0("M", from),
to = paste0("M", to),
length = ProjStruct$EdgeLen,
directed = FALSE
)
progressions <- tibble(cell_id = rownames(expression), edge_id = ProjStruct$EdgeID) %>%
left_join(milestone_network %>% select(from, to) %>% mutate(edge_id = row_number()), "edge_id") %>%
select(-edge_id) %>%
mutate(percentage = pmin(1, pmax(0, ProjStruct$ProjectionValues)))
output <- lst(
cell_ids = rownames(expression),
milestone_network,
progressions,
timings = checkpoints
)
dynwrap::wrap_data(cell_ids = rownames(expression)) %>%
dynwrap::add_trajectory(
milestone_network = milestone_network,
progressions = progressions
) %>%
dynwrap::add_timings(timings = checkpoints) %>%
dyncli::write_output(task$output)