Last updated: 2020-12-23

Checks: 5 2

Knit directory: psychencode/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown is untracked by Git. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20200622) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Using absolute paths to the files within your workflowr project makes it difficult for you and others to run your code on a different machine. Change the absolute path(s) below to the suggested relative path(s) to make your code more reproducible.

absolute relative
/Users/sabrinami/Github/psychencode/code code

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 8ca75e2. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rproj.user/
    Ignored:    analysis/.DS_Store
    Ignored:    data/.DS_Store

Untracked files:
    Untracked:  analysis/psychencode_hg38_validation.Rmd
    Untracked:  data/gencode_v26_ld_region_annotated.txt.gz
    Untracked:  models/

Unstaged changes:
    Modified:   analysis/test_scz_clozuk_pgc.Rmd

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


Liftover

Definitions

conda activate imlabtools
PRE=/Users/sabrinami/Github/analysis-sabrina/prediction_model_liftover
METAXCAN=/Users/sabrinami/Github/MetaXcan/software
DATA=/Users/sabrinami/Desktop/psychencode_test_data
MODEL=$PRE/models
LIFTOVER=$PRE/liftover
RESULTS=$PRE/results
cd $PRE

Model DB

Run the script with the PrediXcan format PsychENCODE model, and a liftover file which can be downloaded: wget https://hgdownload.soe.ucsc.edu/goldenPath/hg19/liftOver/hg19ToHg38.over.chain.gz

python prediction_model_liftover.py \
--input_model_db models/psychencode.db \
--liftover liftover/hg19ToHg38.over.chain.gz \
--output_model_db models/psychencode_hg38.db

Some of the variants in the hg19 model failed to lift over to hg38, they are recorded in dropped_snps.csv

Generate Covariances

A more complete tutorial is here: https://github.com/hakyimlab/analysis-sabrina/blob/master/covariance_1000G_ref/covariances_hg38.Rmd. I submitted this job in CRI: /gpfs/data/im-lab/nas40t2/sabrina/scripts/calculate_covariance_1000G_hg38/psychencode_cov_1000G_hg38.sh

Validation

Definitions

Similarly, in R, load the libraries, then set the same definitions.

suppressPackageStartupMessages(library(tidyverse))
suppressPackageStartupMessages(library(qqman))
suppressPackageStartupMessages(library(data.table))
suppressPackageStartupMessages(library(RSQLite))
suppressPackageStartupMessages(library(UpSetR))
PRE="/Users/sabrinami/Github/analysis-sabrina/prediction_model_liftover"
DATA="/Users/sabrinami/Desktop/psychencode_test_data"
RESULTS=glue::glue("{PRE}/results")
MODEL=glue::glue("{PRE}/models")
CODE="/Users/sabrinami/Github/psychencode/code"
source(glue::glue("{CODE}/load_data_functions.R"))
source(glue::glue("{CODE}/plotting_utils_functions.R"))

gencode_df = load_gencode_df()

Run S-PrediXcan

Run S-PrediXcan on the original model in hg19.

python3 $METAXCAN/SPrediXcan.py --gwas_file $DATA/clozuk_pgc2.meta.sumstats.out.txt \
--model_db_path $MODEL/psychencode.db \
--covariance $MODEL/psychencode_varID.txt.gz \
--snp_column varID \
--or_column OR \
--pvalue_column P \
--non_effect_allele_column A2 \
--effect_allele_column A1 \
--keep_non_rsid --additional_output --model_db_snp_key varID \
--throw \
--output_file $RESULTS/clozuk_pgc2_psychencode.csv

Run S-PrediXcan with the lifted over model.

python $METAXCAN/SPrediXcan.py \
--gwas_file  $DATA/imputed_clozuk_pgc2.txt.gz \
--snp_column panel_variant_id --effect_allele_column effect_allele --non_effect_allele_column non_effect_allele --zscore_column zscore \
--model_db_path $MODEL/psychencode_hg38.db \
--covariance $MODEL/psychencode_hg38.txt.gz \
--keep_non_rsid --additional_output --model_db_snp_key varID \
--throw \
--output_file $RESULTS/clozuk_pgc2_psychencode_hg38.csv

And the mashr model.

python $METAXCAN/SPrediXcan.py \
--gwas_file  $DATA/imputed_clozuk_pgc2.txt.gz \
--snp_column panel_variant_id --effect_allele_column effect_allele --non_effect_allele_column non_effect_allele --zscore_column zscore \
--model_db_path $MODEL/mashr_Brain_Cortex.db \
--covariance $MODEL/mashr_Brain_Cortex.txt.gz \
--keep_non_rsid --additional_output --model_db_snp_key varID \
--throw \
--output_file $RESULTS/clozuk_pgc2_mashr_Brain_Cortex.csv

Compare Association Results

First, load all assocation results, and check for significant genes.

