Last updated: 2020-10-25

Checks: 6 1

Knit directory: Comparative_eQTL/analysis/

This reproducible R Markdown analysis was created with workflowr (version 1.5.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(20190319) 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 version displayed above was the version of the Git repository at the time these results were generated.

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:    .RData
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    WorkingManuscript.zip
    Ignored:    WorkingManuscript/
    Ignored:    analysis/.DS_Store
    Ignored:    analysis/.Rhistory
    Ignored:    analysis_temp/.DS_Store
    Ignored:    big_data/
    Ignored:    code/.DS_Store
    Ignored:    code/snakemake_workflow/.DS_Store
    Ignored:    code/snakemake_workflow/.Rhistory
    Ignored:    data/.DS_Store
    Ignored:    data/PastAnalysesDataToKeep/.DS_Store
    Ignored:    figures/
    Ignored:    output/.DS_Store

Untracked files:
    Untracked:  analysis/.index.Rmd.swp
    Untracked:  analysis/20200907_Response_Point_02.Rmd
    Untracked:  analysis/20200907_Response_Point_04.Rmd
    Untracked:  analysis/20200907_Response_Point_07.Rmd
    Untracked:  analysis/20200907_Response_Point_08.Rmd
    Untracked:  analysis/20200907_Response_Point_11_2.Rmd
    Untracked:  analysis/20201012_MakeSourceData.Rmd
    Untracked:  data/FinalSourceData/
    Untracked:  data/c5.all.v7.1.symbols.gmt
    Untracked:  data/c5.all.v7.1.symbols.gmt.categories.tsv.gz
    Untracked:  data/h.all.v7.1.symbols.gmt

Unstaged changes:
    Modified:   README.md
    Modified:   analysis/20200907_Response_OriginalComments.Rmd
    Modified:   analysis/20200907_Response_Point_06.Rmd
    Modified:   analysis/20200907_Response_Point_09-2.Rmd
    Modified:   analysis/20200907_Response_Point_09.Rmd
    Modified:   analysis/20200907_Response_Point_11.Rmd
    Modified:   analysis/Final_2_DispersionPlots.Rmd
    Modified:   analysis/about.Rmd
    Modified:   analysis/index.Rmd
    Modified:   analysis_temp/TabulaMuris_analysis2.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.


See here for a more description.

Here, I will take the cell type specific dispersion point estimates described in the link above, and examine the bootstrapped standard errors (1000 replicates, resampled at the stage of different individuals after TED expression estimation) that were produced a part of the snakemake in the code section of this repo.

First, load libraries and data

library(tidyverse)
library(knitr)

Bootstrapped.SE.estimates <- read.delim("../output/CellTypeDispersion.SE.tsv.gz")
DispersionPointEstimates <- readRDS("../big_data/NormalizedExpressionPerCellType.rds") %>%
  group_by(gene, CellType, Species) %>%
  summarise(mu=mean(Log.CPM.Expression), log.var=log(var(Log.CPM.Expression))) %>%
  group_by(Species, CellType) %>% 
    do(data.frame(., resid = residuals(loess(log.var ~ mu, data=., degree=1, na.action="na.exclude"))))

CellTypeDispersion.df <- inner_join(Bootstrapped.SE.estimates, DispersionPointEstimates, by=c("CellType", "Species", "gene"))

head(CellTypeDispersion.df) %>% kable()
CellType Species gene mu.SE resid.SE mu log.var resid
cardiac muscle cell Chimp ENSG00000000003 0.0929669 0.1288482 1.3636554 -1.0070469 0.2349300
cardiac muscle cell Chimp ENSG00000000005 0.1713368 0.1838315 -0.9277903 0.2284514 1.0082161
cardiac muscle cell Chimp ENSG00000000457 0.0932767 0.1895129 1.2044743 -1.0083992 0.1977176
cardiac muscle cell Chimp ENSG00000001036 0.0530243 0.3162196 3.4908040 -2.1931103 -0.7386727
cardiac muscle cell Chimp ENSG00000001084 0.1275738 0.2238554 0.8604686 -0.3640991 0.7645701
cardiac muscle cell Chimp ENSG00000001167 0.0531067 0.1944670 1.6356742 -2.1726169 -0.8758627
Dispersion <- read.delim('../output/Final/TableS3.tab')
head(Dispersion) %>% kable()
gene HGNC.symbol Chimp.Mean.Expression Human.Mean.Expression Chimp.Overdispersion Human.Overdispersion Chimp.Mean.Adjusted.Dispersion Human.Mean.Adjusted.Dispersion Chimp.SE Human.SE P q.value
ENSG00000186891 TNFRSF18 -20.04475 -22.72507 2.1055309 0.6147549 2.3121799 0.0805422 0.3799365 1.2023115 0.0054 0.0317946
ENSG00000186827 TNFRSF4 -18.77917 -19.33208 0.6203152 0.8582437 1.6405781 1.9529450 0.2157222 0.3020914 0.3439 0.3126680
ENSG00000078808 SDF4 -17.25701 -17.12363 0.0583115 0.0420739 -0.5386575 -0.8183559 0.2215974 0.2267717 0.3624 0.3210003
ENSG00000176022 B3GALT6 -18.54108 -18.71933 0.0921186 0.0543682 -0.2006514 -0.6565939 0.2894171 0.2657152 0.3434 0.3124612
ENSG00000184163 C1QTNF12 -20.22992 -20.96884 0.9431169 0.3705950 1.4085703 0.3109663 0.3138983 0.4147022 0.0662 0.1329230
ENSG00000160087 UBE2J2 -18.96377 -18.91956 0.0832274 0.0533650 -0.4256215 -0.7154168 0.2888279 0.3411127 0.4752 0.3657044

Let’s plot some things to explore… Is the distribution of gene expression and standard errors obviously different in different cell types?

CellTypeDispersion.df %>%
  ggplot(aes(x=mu, color=CellType)) +
  geom_density(aes(linetype=Species)) +
  facet_wrap(~CellType) +
  theme_bw()

CellTypeDispersion.df %>%
  ggplot(aes(x=mu.SE, color=CellType)) +
  geom_density(aes(linetype=Species)) +
  facet_wrap(~CellType) +
  theme_bw()

CellTypeDispersion.df %>%
  ggplot(aes(x=resid, color=CellType)) +
  geom_density(aes(linetype=Species)) +
  facet_wrap(~CellType) +
  theme_bw()

CellTypeDispersion.df %>%
  ggplot(aes(x=resid.SE, color=CellType)) +
  geom_density(aes(linetype=Species)) +
  facet_wrap(~CellType) +
  theme_bw()

Ok, write out the results

CellTypeDispersion.df %>%
  dplyr::select(Species, CellType, gene, MeanExpression=mu, MeanExpression.StandardError=mu.SE, Overdispersion=log.var, Mean.Adjusted.Dispersion=resid, Mean.Adjusted.Dispersion.StandardError=resid.SE) %>%
  write_delim("../figures/CellTypeDispersion.Reorganized.source.data.tsv", delim='\t')

sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.5

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/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] knitr_1.26      forcats_0.4.0   stringr_1.4.0   dplyr_1.0.2    
 [5] purrr_0.3.3     readr_1.3.1     tidyr_1.0.0     tibble_3.0.3   
 [9] ggplot2_3.3.2   tidyverse_1.3.0

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.0 xfun_0.11        haven_2.2.0      colorspace_1.4-1
 [5] vctrs_0.3.4      generics_0.0.2   htmltools_0.4.0  yaml_2.2.0      
 [9] rlang_0.4.7      later_1.0.0      pillar_1.4.6     withr_2.1.2     
[13] glue_1.4.2       DBI_1.0.0        dbplyr_1.4.2     modelr_0.1.5    
[17] readxl_1.3.1     lifecycle_0.2.0  munsell_0.5.0    gtable_0.3.0    
[21] workflowr_1.5.0  cellranger_1.1.0 rvest_0.3.5      evaluate_0.14   
[25] labeling_0.3     httpuv_1.5.2     fansi_0.4.0      highr_0.8       
[29] broom_0.7.0      Rcpp_1.0.5       promises_1.1.0   backports_1.1.5 
[33] scales_1.1.1     jsonlite_1.6     farver_2.0.3     fs_1.3.1        
[37] hms_0.5.2        digest_0.6.23    stringi_1.4.3    grid_3.6.1      
[41] rprojroot_1.3-2  cli_2.0.0        tools_3.6.1      magrittr_1.5    
[45] crayon_1.3.4     pkgconfig_2.0.3  ellipsis_0.3.0   xml2_1.2.2      
[49] reprex_0.3.0     lubridate_1.7.9  assertthat_0.2.1 rmarkdown_1.18  
[53] httr_1.4.1       rstudioapi_0.10  R6_2.4.1         git2r_0.26.1    
[57] compiler_3.6.1