Skip to content

How to run BrainGENIE

Jonathan Hess edited this page Mar 16, 2023 · 5 revisions

Example for how to run LR-PCA imputation with BrainGENIE:

setwd(path_of_braingenie_repo)

source("braingenie_methods.R")

# --- Load blood transcriptome for new sample that you want to impute brain region transcriptome
new_dat = data.frame(fread("blood_transcriptome_data.txt"))

# --- BrainGENIE functions

# load paired blood-brain transcriptome data for GTExv8
load_expr_data(path_to_data = "~/Documents/BrainGENIE/normalized_expression_dat_gtexv8/Brain_Frontal_Cortex_BA9/")

# re-train LR models using genes from new samples 
# Note: the parameter `tissue` is a character string appended to the output file for record-keeping purposes
retrain_gtex(gene_list = colnames(new_dat), output = "~/Documents/BrainGENIE/", 
             tissue = "Frontal_Cortex_BA9", ncomps = 40, 
             prop_for_test_set = 0.0, n_folds = 5)

# load LR prediction performance from cross-validation
perf = load_cv_performance()

# filter genes that were significantly predicted via cross-validation
perf = perf[(perf$Cor >= 0.1 & perf$fdr < 0.05), ]

# run PCA on full GTEx data
blood.pca = fit_pca(gene_list = colnames(new_dat))

# train LR models using full GTEx data
trained.models = fit_lr_weights_in_gtex(pca_model = blood.pca, gene_list = perf$gene, tissue = 'Frontal_Cortex_BA9', n_comps = 40)

# obtain PCs in new samples based on PCA solution from GTEx
fit.pca.to.new.samples = predict_pca(dat = new_dat, pca_model = blood.pca)

# run imputation step on the PCA solution in new samples based on LR model weights obtained from full GTEx
imputed = impute_gxp(pca_in_new_sample = fit.pca.to.new.samples, trained_model = trained.models, scale = TRUE)

Clone this wiki locally