Last updated: 2021-12-28

Checks: 7 0

Knit directory: ChromatinSplicingQTLs/analysis/

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(20191126) 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 89517ff. 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:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    ._.DS_Store
    Ignored:    analysis/.Rhistory
    Ignored:    code/.DS_Store
    Ignored:    code/.Rhistory
    Ignored:    code/._.DS_Store
    Ignored:    code/._README.md
    Ignored:    code/._dag.pdf
    Ignored:    code/._report.html
    Ignored:    code/.ipynb_checkpoints/
    Ignored:    code/.snakemake/
    Ignored:    code/Alignments/
    Ignored:    code/ENCODE/
    Ignored:    code/ExpressionAnalysis/
    Ignored:    code/Fastq/
    Ignored:    code/FastqFastp/
    Ignored:    code/FastqFastpSE/
    Ignored:    code/FastqSE/
    Ignored:    code/Gather_gwas_summary_stats/
    Ignored:    code/Genotypes/
    Ignored:    code/Multiqc/
    Ignored:    code/Multiqc_chRNA/
    Ignored:    code/PeakCalling/
    Ignored:    code/Phenotypes/
    Ignored:    code/PlotGruberQTLs/
    Ignored:    code/ProCapAnalysis/
    Ignored:    code/QC/
    Ignored:    code/QTLs/
    Ignored:    code/ReferenceGenome/
    Ignored:    code/Session.vim
    Ignored:    code/SplicingAnalysis/
    Ignored:    code/TODO
    Ignored:    code/bigwigs/
    Ignored:    code/bigwigs_FromNonWASPFilteredReads/
    Ignored:    code/config/.DS_Store
    Ignored:    code/config/._.DS_Store
    Ignored:    code/config/ExternalFastqDataAccessions/
    Ignored:    code/config/OldSamplesConfig/
    Ignored:    code/dag.pdf
    Ignored:    code/featureCounts/
    Ignored:    code/gwas_summary_stats/
    Ignored:    code/hyprcoloc/
    Ignored:    code/logs/
    Ignored:    code/notebooks/.ipynb_checkpoints/
    Ignored:    code/out.hap.ld
    Ignored:    code/out.log
    Ignored:    code/report.html
    Ignored:    code/rules/OldRules/
    Ignored:    code/scratch/
    Ignored:    code/scripts/GTFtools_0.8.0/
    Ignored:    code/scripts/__pycache__/
    Ignored:    code/scripts/liftOverBedpe/liftOverBedpe.py
    Ignored:    code/snakemake.log
    Ignored:    code/snakemake.sbatch.log
    Ignored:    data/._PRJEB1350_RunTable.Ding_etal_CTCF.txt
    Ignored:    data/._igsr_samples.tsv
    Ignored:    data/._list_gwas_summary_statistics_PMID27863252.csv
    Ignored:    data/GrowthNotes/._20210830_GrowthNotes_chRNA.ConcentrationsToReplate.txt

Untracked files:
    Untracked:  code/envs/r_2.yaml
    Untracked:  code/snakemake_profiles/slurm/__pycache__/

