-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.R
executable file
·105 lines (85 loc) · 2.81 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/local/bin/Rscript
task <- dyncli::main()
library(dplyr, warn.conflicts = FALSE)
library(purrr, warn.conflicts = FALSE)
library(dynwrap, warn.conflicts = FALSE)
library(Mpath, warn.conflicts = FALSE)
# ____________________________________________________________________________
# Load data ####
counts <- as.matrix(task$counts)
parameters <- task$parameters
groups_id <- task$priors$groups_id
# ____________________________________________________________________________
# Run method ####
if (parameters$numcluster_null) {
numcluster <- NULL
}
# TIMING: done with preproc
checkpoints <- list(method_afterpreproc = as.numeric(Sys.time()))
# collect sample info
sample_info <- groups_id %>% select(cell_id, GroupID = group_id) %>% as.data.frame
# designate landmarks
landmark_cluster <- Mpath::landmark_designation(
rpkmFile = t(counts),
baseName = NULL,
sampleFile = sample_info,
distMethod = parameters$distMethod,
method = parameters$method,
numcluster = min(parameters$numcluster, nrow(counts) - 1),
diversity_cut = parameters$diversity_cut,
size_cut = parameters$size_cut,
saveRes = FALSE
) %>%
mutate_if(is.factor, as.character)
milestone_ids <- unique(landmark_cluster$landmark_cluster)
# catch situation where mpath only detects 1 landmark
if (length(milestone_ids) == 1) {
warning("Mpath only detected one landmark")
milestone_network <-
data_frame(
from = "M1",
to = "M1",
length = 0,
directed = FALSE
)
} else {
# build network
network <- Mpath::build_network(
exprs = t(counts),
baseName = NULL,
landmark_cluster = landmark_cluster,
distMethod = parameters$distMethod,
writeRes = FALSE
)
# trim network
trimmed_network <- Mpath::trim_net(
nb12 = network,
writeRes = FALSE
)
# create final milestone network
class(trimmed_network) <- NULL
milestone_network <- trimmed_network %>%
reshape2::melt(varnames = c("from", "to"), value.name = "length") %>%
mutate_if(is.factor, as.character) %>%
filter(length > 0, from < to) %>%
mutate(directed = FALSE)
}
# TIMING: done with method
checkpoints$method_aftermethod <- as.numeric(Sys.time())
grouping <-
tibble::deframe(landmark_cluster)
output <- lst(
cell_ids = names(grouping),
grouping,
milestone_network,
timings = checkpoints
)
# ____________________________________________________________________________
# Save output ####
output <- dynwrap::wrap_data(cell_ids = names(grouping)) %>%
dynwrap::add_cluster_graph(
milestone_network = milestone_network,
grouping = grouping
) %>%
dynwrap::add_timings(checkpoints)
dyncli::write_output(output, task$output)