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/06_eqtl_epigenome_enrichment.Rmd) and HTML (docs/06_eqtl_epigenome_enrichment.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 c6844a1 Julien Bryois 2022-01-28 Build site.
html 17aa0ed Julien Bryois 2022-01-28 Build site.
Rmd d1c1d2d Julien Bryois 2022-01-28 epigenome_enrichment
html 311cd5c Julien Bryois 2022-01-25 Build site.
Rmd 837ddf9 Julien Bryois 2022-01-25 eQTL GWAS epigenome enrichment

Libraries

library(tidyverse)
library(parallel)
library(liftOver)

Prepare eQTL data

d_sig <- read_tsv('output/eqtl/eqtl.PC70.txt') %>% 
  filter(adj_p<0.05) %>% 
  dplyr::select(cell_type,pid,sid)
geno <- read_tsv('data_sensitive/genotypes/processed/snp_pos_hg38.txt',col_names=FALSE) %>% 
  setNames(c('chr','end','sid')) %>% 
  mutate(start=end) %>% 
  mutate(snp_pos_hg38=paste0(chr,':',start)) %>% 
  dplyr::select(sid,chr,start,end,snp_pos_hg38)
d_sig <- inner_join(d_sig,geno,by='sid')
cell_types <- unique(d_sig$cell_type)
write_bed <- function(i){
  
  d_cell <- filter(d_sig,cell_type==cell_types[i]) %>% 
    dplyr::select(chr,start,end,snp_pos_hg38,pid) %>% mutate(strand='+') %>% 
    arrange(chr,start)
  dir.create('data/epigenome_enrichment/fdensity',showWarnings = FALSE,recursive = TRUE)
  write_tsv(d_cell,paste0('data/epigenome_enrichment/fdensity/',make.names(cell_types[i]),'.sig5FDR.bed'),col_names = FALSE)
}
lapply(1:length(cell_types),write_bed)

Prepare phenotype data

  1. Get gene coordinates
gtf <- rtracklayer::import('data/gencode/Homo_sapiens.GRCh38.96.filtered.gtf') %>% 
  as.data.frame() %>% 
  dplyr::filter(type=='gene') %>% 
  mutate(TSS_start=ifelse(strand=='+',start,end),
         TSS_end=ifelse(strand=='+',start,end)) %>% 
  mutate(gene=paste0(gene_name,'_',gene_id)) %>% 
  dplyr::select(seqnames,TSS_start,TSS_end,gene,gene_name,strand) %>% 
  filter(seqnames%in%c(1:22)) %>% 
  dplyr::select(gene,strand) %>% 
  as_tibble()
  1. For each cell type get phenotypes mapped
files <- list.files('data_sensitive/eqtl',pattern='.bed.gz$',full.names = TRUE)
get_phenotype_coord <- function(i){
  pheno <- read_tsv(files[i]) %>% dplyr::select(1:4) %>% mutate(random='.') %>% dplyr::rename(gene=ID) %>% 
    left_join(.,gtf,by='gene')
  write_tsv(pheno,paste0('data/epigenome_enrichment/fdensity/',make.names(cell_types[i]),'.pheno.bed'),col_names = FALSE)
}
mclapply(1:length(files),get_phenotype_coord)

Prepare Annotation

Process data from Corces et al.

corces <- readxl::read_xlsx('data/epigenome_enrichment/external_data/corces/Corces_etal_Nat_Neuro_2020_TableS4.xlsx',skip=16)
corces <- corces %>% 
  gather(cell_type,present,ExcitatoryNeurons:OPCs) %>% 
  group_by(Peak_ID) %>% 
  mutate(count_present=sum(present)) %>% 
  ungroup()
corces_specific <- corces %>% filter(present==1,count_present==1)

Write bed files

write_bed_annot <- function(i,df,name){
  dir.create('data/epigenome_enrichment/fdensity/corces',showWarnings = FALSE)
  df %>% filter(cell_type==cell_types[i]) %>% 
    dplyr::select(hg38_Chromosome,hg38_Start,hg38_Stop,Peak_ID) %>% 
    mutate(hg38_Chromosome=gsub('chr','',hg38_Chromosome)) %>% 
    write_tsv(.,paste0('data/epigenome_enrichment/fdensity/corces/',make.names(cell_types[i]),'.corces.',name,'.bed'),col_names = FALSE)
}
cell_types <- unique(corces_specific$cell_type)
lapply(1:length(cell_types),write_bed_annot,df=corces_specific,name='specific')

Process data from Fullard et al.

Get DLPFC specific peaks using bedtools

mkdir -p data/epigenome_enrichment/fdensity/fullard
cd data/epigenome_enrichment/fdensity/fullard
source ~/.bashrc
ml bedtools/2.25.0-goolf-1.7.20
bedtools intersect -v -a DLPFC_neuron.bed -b DLPFC_glia.bed > DLPFC_neuron.specific.bed
bedtools intersect -v -a DLPFC_glia.bed -b DLPFC_neuron.bed > DLPFC_glia.specific.bed

Process data from Nott et al.

path <-  system.file(package="liftOver", "extdata", "hg19ToHg38.over.chain")
ch <-  import.chain(path)
lift_to_h38 <- function(df,out){
  df <- setNames(df,c('chr','start','end')) %>% filter(!is.na(chr)) %>%  makeGRangesFromDataFrame(., TRUE)
  seqlevelsStyle(df) <-  "UCSC" 
  df_hg38 <- liftOver(df, ch) %>% 
    unlist() %>% 
    as.data.frame() %>% 
    as_tibble() %>% 
    mutate(seqnames=gsub('chr','',seqnames)) %>%
    filter(seqnames%in%1:22) %>%
    arrange(seqnames,start) %>% 
    dplyr::select(seqnames,start,end) %>% 
    sample_n(min(25000,nrow(.))) %>% #get at most 25000 peaks, more leads to failure of QTLtools for unknown reason
    write_tsv(.,paste0('data/epigenome_enrichment/fdensity/nott/',out),col_names = FALSE)
}
astro_enh <- readxl::read_xlsx('data/epigenome_enrichment/external_data/nott/Nott_etal_Science2019_Table_S5.xlsx',skip=0,sheet=5) %>% 
  lift_to_h38(.,out='Astrocytes.enhancer.bed')
neuronal_enh <- readxl::read_xlsx('data/epigenome_enrichment/external_data/nott/Nott_etal_Science2019_Table_S5.xlsx',skip=0,sheet=7) %>% 
  lift_to_h38(.,out='Neuronal.enhancer.bed')
oligo_enh <- readxl::read_xlsx('data/epigenome_enrichment/external_data/nott/Nott_etal_Science2019_Table_S5.xlsx',skip=0,sheet=9) %>% 
  lift_to_h38(.,out='Oligodendrocytes.enhancer.bed')
micro_enh <- readxl::read_xlsx('data/epigenome_enrichment/external_data/nott/Nott_etal_Science2019_Table_S5.xlsx',skip=0,sheet=11) %>% 
  lift_to_h38(.,out='Microglia.enhancer.bed')

Enhancer specific peaks

cd data/epigenome_enrichment/fdensity/nott
source ~/.bashrc
ml bedtools/2.25.0-goolf-1.7.20
bedtools intersect -v -a Astrocytes.enhancer.bed -b Microglia.enhancer.bed Neuronal.enhancer.bed Oligodendrocytes.enhancer.bed > Astrocytes.enhancer_specific.bed
bedtools intersect -v -a Microglia.enhancer.bed -b Astrocytes.enhancer.bed Neuronal.enhancer.bed Oligodendrocytes.enhancer.bed > Microglia.enhancer_specific.bed
bedtools intersect -v -a Neuronal.enhancer.bed -b Astrocytes.enhancer.bed Microglia.enhancer.bed Oligodendrocytes.enhancer.bed > Neuronal.enhancer_specific.bed
bedtools intersect -v -a Oligodendrocytes.enhancer.bed -b Astrocytes.enhancer.bed Microglia.enhancer.bed Neuronal.enhancer.bed > Oligodendrocytes.enhancer_specific.bed

Epigenome Enrichment

Corces

ml GSL/2.5-GCCcore-7.3.0
ml Boost/1.67.0-foss-2018b

source ~/.bashrc
cd data/epigenome_enrichment/fdensity
mkdir -p results/corces

for f in *sig5FDR.bed
do
echo $f
for f2 in corces/*.corces.*
do
f2_name=`basename $f2`
QTLtools fdensity --qtl $f --bed $f2 --bin 10000 --out results/corces/density_${f}_${f2_name}
done
done

Fullard

ml GSL/2.5-GCCcore-7.3.0
ml Boost/1.67.0-foss-2018b

source ~/.bashrc

cd data/epigenome_enrichment/fdensity
mkdir -p results/fullard

for f in *.sig5FDR.bed
do
echo $f
for f2 in fullard/*specific.bed
do
f2_name=`basename $f2`
QTLtools fdensity --qtl $f --bed $f2 --bin 10000 --out results/fullard/density_${f}_${f2_name}
done
done

Nott

ml GSL/2.5-GCCcore-7.3.0
ml Boost/1.67.0-foss-2018b

source ~/.bashrc

cd data/epigenome_enrichment/fdensity
mkdir -p results/nott

for f in *.sig5FDR.bed
do
echo $f
for f2 in nott/*.bed
do
f2_name=`basename $f2`
QTLtools fdensity --qtl $f --bed $f2 --bin 10000 --out results/nott/density_${f}_${f2_name}
done
done

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] stats4    parallel  stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
 [1] liftOver_1.12.0                        
 [2] Homo.sapiens_1.3.1                     
 [3] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2
 [4] org.Hs.eg.db_3.11.4                    
 [5] GO.db_3.11.4                           
 [6] OrganismDbi_1.30.0                     
 [7] GenomicFeatures_1.40.0                 
 [8] AnnotationDbi_1.50.0                   
 [9] Biobase_2.48.0                         
[10] rtracklayer_1.48.0                     
[11] GenomicRanges_1.40.0                   
[12] GenomeInfoDb_1.24.0                    
[13] IRanges_2.22.2                         
[14] S4Vectors_0.26.1                       
[15] BiocGenerics_0.34.0                    
[16] gwascat_2.20.1                         
[17] forcats_0.5.0                          
[18] stringr_1.4.0                          
[19] dplyr_1.0.0                            
[20] purrr_0.3.4                            
[21] readr_1.3.1                            
[22] tidyr_1.1.0                            
[23] tibble_3.0.1                           
[24] ggplot2_3.3.3                          
[25] tidyverse_1.3.0                        
[26] workflowr_1.6.2                        

loaded via a namespace (and not attached):
 [1] colorspace_1.4-1            ellipsis_0.3.1             
 [3] rprojroot_1.3-2             XVector_0.28.0             
 [5] fs_1.4.1                    rstudioapi_0.11            
 [7] bit64_0.9-7                 fansi_0.4.1                
 [9] lubridate_1.7.9             xml2_1.3.2                 
[11] knitr_1.28                  jsonlite_1.6.1             
[13] Rsamtools_2.4.0             broom_0.5.6                
[15] dbplyr_1.4.4                graph_1.66.0               
[17] BiocManager_1.30.10         compiler_4.0.1             
[19] httr_1.4.1                  backports_1.1.7            
[21] assertthat_0.2.1            Matrix_1.2-18              
[23] cli_2.0.2                   later_1.1.0.1              
[25] htmltools_0.5.1.1           prettyunits_1.1.1          
[27] tools_4.0.1                 gtable_0.3.0               
[29] glue_1.4.1                  GenomeInfoDbData_1.2.3     
[31] rappdirs_0.3.1              Rcpp_1.0.6                 
[33] cellranger_1.1.0            vctrs_0.3.1                
[35] Biostrings_2.56.0           nlme_3.1-148               
[37] xfun_0.14                   rvest_0.3.5                
[39] lifecycle_0.2.0             XML_3.99-0.3               
[41] zlibbioc_1.34.0             scales_1.1.1               
[43] hms_0.5.3                   promises_1.1.1             
[45] SummarizedExperiment_1.18.1 RBGL_1.64.0                
[47] yaml_2.2.1                  curl_4.3                   
[49] memoise_1.1.0               biomaRt_2.44.4             
[51] stringi_1.4.6               RSQLite_2.2.0              
[53] BiocParallel_1.22.0         rlang_0.4.10               
[55] pkgconfig_2.0.3             bitops_1.0-6               
[57] matrixStats_0.56.0          evaluate_0.14              
[59] lattice_0.20-41             GenomicAlignments_1.24.0   
[61] bit_1.1-15.2                tidyselect_1.1.0           
[63] magrittr_1.5                R6_2.4.1                   
[65] generics_0.0.2              DelayedArray_0.14.0        
[67] DBI_1.1.0                   pillar_1.4.4               
[69] haven_2.3.1                 whisker_0.4                
[71] withr_2.2.0                 RCurl_1.98-1.2             
[73] modelr_0.1.8                crayon_1.3.4               
[75] utf8_1.1.4                  BiocFileCache_1.12.0       
[77] rmarkdown_2.2               progress_1.2.2             
[79] grid_4.0.1                  readxl_1.3.1               
[81] blob_1.2.1                  git2r_0.27.1               
[83] reprex_0.3.0                digest_0.6.25              
[85] httpuv_1.5.4                openssl_1.4.1              
[87] munsell_0.5.0               askpass_1.1