# Create example trend data
set.seed(456)
n_cells <- 200
mPT <- runif(n_cells, 0, 1)
# Simulate trend with switchpoint at mPT = 0.5
scores <- ifelse(mPT < 0.5,
0.3 + rnorm(n_cells, 0, 0.05),
0.7 + rnorm(n_cells, 0, 0.05))
# Compute trend
trend <- scMetaTraj_trend(scores, mPT, n_bins = 30, smooth = TRUE)
# Find switchpoint
switchpoint <- scMetaTraj_switchpoint(trend)
print(switchpoint$mPT_switch)
# Visualize
plot(trend$mPT_bin, trend$score_smooth, type = "l",
xlab = "Metabolic pseudotime", ylab = "Module score")
abline(v = switchpoint$mPT_switch, col = "red", lty = 2)
Run the code above in your browser using DataLab