Unstaged changes:
    Modified:   code/rules/report.smk
    Modified:   code/scripts/GenometracksByGenotype
    Modified:   output/hyprcoloc_results/ForColoc/hyprcoloc.results.txt.gz

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/20211217_GenewiseColocFirstLook.Rmd) and HTML (docs/20211217_GenewiseColocFirstLook.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
Rmd 89517ff Benjmain Fair 2021-12-22 added genewise coloc rmd

Introduction

I have colocalized a bunch of molecular phenotypes in the window of each gene (Locus). Chromatin phenotypes and other genes must be within +/- 100kb of the gene. Splicing events must be within the gene. Nominal permutation Pvalues must be under 0.01. The real results are subject to change, since there are many more molecular phenotypes I haven’t included in this analysis, due to computational impatience, and that I am still collecting data. So I will evenetually include more phenotype which will change the results. More details of the methods are embedded in the snakemake pipeline. Here I will get some intuitions about the results.

Analysis

First, load necessary libraries

library(tidyverse)
library(viridis)

dat <- read_tsv("../output/hyprcoloc_results/ForColoc/hyprcoloc.results.txt.gz", col_names = c("Locus", "iteration", 'ColocalizedTraits', 'ColocPr', 'RegionalPr', "topSNP", "TopSNPFinemapPr", "DroppedTrait"), skip=1)

First question:

how many traits attempted to colocalized per gene:

dat %>%
  mutate(NumTraits = str_count(ColocalizedTraits, ",") + 1) %>%
  group_by(Locus) %>%
  summarise(TotalTraitsAttemptedColocalization = sum(NumTraits)+1) %>%
  ggplot(aes(x=TotalTraitsAttemptedColocalization)) +
  stat_ecdf() +
  ylab("cumulative fraction") +
  xlab("Number molecular traits attempted to colocalize for each gene locus") +
  theme_light()

Now how many traits actually colocalized per gene:

dat %>%
  mutate(NumTraits = str_count(ColocalizedTraits, ",") ) %>%
  mutate(NumColocalizedTraits  = case_when(
    NumTraits > 0 ~ NumTraits +1,
    TRUE ~ 0
  )) %>%
  group_by(Locus) %>%
  summarise(TotalTraitsColocalized = sum(NumColocalizedTraits)) %>%
  ggplot(aes(x=TotalTraitsColocalized)) +
  stat_ecdf() +
  ylab("cumulative fraction") +
  xlab("Number molecular traits colocalize for each gene locus") +
  theme_light()

Now how many colocalizations involve each type of molecular trait. I’m envisioning a matrix of how many colocalizations were attempted for each trait family pair, and how many times they were actually colocalized.

set.seed(0)
ToSplit <- dat %>%
  select(Locus, ColocalizedTraits, iteration, DroppedTrait) %>%
  # filter(Locus %in% (dat$Locus %>% unique() %>% head(200))) %>%
  mutate(ColocalizedTraits = str_replace(ColocalizedTraits, paste0(Locus, ", "), "")) %>%
  separate_rows(ColocalizedTraits, sep = ' ') %>%
  mutate(Trait = case_when(
    ColocalizedTraits == "None" ~ DroppedTrait,
    TRUE ~ ColocalizedTraits
  )) %>%
  select(Locus, Trait, iteration) %>%
  group_by(Locus)


ToMat <- function(df){
  xp <- df %>%
  select(Trait, iteration) %>%
  deframe()

  mat <- apply(as.matrix(xp), 1, 
                   function(x) as.numeric(x==as.matrix(xp)))
  rownames(mat) <- colnames(mat)
  # mat[upper.tri(mat, diag=T)] <- NA
  mat[diag(mat)] <- NA
return(mat)
}

SumColocsByPhenotypeClass <- function(mat){
  mat %>%
  as.data.frame() %>%
  rownames_to_column("Trait1") %>%
  gather(key="Trait2", value="IsColoc", -Trait1) %>%
  mutate(
    Trait1 = str_replace(Trait1, "(.+?);.+", "\\1"),
    Trait2 = str_replace(Trait2, "(.+?);.+", "\\1")
    ) %>%
  drop_na() %>%
  group_by(Trait1, Trait2) %>%
  summarise(NumColocs = sum(IsColoc)) %>%
  return()
}

SumColocAttemptsByPhenotypeClass <- function(mat){
  mat %>%
  as.data.frame() %>%
  rownames_to_column("Trait1") %>%
  gather(key="Trait2", value="IsColoc", -Trait1) %>%
  mutate(
    Trait1 = str_replace(Trait1, "(.+?);.+", "\\1"),
    Trait2 = str_replace(Trait2, "(.+?);.+", "\\1")
    ) %>%
  drop_na() %>%
  mutate(IsColoc=1) %>%
  group_by(Trait1, Trait2) %>%
  summarise(NumColocs = sum(IsColoc)) %>%
  return()
}



Split.list <- setNames(group_split(ToSplit), deframe(group_keys(ToSplit)))

Mat.list <- lapply(Split.list, ToMat)

## Some sanity checks that this code works as expected
# Mat.list[[3]] %>%
#   write.table(row.names = F, col.names = F)


SumColocs.list <- lapply(Mat.list, SumColocsByPhenotypeClass)
SumAttemptedColocs.list <- lapply(Mat.list, SumColocAttemptsByPhenotypeClass)


Coloc.ByClass.Summary <- bind_rows(SumColocs.list, .id="Locus") %>%
  inner_join(
    bind_rows(SumAttemptedColocs.list, .id="Locus"),
    by=c("Trait1", "Trait2", "Locus"),
    suffix = c(".Success", ".Attemped")
  ) %>%
  # filter(Locus == "ENSG00000114378.17")
  group_by(Trait1, Trait2) %>%
  summarise(
    Colocs = sum(NumColocs.Success),
    ColocAttempts = sum(NumColocs.Attemped))

Coloc.ByClass.Summary %>%
  arrange(Trait1, Trait2) %>%
  gather(key="AttemptOrSuccess", value="NumColocs", Colocs, ColocAttempts) %>%
  mutate(NumColocs = NumColocs/2) %>%
  ggplot(aes(x=Trait1, y=Trait2, fill=NumColocs)) +
  geom_raster() +
  scale_fill_viridis(trans="log10", option="B") +
  facet_wrap(~AttemptOrSuccess) +
  theme_light() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))

