-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.R
executable file
·95 lines (72 loc) · 2.47 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
#!/usr/local/bin/Rscript
requireNamespace("dyncli", quietly = TRUE)
task <- dyncli::main()
# task <- dyncli::main(args = strsplit("--dataset ~/example.h5 --output ~/output.h5", " ")[[1]], definition_location = "ti_oscope/definition.yml")
library(dplyr, warn.conflicts = FALSE)
requireNamespace("dynutils", quietly = TRUE)
requireNamespace("dynwrap", quietly = TRUE)
requireNamespace("Oscope", quietly = TRUE)
# ____________________________________________________________________________
# Load data ####
counts <- t(as.matrix(task$counts))
parameters <- task$parameters
# ____________________________________________________________________________
# Infer trajectory ####
# TIMING: done with preproc
checkpoints <- list(method_afterpreproc = Sys.time())
# taken from vignette
# https://bioconductor.org/packages/release/bioc/vignettes/Oscope/inst/doc/Oscope_vignette.pdf
Sizes <- EBSeq::MedianNorm(counts+1, alternative = parameters$alternative_median)
DataNorm <- EBSeq::GetNormalizedMat(counts, Sizes)
if (parameters$filter_genes) {
MV <- Oscope::CalcMV(
Data = counts,
Sizes = Sizes,
MeanCutLow = parameters$mean_cut[[1]],
MeanCutHigh = parameters$mean_cut[[2]],
Plot = FALSE
)
DataSubset <- DataNorm[MV$GeneToUse,]
} else {
DataSubset <- DataNorm
}
DataInput <- Oscope::NormForSine(
DataSubset,
qt1 = parameters$qt[[1]],
qt2 = parameters$qt[[2]]
)
SineRes <- Oscope::OscopeSine(DataInput)
KMRes <- Oscope::OscopeKM(
SineRes,
quan = parameters$quan
)
ToRM <- Oscope::FlagCluster(SineRes, KMRes, DataInput)
KMResUse <- KMRes[-ToRM$FlagID]
if (length(KMResUse) == 0) {
stop("No cyclic trajectory found")
}
ENIRes <- Oscope::OscopeENI(
KMRes = KMResUse,
Data = DataInput,
Ndg = parameters$ndg,
NChun = parameters$nchun,
N = parameters$niter,
NCThre = parameters$ncthre
)
pseudotime <- percent_rank(order(ENIRes[[1]]))
names(pseudotime) <- colnames(counts)
# TIMING: done with method
checkpoints$method_aftermethod <- Sys.time()
# ____________________________________________________________________________
# Save output ####
output <-
dynwrap::wrap_data(
cell_ids = names(pseudotime)
) %>%
dynwrap::add_cyclic_trajectory(
pseudotime = pseudotime
) %>%
dynwrap::add_timings(
timings = checkpoints
)
dyncli::write_output(output, task$output)