Skip to content
Jonathan Hess edited this page May 31, 2019 · 17 revisions

Welcome to the tutorial page for ptrs!

Follow these steps to generate run ptrs using toy data:

  1. Download ExampleWeightFile.txt from main page and ptrs.R
  2. Navigate to directory where these downloads were saved
  3. Run the following R code:
# load ptrs
source("ptrs.R")

# load weights
weights = load_weights(file="ExampleWeightFile.txt", gene_col = "GeneSymbol", weight_col = "z.score", p_col = "P")

# create random gene expression values
datExpr = matrix(data = NA, nrow = nrow(ptrs_weights), ncol = 100)
datExpr = data.frame(datExpr)
datExpr = data.frame(sapply(datExpr, function(x) rnorm(n = nrow(datExpr), mean = 0, sd=1)))
rownames(datExpr) = sample(ptrs_weights$gene_id)
colnames(datExpr) = paste("subject.", 1:ncol(datExpr), sep="")

# run ptrs on random data
score_df = ptrs(dat = datExpr, weight_table = weights, p_thres = c(0.5, 0.1, 0.05, 0.005, 0.002, 0.001))

# plot score density
plot(density(score_df$ptrs_1)) # column named ptrs_1 is equal to p_thres = 0.5

# create random case-control phenotype (case = 1, control = 0)
dx = sample(c(0,1), replace=T, nrow(score_df))

# contrast cases and controls on ptrs
fit = lm(as.matrix(score_df) ~ dx)
coefs = summary(fit)
coefs = lapply(coefs, function(x) broom::tidy(x$coefficients))
coefs = ldply(coefs)
coefs = coefs[grepl("dx", coefs$.rownames), ]
print(coefs)

Clone this wiki locally