Last updated: 2022-03-02

Checks: 5 2

Knit directory: cTWAS_analysis/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). 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(20211220) 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
/project2/xinhe/shengqian/cTWAS/cTWAS_analysis/data/ data
/project2/xinhe/shengqian/cTWAS/cTWAS_analysis/code/ctwas_config.R code/ctwas_config.R

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 9f9aa75. 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:    .ipynb_checkpoints/
    Ignored:    data/AF/

Untracked files:
    Untracked:  Rplot.png
    Untracked:  analysis/.ipynb_checkpoints/
    Untracked:  analysis/SCZ_Brain_Amygdala_S.Rmd
    Untracked:  analysis/SCZ_Brain_Anterior_cingulate_cortex_BA24_S.Rmd
    Untracked:  analysis/SCZ_Brain_Caudate_basal_ganglia_S.Rmd
    Untracked:  analysis/SCZ_Brain_Cerebellar_Hemisphere_S.Rmd
    Untracked:  analysis/SCZ_Brain_Cerebellum_S.Rmd
    Untracked:  analysis/SCZ_Brain_Cortex_S.Rmd
    Untracked:  analysis/SCZ_Brain_Frontal_Cortex_BA9_S.Rmd
    Untracked:  analysis/SCZ_Brain_Hippocampus_S.Rmd
    Untracked:  analysis/SCZ_Brain_Hypothalamus_S.Rmd
    Untracked:  analysis/SCZ_Brain_Nucleus_accumbens_basal_ganglia_S.Rmd
    Untracked:  analysis/SCZ_Brain_Putamen_basal_ganglia_S.Rmd
    Untracked:  analysis/SCZ_Brain_Spinal_cord_cervical_c-1_S.Rmd
    Untracked:  analysis/SCZ_Brain_Substantia_nigra_S.Rmd
    Untracked:  code/.ipynb_checkpoints/
    Untracked:  code/AF_out/
    Untracked:  code/Autism_out/
    Untracked:  code/BMI_S_out/
    Untracked:  code/BMI_out/
    Untracked:  code/Glucose_out/
    Untracked:  code/LDL_S_out/
    Untracked:  code/SCZ_S_out/
    Untracked:  code/SCZ_out/
    Untracked:  code/T2D_out/
    Untracked:  code/ctwas_config.R
    Untracked:  code/mapping.R
    Untracked:  code/out/
    Untracked:  code/run_AF_analysis.sbatch
    Untracked:  code/run_AF_analysis.sh
    Untracked:  code/run_AF_ctwas_rss_LDR.R
    Untracked:  code/run_Autism_analysis.sbatch
    Untracked:  code/run_Autism_analysis.sh
    Untracked:  code/run_Autism_ctwas_rss_LDR.R
    Untracked:  code/run_BMI_analysis.sbatch
    Untracked:  code/run_BMI_analysis.sh
    Untracked:  code/run_BMI_analysis_S.sbatch
    Untracked:  code/run_BMI_analysis_S.sh
    Untracked:  code/run_BMI_ctwas_rss_LDR.R
    Untracked:  code/run_BMI_ctwas_rss_LDR_S.R
    Untracked:  code/run_Glucose_analysis.sbatch
    Untracked:  code/run_Glucose_analysis.sh
    Untracked:  code/run_Glucose_ctwas_rss_LDR.R
    Untracked:  code/run_LDL_analysis_S.sbatch
    Untracked:  code/run_LDL_analysis_S.sh
    Untracked:  code/run_LDL_ctwas_rss_LDR_S.R
    Untracked:  code/run_SCZ_analysis.sbatch
    Untracked:  code/run_SCZ_analysis.sh
    Untracked:  code/run_SCZ_analysis_S.sbatch
    Untracked:  code/run_SCZ_analysis_S.sh
    Untracked:  code/run_SCZ_ctwas_rss_LDR.R
    Untracked:  code/run_SCZ_ctwas_rss_LDR_S.R
    Untracked:  code/run_T2D_analysis.sbatch
    Untracked:  code/run_T2D_analysis.sh
    Untracked:  code/run_T2D_ctwas_rss_LDR.R
    Untracked:  code/wflow_build-18162038.err
    Untracked:  code/wflow_build-18162038.out
    Untracked:  code/wflow_build.R
    Untracked:  code/wflow_build.sbatch
    Untracked:  data/.ipynb_checkpoints/
    Untracked:  data/Autism/
    Untracked:  data/BMI/
    Untracked:  data/BMI_S/
    Untracked:  data/Glucose/
    Untracked:  data/LDL_S/
    Untracked:  data/SCZ/
    Untracked:  data/SCZ_S/
    Untracked:  data/T2D/
    Untracked:  data/TEST/
    Untracked:  data/UKBB/
    Untracked:  data/UKBB_SNPs_Info.text
    Untracked:  data/gene_OMIM.txt
    Untracked:  data/gene_pip_0.8.txt
    Untracked:  data/mashr_Heart_Atrial_Appendage.db
    Untracked:  data/mashr_sqtl/
    Untracked:  data/summary_known_genes_annotations.xlsx
    Untracked:  data/untitled.txt

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.


