Learn R Programming

scMetaTraj (version 0.1.1)

scMetaTraj_trend: Compute metabolic module trend along pseudotime

Description

Bins cells along metabolic pseudotime (mPT) and computes mean module scores per bin, with optional loess smoothing.

Usage

scMetaTraj_trend(scores, mPT, n_bins = 30, smooth = TRUE, span = 0.3)

Value

A data frame with columns:

mPT_bin

Mid-point of each mPT bin

score

Mean score per bin

score_smooth

Smoothed score (if smooth = TRUE, otherwise same as score)

Arguments

scores

Numeric vector of module scores (length = n_cells).

mPT

Numeric vector of metabolic pseudotime values (length = n_cells).

n_bins

Integer. Number of bins along mPT for trend computation.

smooth

Logical. Whether to apply loess smoothing to the binned trend.

span

Numeric. Loess span parameter (only used if smooth = TRUE).

Examples

Run this code
# Create example data
set.seed(123)
n_cells <- 200
mPT <- runif(n_cells, 0, 1)
scores <- sin(mPT * 2 * pi) + rnorm(n_cells, 0, 0.1)

# Compute trend
trend <- scMetaTraj_trend(
  scores = scores,
  mPT = mPT,
  n_bins = 30,
  smooth = TRUE,
  span = 0.3
)

# Plot trend
plot(trend$mPT_bin, trend$score_smooth, type = "l",
     xlab = "Metabolic pseudotime", ylab = "Module score")

Run the code above in your browser using DataLab