Last updated: 2022-02-02
Checks: 7 0
Knit directory: snRNA_eqtl/
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.
Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.
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(20211124)
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.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
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 40b6b67. 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: .Rproj.user/
Ignored: data/magma_interaction_eqtl/
Ignored: data/magma_specific_genes/
Ignored: data_sensitive/
Ignored: output/figures/
Untracked files:
Untracked: analysis/._index.Rmd
Untracked: analysis/additional/
Untracked: analysis/alternatives/
Untracked: analysis/clean_analysis.Rmd
Untracked: analysis/log_run_slurm_out
Untracked: analysis/log_run_slurm_stderr
Untracked: analysis/portfolio/
Untracked: analysis/revision.Rmd
Untracked: analysis/run_slurm.Rscript
Untracked: analysis/run_slurm.sbatch
Untracked: data/dice/
Untracked: data/epigenome_enrichment/
Untracked: data/gencode/
Untracked: data/gnomad_loeuf/
Untracked: data/gtex/
Untracked: data/gwas/
Untracked: data/gwas_epigenome_overlap/
Untracked: data/metabrain/
Untracked: data/umap/
Untracked: output/coloc/
Untracked: output/eqtl/
Untracked: output_almost_final/
Untracked: output_tmp_QTLtools/
Untracked: output_tmp_fastQTL_sample_ambient_removed/
Unstaged changes:
Modified: .gitignore
Modified: analysis/_site.yml
Modified: analysis/plot_figures.Rmd
Deleted: output/README.md
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.
These are the previous versions of the repository in which changes were made to the R Markdown (analysis/05_coloc_GTEx_Dice.Rmd
) and HTML (docs/05_coloc_GTEx_Dice.html
) files. If you’ve configured a remote Git repository (see ?wflow_git_remote
), click on the hyperlinks in the table below to view the files as they were in that past version.
File | Version | Author | Date | Message |
---|---|---|---|---|
html | 0d18805 | Julien Bryois | 2022-01-27 | Build site. |
html | 06d5e04 | Julien Bryois | 2022-01-25 | Build site. |
Rmd | befc976 | Julien Bryois | 2022-01-25 | coloc GTEx |
html | 1eba9f2 | Julien Bryois | 2022-01-06 | Build site. |
Rmd | 58f7ae1 | Julien Bryois | 2022-01-06 | Coloc GTEx Dice |
html | 1ec3603 | Julien Bryois | 2022-01-03 | Build site. |
Rmd | 9926eae | Julien Bryois | 2022-01-03 | Coloc GTEx Dice |
Rmd | edcd2db | Julien Bryois | 2021-12-17 | Coloc GTEx Dice |
library(tidyverse)
library(data.table)
library(coloc)
library(parallel)
library(arrow)
library(biomaRt)
selected_trait <- 'ms'
if(selected_trait=='ms'){
sumstats <- vroom::vroom('data/gwas/ms/discovery_metav3.0.meta') %>%
mutate(CHR=paste0('chr',CHR)) %>%
filter(!is.na(P)) %>%
mutate(beta=log(OR),
se=abs(beta/qnorm(P/2))) %>%
dplyr::select(variant_id=SNP,
p_value=P,
chr=CHR,
bp_b37=BP,
effect_allele=A1,
other_allele=A2,
beta,
se) %>%
filter(beta!=0) %>% #Some SNPs have OR=1, so se estimate = 0, leading to issues in coloc, we exclude these here
dplyr::mutate(SNP_id_hg19=paste0(chr,':',bp_b37))
loci <- read_tsv('data/gwas/ms/loci_LDlinkR.r2.0.1.EUR.txt')
}
We will later add the MAF of SNPs in our study to the MS sumstats as this is required by coloc to estimate sdY when the expression data was not standard normalized (which is the case for DICE). We make the assumption that MAF in DICE is similar to the MAF in our european eQTL study.
snp_pos <- data.table::fread('data_sensitive/genotypes/processed/snp_pos_hg38_hg19.mappings.txt',data.table = FALSE) %>% as_tibble() %>%
dplyr::select(SNP_id_hg19,MAF)
closest <- read_tsv(paste0('data/gwas/',selected_trait,'/closest.protein.coding.bed'),col_names = FALSE) %>%
setNames(c('chr_snp','start_snp','end_snp','GWAS_snp','beta','chr_gene','start_gene','end_gene','gene','distance')) %>%
mutate(GWAS_snp_pos=paste0(chr_snp,':',start_snp)) %>%
dplyr::select(GWAS_snp,GWAS_snp_pos,gene,beta,distance) %>%
separate(gene,into=c('symbol','ensembl'),sep='_') %>%
add_count(GWAS_snp) %>%
group_by(GWAS_snp) %>%
mutate(locus_name_gene=ifelse(n==1,symbol,paste0(symbol,collapse=' - '))) %>%
ungroup() %>%
dplyr::select(GWAS_snp_pos,locus_name_gene,beta_top_GWAS=beta) %>%
unique() %>% arrange(-abs(beta_top_GWAS))
loci <- left_join(loci,closest,by='GWAS_snp_pos')
if(!file.exists(paste0('data/gtex/variant_id_SNP_mapping.',selected_trait,'.rds'))){
mappings <- fread('data/gtex/GTEx_Analysis_2017-06-05_v8_WholeGenomeSeq_838Indiv_Analysis_Freeze.lookup_table.txt',
data.table = FALSE) %>%
filter(num_alt_per_site==1) %>%
filter(chr!='chrX') %>%
dplyr::select(id=variant_id,rs_id_dbSNP151_GRCh38p7,A1=alt,A2=ref,variant_id_b37) %>%
dplyr::rename(variant_id=rs_id_dbSNP151_GRCh38p7) %>%
filter(variant_id%in%sumstats$variant_id) %>%
mutate(chr_hg19=sapply(str_split(variant_id_b37,'_'),"[", 1)) %>%
mutate(pos_hg19=sapply(str_split(variant_id_b37,'_'),"[", 2)) %>%
mutate(SNP_id_hg19=paste0('chr',chr_hg19,':',pos_hg19)) %>%
dplyr::select(-chr_hg19,-pos_hg19,-variant_id_b37)
saveRDS(mappings,paste0('data/gtex/variant_id_SNP_mapping.',selected_trait,'.rds'))
} else{
mappings <- readRDS(paste0('data/gtex/variant_id_SNP_mapping.',selected_trait,'.rds'))
}
Set location of nominal results files:
gtex_eqtl_path <- 'data/gtex/GTEx_Analysis_v8_EUR_eQTL_all_associations/'
gtex_sqtl_path <- 'data/gtex/GTEx_Analysis_v8_EUR_sQTL_all_associations/'
gtex_eqtl_spleen_path <- paste0(gtex_eqtl_path,'Spleen.v8.EUR.allpairs.')
gtex_eqtl_blood_path <- paste0(gtex_eqtl_path,'Whole_Blood.v8.EUR.allpairs.')
gtex_sqtl_spleen_path <- paste0(gtex_sqtl_path,'Spleen.v8.EUR.sqtl_allpairs.')
gtex_sqtl_blood_path <- paste0(gtex_sqtl_path,'Whole_Blood.v8.EUR.sqtl_allpairs.')
dice_eqtl_path <- 'data/dice/'
dice_B_cell_naive <- paste0(dice_eqtl_path,'B_CELL_NAIVE.sumstats.')
dice_CD4_naive <- paste0(dice_eqtl_path,'CD4_NAIVE.sumstats.')
dice_CD4_stim <- paste0(dice_eqtl_path,'CD4_STIM.sumstats.')
dice_CD8_naive <- paste0(dice_eqtl_path,'CD8_NAIVE.sumstats.')
dice_CD8_stim <- paste0(dice_eqtl_path,'CD8_STIM.sumstats.')
dice_M2 <- paste0(dice_eqtl_path,'M2.sumstats.')
dice_monocytes <- paste0(dice_eqtl_path,'MONOCYTES.sumstats.')
dice_NK <- paste0(dice_eqtl_path,'NK.sumstats.')
dice_TFH <- paste0(dice_eqtl_path,'TFH.sumstats.')
dice_TH17 <- paste0(dice_eqtl_path,'TH17.sumstats.')
dice_TH1 <- paste0(dice_eqtl_path,'TH1.sumstats.')
dice_TH2 <- paste0(dice_eqtl_path,'TH2.sumstats.')
dice_THSTAR <- paste0(dice_eqtl_path,'THSTAR.sumstats.')
dice_TREG_MEM <- paste0(dice_eqtl_path,'TREG_MEM.sumstats.')
dice_TREG_NAIVE <- paste0(dice_eqtl_path,'TREG_NAIVE.sumstats.')
dice_files <- tibble(files=c(dice_B_cell_naive,
dice_CD4_naive,
dice_CD4_stim,
dice_CD8_naive,
dice_CD8_stim,
dice_M2,
dice_monocytes,
dice_NK,
dice_TFH,
dice_TH17,
dice_TH1,
dice_TH2,
dice_THSTAR,
dice_TREG_MEM,
dice_TREG_NAIVE)) %>%
mutate(name=gsub('data/dice/|.sumstats.','',files))
prepare_eqtl_gtex <- function(gtex_tissue_path,chrom_locus,sumstats_locus){
gtex_file <- paste0(gtex_tissue_path,chrom_locus,'.parquet')
gtex <- read_parquet(gtex_file,
as_tibble = TRUE,
props=ParquetReaderProperties$create(use_threads=FALSE)) %>%
dplyr::select(gene=phenotype_id,
id=variant_id,
p_eqtl=pval_nominal,
beta_eqtl=slope,
se_eqtl=slope_se) %>%
inner_join(.,mappings,by='id') %>%
filter(SNP_id_hg19%in%sumstats_locus$SNP_id_hg19) %>%
filter(!is.na(beta_eqtl)) %>%
add_count(gene) %>%
filter(n>10) #Only keep genes with at least 10 SNPs
}
prepare_eqtl_dice <- function(eqtl_path,chrom_locus,sumstats_locus){
file <- paste0(eqtl_path,chrom_locus,'.gz')
eqtl <- fread(file,header = FALSE,data.table=FALSE) %>%
dplyr::select(gene=V3,
p_eqtl=V7,
beta_eqtl=V6,
SNP_id_hg19=V2,
A1=V5,
A2=V4) %>%
mutate(se_eqtl=abs(beta_eqtl/qnorm(p_eqtl/2))) %>% #compute standard error from pvalue and beta
filter(SNP_id_hg19%in%sumstats_locus$SNP_id_hg19) %>%
add_count(gene) %>%
filter(n>10) %>%
filter(beta_eqtl!=0) %>%
inner_join(.,snp_pos,by='SNP_id_hg19')
}
run_coloc <- function(tissue_sumstats,tissue_name,sumstats_locus,dice=FALSE){
if(nrow(tissue_sumstats)==0){
return (NULL)
}
out <- lapply(unique(tissue_sumstats$gene),function(x){
message(x)
tissue_sumstats_gene <- filter(tissue_sumstats,gene==x)
sumstats_locus_gene <- sumstats_locus %>% inner_join(.,tissue_sumstats_gene,by='SNP_id_hg19')
if (nrow(sumstats_locus_gene)>0){
coloc_res_pval <- coloc.abf(
dataset1=list(beta=sumstats_locus_gene$beta,
varbeta=sumstats_locus_gene$se^2,
type="cc"),
dataset2=list(beta=sumstats_locus_gene$beta_eqtl,
varbeta=sumstats_locus_gene$se_eqtl^2,
sdY=1,
type="quant"))$summary %>%
as.data.frame()
colnames(coloc_res_pval) <- x
if (dice==TRUE){
#If dice dataset, the expression data was not inverse normal transformed.
#We will estimate sdY from N and MAF
coloc_res_pval <- coloc.abf(
dataset1=list(beta=sumstats_locus_gene$beta,
varbeta=sumstats_locus_gene$se^2,
type="cc"),
dataset2=list(beta=sumstats_locus_gene$beta_eqtl,
varbeta=sumstats_locus_gene$se_eqtl^2,
MAF=sumstats_locus_gene$MAF,
N=91,
type="quant"))$summary %>%
as.data.frame()
colnames(coloc_res_pval) <- x
}
#Get direction of effect for all SNPs at the locus
sumstats_locus_gene <- sumstats_locus_gene %>%
mutate(direction=case_when(
(effect_allele==A1 & other_allele==A2) ~ sign(beta*beta_eqtl),
(effect_allele==A2 & other_allele==A1) ~ -sign(beta*beta_eqtl),
TRUE ~ 0))
#Get Proportion of positive direction
direction_prop <- sumstats_locus_gene %>%
summarise(prop_pos_direction=sum(direction==1)/n()) %>%
setNames(x) %>%
as.data.frame()
rownames(direction_prop) <- 'prop_pos_direction'
direction_sign <- sumstats_locus_gene %>%
#Take SNP with strongest evidence of an effect on gene expression
filter(p_eqtl==min(p_eqtl)) %>%
#If there are ties, take SNPs with lowest GWAS association (at random of ties).
slice_min(n=1,p_value,with_ties=FALSE) %>%
summarise(direction=direction,
beta_gwas=case_when(
(effect_allele==A1 & other_allele==A2) ~ beta,
(effect_allele==A2 & other_allele==A1) ~ -beta
),
beta_eqtl=beta_eqtl,
beta_smr=case_when(
direction== 1 ~ abs(beta)/abs(beta_eqtl),
direction== -1 ~ -(abs(beta)/abs(beta_eqtl))
),
) %>%
t() %>%
as.data.frame()
colnames(direction_sign) <- x
#Add direction of effect to coloc results
coloc_res_pval <- rbind(coloc_res_pval,direction_sign,direction_prop)
return(coloc_res_pval)
}
else{
return (NULL)
}
})
out_pvalue <- out %>%
bind_cols() %>%
t() %>%
as.data.frame() %>%
rownames_to_column('gene') %>%
as_tibble() %>%
arrange(-PP.H4.abf) %>%
mutate(tissue=tissue_name)
return(out_pvalue)
}
#Add metadata data for the type of colocalization analysis (if the coloc did not return a NULL value (for e.g. if there were no SNPs in common between the GWAS and the eQTL analaysis.))
add_meta <- function(d,type_name,set_direction_to_0=FALSE){
if(!is.null(d)){
d <- d %>% mutate(type=type_name)
if(set_direction_to_0){
d <- d %>% mutate(direction=0)
}
}
return(d)
}
coloc_results_all <- mclapply(1:nrow(loci),function(i){
#Get coordinates from the GWAS locus
chrom_locus <- loci$chrom[i]
start <- loci$start[i] %>% as.numeric()
end <- loci$end[i] %>% as.numeric()
closest_gene_locus <- loci$locus_name_gene[i]
beta_top_GWAS_locus <- loci$beta_top_GWAS[i]
GWAS_snp_name <- loci$GWAS_snp[i]
GWAS_snp_pos_name <- loci$GWAS_snp_pos[i]
#Keep GWAS sumstats of SNPs in the locus
sumstats_locus <- filter(sumstats,chr==chrom_locus) %>%
filter(bp_b37>=start & bp_b37<=end)
#Running colocalization analysis
##GTEx
### eQTL
eqtl_blood <- prepare_eqtl_gtex(gtex_eqtl_blood_path,chrom_locus,sumstats_locus)
eqtl_blood_coloc <- run_coloc(eqtl_blood,'blood',sumstats_locus) %>%
add_meta(type_name='eQTL')
rm(eqtl_blood)
gc()
eqtl_spleen <- prepare_eqtl_gtex(gtex_eqtl_spleen_path,chrom_locus,sumstats_locus)
eqtl_spleen_coloc <- run_coloc(eqtl_spleen,'spleen',sumstats_locus) %>%
add_meta(type_name='eQTL')
rm(eqtl_spleen)
gc()
### sQTL
sqtl_blood <- prepare_eqtl_gtex(gtex_sqtl_blood_path,chrom_locus,sumstats_locus)
sqtl_blood_coloc <- run_coloc(sqtl_blood,'blood',sumstats_locus) %>%
add_meta(type_name='sQTL',set_direction_to_0=TRUE)
rm(sqtl_blood)
gc()
sqtl_spleen <- prepare_eqtl_gtex(gtex_sqtl_spleen_path,chrom_locus,sumstats_locus)
sqtl_spleen_coloc <- run_coloc(sqtl_spleen,'spleen',sumstats_locus) %>%
add_meta(type_name='sQTL',set_direction_to_0=TRUE)
rm(sqtl_spleen)
gc()
#Dice
dice_res <- lapply(1:nrow(dice_files), function(j){
dice_eqtl_file <- prepare_eqtl_dice(dice_files$files[j],chrom_locus,sumstats_locus)
dice_coloc <- run_coloc(dice_eqtl_file,dice_files$name[j],sumstats_locus,dice=TRUE) %>%
add_meta(type_name='eQTL')
rm(dice_eqtl_file)
gc()
return(dice_coloc)
}) %>% bind_rows()
pval_eqtl <- rbind(eqtl_blood_coloc,eqtl_spleen_coloc,sqtl_blood_coloc,sqtl_spleen_coloc,dice_res)
if(!is.null(pval_eqtl)){
pval_eqtl <- pval_eqtl %>%
mutate(locus=loci$locus_name[i],
coloc_method='beta') %>%
mutate(closest_gene=closest_gene_locus,
beta_top_GWAS=beta_top_GWAS_locus,
GWAS_snp=GWAS_snp_name,
GWAS_snp_pos=GWAS_snp_pos_name)
}
results <- pval_eqtl
if(!is.null(results)){
results <- results %>%
arrange(-PP.H4.abf) %>%
dplyr::select(locus,closest_gene,GWAS_snp,GWAS_snp_pos,beta_top_GWAS,everything())
}
return(results)
},mc.cores = 10,mc.preschedule = FALSE)
coloc_results_all <- coloc_results_all %>%
bind_rows() %>%
mutate(gene_parsed=str_extract(gene, "ENSG.+") %>% gsub('\\..+','',.)) %>%
arrange(-PP.H4.abf)
From biomart
mart <- useDataset("hsapiens_gene_ensembl", useMart("ensembl"))
genes <- unique(coloc_results_all$gene_parsed)
G_list <- getBM(filters= "ensembl_gene_id",
attributes= c("ensembl_gene_id","hgnc_symbol"),
values=genes,
mart= mart) %>%
dplyr::rename(gene_parsed=ensembl_gene_id)
coloc_results_all <- coloc_results_all %>% left_join(.,G_list,by='gene_parsed')
coloc_results_all <- coloc_results_all %>%
dplyr::select(locus:beta_top_GWAS,symbol=hgnc_symbol,ensembl=gene_parsed,nsnps:coloc_method)
loeuf <- read_tsv('data/gnomad_loeuf/supplementary_dataset_11_full_constraint_metrics.tsv') %>%
filter(canonical==TRUE) %>%
dplyr::select(gene,gene_id,transcript,oe_lof_upper,p) %>%
mutate(oe_lof_upper_bin = ntile(oe_lof_upper, 10)) %>%
dplyr::rename(ensembl=gene_id,symbol=gene) %>%
dplyr::select(ensembl,oe_lof_upper_bin)
coloc_results_all <- left_join(coloc_results_all,loeuf,by='ensembl')
dir.create('output/coloc',showWarnings = FALSE)
write_tsv(coloc_results_all,paste0('output/coloc/coloc.',selected_trait,'.gtex_dice.txt'))
sessionInfo()
R version 4.0.1 (2020-06-06)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)
Matrix products: default
BLAS/LAPACK: /pstore/apps/OpenBLAS/0.3.1-GCC-7.3.0-2.30/lib/libopenblasp-r0.3.1.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] parallel stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] biomaRt_2.44.4 arrow_2.0.0 coloc_5.1.0 data.table_1.12.8
[5] forcats_0.5.0 stringr_1.4.0 dplyr_1.0.0 purrr_0.3.4
[9] readr_1.3.1 tidyr_1.1.0 tibble_3.0.1 ggplot2_3.3.3
[13] tidyverse_1.3.0
loaded via a namespace (and not attached):
[1] nlme_3.1-148 fs_1.4.1 lubridate_1.7.9
[4] bit64_0.9-7 progress_1.2.2 httr_1.4.1
[7] rprojroot_1.3-2 tools_4.0.1 backports_1.1.7
[10] R6_2.4.1 irlba_2.3.3 DBI_1.1.0
[13] BiocGenerics_0.34.0 colorspace_1.4-1 withr_2.2.0
[16] prettyunits_1.1.1 tidyselect_1.1.0 gridExtra_2.3
[19] curl_4.3 bit_1.1-15.2 compiler_4.0.1
[22] git2r_0.27.1 cli_2.0.2 rvest_0.3.5
[25] Biobase_2.48.0 xml2_1.3.2 scales_1.1.1
[28] askpass_1.1 rappdirs_0.3.1 mixsqp_0.3-43
[31] digest_0.6.25 rmarkdown_2.2 pkgconfig_2.0.3
[34] htmltools_0.5.1.1 dbplyr_1.4.4 rlang_0.4.10
[37] readxl_1.3.1 susieR_0.11.42 rstudioapi_0.11
[40] RSQLite_2.2.0 generics_0.0.2 jsonlite_1.6.1
[43] vroom_1.3.2 magrittr_1.5 Matrix_1.2-18
[46] Rcpp_1.0.6 munsell_0.5.0 S4Vectors_0.26.1
[49] fansi_0.4.1 viridis_0.5.1 lifecycle_0.2.0
[52] stringi_1.4.6 whisker_0.4 yaml_2.2.1
[55] BiocFileCache_1.12.0 plyr_1.8.6 grid_4.0.1
[58] blob_1.2.1 promises_1.1.1 crayon_1.3.4
[61] lattice_0.20-41 haven_2.3.1 hms_0.5.3
[64] knitr_1.28 pillar_1.4.4 stats4_4.0.1
[67] reprex_0.3.0 XML_3.99-0.3 glue_1.4.1
[70] evaluate_0.14 modelr_0.1.8 vctrs_0.3.1
[73] httpuv_1.5.4 cellranger_1.1.0 openssl_1.4.1
[76] gtable_0.3.0 reshape_0.8.8 assertthat_0.2.1
[79] xfun_0.14 broom_0.5.6 later_1.1.0.1
[82] viridisLite_0.3.0 AnnotationDbi_1.50.0 memoise_1.1.0
[85] IRanges_2.22.2 workflowr_1.6.2 ellipsis_0.3.1