Weight QC

#number of imputed weights
nrow(qclist_all)
[1] 31542
#number of imputed weights by chromosome
table(qclist_all$chr)

   1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16 
2949 2110 1909 1116 1306 1374 1747 1105 1302 1325 1901 1686  587 1093 1113 1580 
  17   18   19   20   21   22 
2203  399 2251 1027  412 1047 
#number of imputed weights without missing variants
sum(qclist_all$nmiss==0)
[1] 28610
#proportion of imputed weights without missing variants
mean(qclist_all$nmiss==0)
[1] 0.907
#add z scores to results
load(paste0(results_dir, "/", analysis_id, "_expr_z_gene.Rd"))
ctwas_gene_res$z <- z_gene[ctwas_gene_res$intron_id,]$z

z_snp <- z_snp[z_snp$id %in% ctwas_snp_res$id,]
ctwas_snp_res$z <- z_snp$z[match(ctwas_snp_res$id, z_snp$id)]

#merge gene and snp results with added information
ctwas_snp_res$genename=NA
ctwas_snp_res$gene_type=NA
ctwas_snp_res$intron_id=NA

saveRDS(ctwas_gene_res, file = paste0(results_dir,"/",analysis_id,"_ctwas_gene_res.RDS"))
saveRDS(ctwas_snp_res, file =  paste0(results_dir,"/",analysis_id,"_ctwas_snp_res.RDS"))
ctwas_intron_res <- readRDS(paste0(results_dir,"/",analysis_id,"_ctwas_gene_res.RDS"))
ctwas_intron_res <- ctwas_intron_res[!is.na(ctwas_intron_res$genename),]
ctwas_snp_res <- readRDS(paste0(results_dir,"/",analysis_id,"_ctwas_snp_res.RDS"))

#get number of eQTL for inrtons
num_sqtl <- c()
for (i in 1:22){
  load(paste0(results_dir, "/", analysis_id, "_expr_chr", i, ".exprqc.Rd"))
  num_sqtl <- c(num_sqtl, unlist(lapply(wgtlist, nrow)))
}
ctwas_intron_res$num_sqtl <- num_sqtl[ctwas_intron_res$intron_id]
library(dplyr)
by_genename <- ctwas_intron_res %>% group_by(genename)
ctwas_gene_res <- data.frame(by_genename %>% summarise(
  chrom = chrom[1],
  id = id[1],
  pos = min(pos),
  type = type[1],
  region_tag1 = region_tag1[1],
  region_tag2 = region_tag2[1],
  cs_index = cs_index[1],
  susie_pip = sum(susie_pip),
  mu2 = mu2[which.max(abs(mu2))],
  region_tag = region_tag[1],
  PVE = sum(susie_pip*PVE),
  z = z[which.max(abs(z))],
  gene_type = type[1],
  num_intron = length(intron_id),
  num_sqtl = sum(num_sqtl)))

ctwas_snp_res$num_intron <- NA
ctwas_snp_res$num_sqtl <- NA
ctwas_res <- rbind(ctwas_gene_res,
                   ctwas_snp_res[,colnames(ctwas_gene_res)])

#store columns to report
report_cols <- colnames(ctwas_gene_res)[!(colnames(ctwas_gene_res) %in% c("type", "region_tag1", "region_tag2", "cs_index", "gene_type", "z_flag", "id", "chrom", "pos"))]
first_cols <- c("genename", "region_tag")
report_cols <- c(first_cols, report_cols[!(report_cols %in% first_cols)])

report_cols_snps <- c("id", report_cols[-1])
report_cols_snps <- report_cols_snps[!(report_cols_snps %in% "num_sqtl")]

#get number of SNPs from s1 results; adjust for thin argument
ctwas_res_s1 <- data.table::fread(paste0(results_dir, "/", analysis_id, "_ctwas.s1.susieIrss.txt"))
n_snps <- sum(ctwas_res_s1$type=="SNP")/thin
rm(ctwas_res_s1)

Check convergence of parameters

#estimated group prior
estimated_group_prior <- group_prior_rec[,ncol(group_prior_rec)]
names(estimated_group_prior) <- c("gene", "snp")
estimated_group_prior["snp"] <- estimated_group_prior["snp"]*thin #adjust parameter to account for thin argument
print(estimated_group_prior)

#estimated group prior variance
estimated_group_prior_var <- group_prior_var_rec[,ncol(group_prior_var_rec)]
names(estimated_group_prior_var) <- c("gene", "snp")
print(estimated_group_prior_var)