#Plot fill color by rate
Coloc.ByClass.Summary %>%
  mutate(ColocRate = Colocs/ColocAttempts * 100) %>%
  arrange(Trait1, Trait2) %>%
  ggplot(aes(x=Trait1, y=Trait2, fill=ColocRate)) +
  geom_raster() +
  scale_fill_viridis(option="B") +
  theme_light() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))

Conclusions

Some thing make sense. polyA.splicing traits often colocalize with other polyA.Splicing traits, which is unsurprisingly biologically and also technically since intra-cluster introns are not independent quantifications. H3K27ME3 and H3K4ME3 also tend to colocalize.

The colocalization rate might be more informative, in the sense that the results match by expectations for which traits might colocalize.


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

Matrix products: default
BLAS/LAPACK: /project2/yangili1/bjf79/ChromatinSplicingQTLs/code/.snakemake/conda/c945d3ed441f0cb7ff83e43424561c95/lib/R/lib/libRblas.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] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] viridis_0.5.1     viridisLite_0.3.0 forcats_0.5.1     stringr_1.4.0    
 [5] dplyr_1.0.5       purrr_0.3.4       readr_1.4.0       tidyr_1.1.3      
 [9] tibble_3.1.0      ggplot2_3.3.3     tidyverse_1.3.0  

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6        lubridate_1.7.10  ps_1.6.0          assertthat_0.2.1 
 [5] rprojroot_2.0.2   digest_0.6.27     utf8_1.2.1        R6_2.5.0         
 [9] cellranger_1.1.0  backports_1.2.1   reprex_1.0.0      evaluate_0.14    
[13] highr_0.8         httr_1.4.2        pillar_1.5.1      rlang_0.4.10     
[17] readxl_1.3.1      rstudioapi_0.13   whisker_0.4       jquerylib_0.1.3  
[21] rmarkdown_2.7     labeling_0.4.2    munsell_0.5.0     broom_0.7.6      
[25] compiler_3.6.1    httpuv_1.5.5      modelr_0.1.8      xfun_0.20        
[29] pkgconfig_2.0.3   htmltools_0.5.1.1 tidyselect_1.1.0  gridExtra_2.3    
[33] workflowr_1.6.2   fansi_0.4.2       crayon_1.4.1      dbplyr_2.1.1     
[37] withr_2.4.1       later_1.1.0.1     grid_3.6.1        jsonlite_1.7.2   
[41] gtable_0.3.0      lifecycle_1.0.0   DBI_1.1.1         git2r_0.28.0     
[45] magrittr_2.0.1    scales_1.1.1      cli_2.4.0         stringi_1.4.3    
[49] farver_2.1.0      fs_1.5.0          promises_1.2.0.1  xml2_1.3.2       
[53] bslib_0.2.4       ellipsis_0.3.1    generics_0.1.0    vctrs_0.3.7      
[57] tools_3.6.1       glue_1.4.2        hms_1.0.0         yaml_2.2.1       
[61] colorspace_2.0-0  rvest_1.0.0       knitr_1.31        haven_2.3.1      
[65] sass_0.3.1