spredixcan_association_psychencode_hg19 = load_spredixcan_association(glue::glue("{RESULTS}/clozuk_pgc2_psychencode.csv"), gencode_df)
dim(spredixcan_association_psychencode_hg19)
[1] 14021    16
significant_genes_psychencode_hg19 <- spredixcan_association_psychencode_hg19 %>% filter(pvalue < 0.05/nrow(spredixcan_association_psychencode_hg19)) %>% arrange(pvalue)
spredixcan_association_psychencode_hg38 = load_spredixcan_association(glue::glue("{RESULTS}/clozuk_pgc2_psychencode_hg38.csv"), gencode_df)
dim(spredixcan_association_psychencode_hg38)
[1] 13992    16
significant_genes_psychencode_hg38 <- spredixcan_association_psychencode_hg38 %>% filter(pvalue < 0.05/nrow(spredixcan_association_psychencode_hg38)) %>% arrange(pvalue)
spredixcan_association_Brain_Cortex = load_spredixcan_association(glue::glue("{RESULTS}/clozuk_pgc2_mashr_Brain_Cortex.csv"), gencode_df)
dim(spredixcan_association_Brain_Cortex)
[1] 12805    16
significant_genes_Brain_Cortex <- spredixcan_association_Brain_Cortex %>% filter(pvalue < 0.05/nrow(spredixcan_association_Brain_Cortex)) %>% arrange(pvalue)

As a sanity check, check PsychENCODE models are consistent between builds.

psychencode_zscores = inner_join(spredixcan_association_psychencode_hg19, spredixcan_association_psychencode_hg38, by=c("gene"))
dim(psychencode_zscores)
[1] 13978    31
psychencode_zscores %>% ggplot(aes(zscore.x, zscore.y)) + geom_point() + ggtitle("PsychENCODE S-PrediXcan z-score") + xlab("hg19") + ylab("hg38") + geom_abline(intercept = 0, slope = 1)
Warning: Removed 32 rows containing missing values (geom_point).

Then compare PsychENCODE and mashr Brain Cortex z-scores.

psychencode_Brain_Cortex_zscores = inner_join(spredixcan_association_Brain_Cortex, spredixcan_association_psychencode_hg38, by=c("gene"))
dim(psychencode_Brain_Cortex_zscores)
[1] 8701   31
psychencode_zscores %>% ggplot(aes(zscore.x, zscore.y)) + geom_point() + ggtitle("S-PrediXcan z-score") + xlab("mashr Brain Cortex") + ylab("PsychENCODE") + geom_abline(intercept = 0, slope = 1)
Warning: Removed 32 rows containing missing values (geom_point).


sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] UpSetR_1.4.0      RSQLite_2.2.1     data.table_1.13.2 qqman_0.1.4      
 [5] forcats_0.5.0     stringr_1.4.0     dplyr_1.0.2       purrr_0.3.4      
 [9] readr_1.4.0       tidyr_1.1.2       tibble_3.0.4      ggplot2_3.3.2    
[13] tidyverse_1.3.0  

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5       lubridate_1.7.9  assertthat_0.2.1 rprojroot_1.3-2 
 [5] digest_0.6.27    plyr_1.8.6       R6_2.4.1         cellranger_1.1.0
 [9] backports_1.1.10 reprex_0.3.0     evaluate_0.14    httr_1.4.2      
[13] highr_0.8        pillar_1.4.6     rlang_0.4.8      readxl_1.3.1    
[17] rstudioapi_0.11  blob_1.2.1       rmarkdown_2.5    labeling_0.4.2  
[21] bit_4.0.4        munsell_0.5.0    broom_0.7.2      compiler_4.0.3  
[25] httpuv_1.5.4     modelr_0.1.8     xfun_0.18        pkgconfig_2.0.3 
[29] htmltools_0.5.0  tidyselect_1.1.0 gridExtra_2.3    workflowr_1.6.2 
[33] fansi_0.4.1      calibrate_1.7.7  crayon_1.3.4     dbplyr_1.4.4    
[37] withr_2.3.0      later_1.1.0.1    MASS_7.3-53      grid_4.0.3      
[41] jsonlite_1.7.1   gtable_0.3.0     lifecycle_0.2.0  DBI_1.1.0       
[45] git2r_0.27.1     magrittr_1.5     scales_1.1.1     cli_2.1.0       
[49] stringi_1.5.3    farver_2.0.3     fs_1.5.0         promises_1.1.1  
[53] xml2_1.3.2       ellipsis_0.3.1   generics_0.0.2   vctrs_0.3.4     
[57] tools_4.0.3      bit64_4.0.5      glue_1.4.2       hms_0.5.3       
[61] yaml_2.2.1       colorspace_1.4-1 rvest_0.3.6      memoise_1.1.0   
[65] knitr_1.30       haven_2.3.1