#report sample size
print(sample_size)

#report group size
group_size <- c(nrow(ctwas_gene_res), n_snps)
print(group_size)

#estimated group PVE
estimated_group_pve <- estimated_group_prior_var*estimated_group_prior*group_size/sample_size #check PVE calculation
names(estimated_group_pve) <- c("gene", "snp")
print(estimated_group_pve)

#compare sum(PIP*mu2/sample_size) with above PVE calculation
c(sum(ctwas_gene_res$PVE),sum(ctwas_snp_res$PVE))

Genes with highest PIPs

Genes with highest PVE

Comparing z scores and PIPs

GO enrichment analysis for genes with PIP>0.5

#number of genes for gene set enrichment
length(genes)

DisGeNET enrichment analysis for genes with PIP>0.5

WebGestalt enrichment analysis for genes with PIP>0.5

PIP Manhattan Plot

Sensitivity, specificity and precision for silver standard genes

#number of genes in known annotations
print(length(known_annotations))

#number of genes in known annotations with imputed expression
print(sum(known_annotations %in% ctwas_gene_res$genename))

#significance threshold for TWAS
print(sig_thresh)

#number of ctwas genes
length(ctwas_genes)

#number of TWAS genes
length(twas_genes)

#show novel genes (ctwas genes with not in TWAS genes)
ctwas_gene_res[ctwas_gene_res$genename %in% novel_genes,report_cols]

#sensitivity / recall
print(sensitivity)

#specificity
print(specificity)

#precision / PPV
print(precision)

sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Scientific Linux 7.4 (Nitrogen)

Matrix products: default
BLAS/LAPACK: /software/openblas-0.2.19-el7-x86_64/lib/libopenblas_haswellp-r0.2.19.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
 [1] EnsDb.Hsapiens.v79_2.99.0 ensembldb_2.8.0          
 [3] AnnotationFilter_1.8.0    GenomicFeatures_1.36.3   
 [5] AnnotationDbi_1.46.0      Biobase_2.44.0           
 [7] GenomicRanges_1.36.1      GenomeInfoDb_1.20.0      
 [9] IRanges_2.18.1            S4Vectors_0.22.1         
[11] BiocGenerics_0.30.0       workflowr_1.7.0          

loaded via a namespace (and not attached):
 [1] httr_1.4.2                  bit64_4.0.5                
 [3] getPass_0.2-2               highr_0.9                  
 [5] blob_1.2.2                  GenomeInfoDbData_1.2.1     
 [7] Rsamtools_2.0.0             yaml_2.2.1                 
 [9] progress_1.2.2              pillar_1.6.4               
[11] RSQLite_2.2.8               lattice_0.20-38            
[13] glue_1.6.2                  digest_0.6.29              
[15] promises_1.0.1              XVector_0.24.0             
[17] htmltools_0.5.2             httpuv_1.5.1               
[19] Matrix_1.2-18               XML_3.99-0.3               
[21] pkgconfig_2.0.3             biomaRt_2.40.1             
[23] zlibbioc_1.30.0             processx_3.5.2             
[25] whisker_0.3-2               later_0.8.0                
[27] BiocParallel_1.18.0         git2r_0.26.1               
[29] tibble_3.1.6                ellipsis_0.3.2             
[31] cachem_1.0.6                SummarizedExperiment_1.14.1
[33] lazyeval_0.2.2              cli_3.1.0                  
[35] magrittr_2.0.2              crayon_1.5.0               
[37] memoise_2.0.1               evaluate_0.14              
[39] ps_1.6.0                    fs_1.5.2                   
[41] fansi_1.0.2                 tools_3.6.1                
[43] data.table_1.14.2           prettyunits_1.1.1          
[45] hms_1.1.1                   lifecycle_1.0.1            
[47] matrixStats_0.57.0          stringr_1.4.0              
[49] DelayedArray_0.10.0         callr_3.7.0                
[51] Biostrings_2.52.0           compiler_3.6.1             
[53] jquerylib_0.1.4             rlang_1.0.1                
[55] grid_3.6.1                  RCurl_1.98-1.5             
[57] rstudioapi_0.13             bitops_1.0-7               
[59] rmarkdown_2.11              DBI_1.1.2                  
[61] curl_4.3.2                  R6_2.5.1                   
[63] GenomicAlignments_1.20.1    knitr_1.36                 
[65] rtracklayer_1.44.4          fastmap_1.1.0              
[67] bit_4.0.4                   utf8_1.2.2                 
[69] rprojroot_2.0.2             ProtGenerics_1.16.0        
[71] stringi_1.7.6               Rcpp_1.0.8                 
[73] vctrs_0.3.8                 xfun_0.29