Learn R Programming

scMetaTraj (version 0.1.1)

scMetaTraj_switchpoint: Identify metabolic trajectory switchpoint

Description

Identifies the point along metabolic pseudotime where a module shows maximum change in trend (inflection point).

Usage

scMetaTraj_switchpoint(trend_df)

Value

A list with:

mPT_switch

Numeric. The mPT value at the switchpoint

index

Integer. The index (row number) of the switchpoint in trend_df

Arguments

trend_df

Data frame with columns: mPT_bin and score_smooth. Typically output from scMetaTraj_trend.

Examples

Run this code
# 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