• Flash model based on effects:
  • Flash model based on z scores:
  • Estimated null cor V
  • Results

Last updated: 2020-01-15

Checks: 7 0

Knit directory: GTEx/

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.


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(20181220) 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:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    dsc-mash-gtex/

Untracked files:
    Untracked:  .DS_Store
    Untracked:  analysis/.DS_Store
    Untracked:  code/Demo_SumstatQuery.R
    Untracked:  code/SexDE.TAU.R
    Untracked:  code/SexDE_get_genes.R
    Untracked:  data/.DS_Store
    Untracked:  data/cor_tissues_non_ash_voom_pearson.rda
    Untracked:  data/gene_names_GTEX_V6.txt
    Untracked:  data/genewide_ash_out_tissue_mat_halfuniform_non_mode.rda
    Untracked:  data/meta.ivw.sexde_logfc_matrix.sexde.svs.allgenes.v8.FINAL.txt
    Untracked:  data/order_index.rda
    Untracked:  data/samples_id.txt
    Untracked:  data/sexde.data.rds
    Untracked:  data/sexde/
    Untracked:  data/tissuewide_pearson_halfuniform_tissuewide_non_mode.rda
    Untracked:  output/.DS_Store
    Untracked:  output/GTExV6/
    Untracked:  output/GTExV6pipeline/
    Untracked:  output/corshrink_noise_gene_1.rds
    Untracked:  output/sexde.final/
    Untracked:  output/sexde/
    Untracked:  pipeline/.DS_Store

Unstaged changes:
    Modified:   analysis/SexDEPlots.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.


These are the previous versions of the R Markdown and HTML files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view them.

File Version Author Date Message
Rmd 9594264 zouyuxin 2020-01-15 wflow_publish(“analysis/SexDEpipeline.final.Rmd”)
html 9694106 zouyuxin 2020-01-15 Build site.
Rmd 1c6ff33 zouyuxin 2020-01-15 wflow_publish(“analysis/SexDEpipeline.final.Rmd”)

library(mashr)
Loading required package: ashr
library(knitr)
library(kableExtra)
library(ggplot2)
library(gridExtra)
sexde <- readRDS('data/sexde.data.rds')

missing.tissues <- c(7, 24, 25, 31, 40, 43, 49, 51, 52)
gtex.colors <- read.table("https://github.com/stephenslab/gtexresults/blob/master/data/GTExColors.txt?raw=TRUE", sep = '\t', comment.char = '')[-missing.tissues, 2]
gtex.colors <- as.character(gtex.colors)

The results are from mashr_flashr_pipeline. We include the data driven covariance matrices based on the first three principal components and factors from flash.

Flash model based on effects:

factors = readRDS('output/sexde.final/outputEE/sexde.data.EE.flash.model.rds')$factors
par(mfrow = c(2, 3))
for(k in 1:13){
  barplot(factors[,k], col=gtex.colors, names.arg = FALSE, axes = FALSE, main=paste0("Factor ", k))
}

Version Author Date
9694106 zouyuxin 2020-01-15

Version Author Date
9694106 zouyuxin 2020-01-15

Version Author Date
9694106 zouyuxin 2020-01-15

Flash model based on z scores:

factors = readRDS('output/sexde.final/outputEZ/sexde.data.EZ.flash.model.rds')$factors
par(mfrow = c(2, 3))
for(k in 1:17){
  barplot(factors[,k], col=gtex.colors, names.arg = FALSE, axes = FALSE, main=paste0("Factor ", k))
}

Version Author Date
9694106 zouyuxin 2020-01-15

Version Author Date
9694106 zouyuxin 2020-01-15

Version Author Date
9694106 zouyuxin 2020-01-15
# read model
m_mle_EE = readRDS('output/sexde.final/outputEE/sexde.ee.fl_pc3.v_mle.mash_model.rds')
m_mle_EZ = readRDS('output/sexde.final/outputEZ/sexde.ez.fl_pc3.v_mle.mash_model.rds')

Estimated null cor V

V.mle.EE = readRDS('output/sexde.final/outputEE/sexde.data.EE.FL_PC3.V_mle.rds')
corrplot::corrplot(V.mle.EE, method='color', type='upper', tl.col="black", tl.srt=45, tl.cex = 0.5, diag = FALSE, col=colorRampPalette(c("blue", "white", "red"))(200), cl.lim = c(-1,1), title = 'MLE EE', mar=c(0,0,5,0))

Version Author Date
9694106 zouyuxin 2020-01-15
V.mle.EZ = readRDS('output/sexde.final/outputEZ/sexde.data.EZ.FL_PC3.V_mle.rds')
corrplot::corrplot(V.mle.EZ, method='color', type='upper', tl.col="black", tl.srt=45, tl.cex = 0.5, diag = FALSE, col=colorRampPalette(c("blue", "white", "red"))(200), cl.lim = c(-1,1), title = 'MLE EZ', mar=c(0,0,5,0))

Version Author Date
9694106 zouyuxin 2020-01-15

Results

logliks = c(get_loglik(m_mle_EE))
logliks_EZ = c(get_loglik(m_mle_EZ))
tmp = cbind(logliks, logliks_EZ)
row.names(tmp) = c('MLE')
colnames(tmp) = c('EE', 'EZ')
tmp %>% kable() %>% kable_styling()
EE EZ
MLE 1706731 1719887
par(mfrow=c(1,2))
barplot(get_estimated_pi(m_mle_EE), las=2, cex.names = 0.7, main = 'MLE EE')

barplot(get_estimated_pi(m_mle_EZ), las=2, cex.names = 0.7, main = 'MLE EZ')

Version Author Date
9694106 zouyuxin 2020-01-15

Number of significant:

numsig_EE = c(length(get_significant_results(m_mle_EE)))
numsig_EZ = c(length(get_significant_results(m_mle_EZ)))
tmp = cbind(numsig_EE, numsig_EZ)
row.names(tmp) = c('MLE')
colnames(tmp) = c('EE', 'EZ')
tmp %>% kable() %>% kable_styling()
EE EZ
MLE 17391 19556

The pairwise sharing by magnitude

par(mfrow = c(1,2))
clrs=colorRampPalette(rev(c('darkred', 'red','orange','yellow','cadetblue1', 'cyan', 'dodgerblue4', 'blue','darkorchid1','lightgreen','green', 'forestgreen','darkolivegreen')))(200)

x           <- get_pairwise_sharing(m_mle_EE)
colnames(x) <- colnames(get_lfsr(m_mle_EE))
rownames(x) <- colnames(x)
corrplot::corrplot(x, method='color', type='upper', tl.col="black", tl.srt=45, tl.cex = 0.7, diag = FALSE, col=clrs, cl.lim = c(0,1), title = 'MLE EE', mar=c(0,0,5,0))

x           <- get_pairwise_sharing(m_mle_EZ)
colnames(x) <- colnames(get_lfsr(m_mle_EZ))
rownames(x) <- colnames(x)
corrplot::corrplot(x, method='color', type='upper', tl.col="black", tl.srt=45, tl.cex = 0.7, diag = FALSE, col=clrs, cl.lim = c(0,1), title = 'MLE EZ', mar=c(0,0,5,0))

Version Author Date
9694106 zouyuxin 2020-01-15
meta_result = read.table('data/meta.ivw.sexde_logfc_matrix.sexde.svs.allgenes.v8.FINAL.txt', header = TRUE)
meta_gene = as.character(meta_result$gene[meta_result$padj < 0.05])
meta_gene = sapply(strsplit(meta_gene, '_', fixed = TRUE), function(x) x[1])
length(intersect(meta_gene, names(get_significant_results(m_mle_EZ))))
[1] 9707

There are 11212 significant genes from meta analysis, 9707 of them are significant in mash model (EZ) as well.

The gene significant in meta analysis, not in MLE EZ:

ind.name = setdiff(meta_gene, names(get_significant_results(m_mle_EZ)))[1]
ind = which(row.names(sexde$random.b) == ind.name)
stronggene = data.frame(sexde$random.b[ind,])
colnames(stronggene) = 'EffectSize'
stronggene$Group = row.names(stronggene)
stronggene$se = sexde$random.s[ind,]
p1 = ggplot(stronggene, aes(y = EffectSize, x = Group)) + 
  geom_point(show.legend = FALSE, color=gtex.colors) + coord_flip() + ggtitle('Row') + ylim(c(-1.6,1.1)) + geom_errorbar(aes(ymin=EffectSize-1.96*se, ymax=EffectSize+1.96*se), width=0.4, show.legend = FALSE, color=gtex.colors) + 
  theme_bw(base_size=12) + theme(axis.text.y = element_text(colour = gtex.colors, size = 6))

stronggeneMLE = data.frame(m_mle_EZ$result$PosteriorMean[ind,])
colnames(stronggeneMLE) = 'EffectSize'
stronggeneMLE$Group = row.names(stronggeneMLE)
stronggeneMLE$se = m_mle_EZ$result$PosteriorSD[ind,]
p2 = ggplot(stronggeneMLE, aes(y = EffectSize, x = Group)) + 
  geom_point(show.legend = FALSE, color=gtex.colors) + coord_flip() + ggtitle('MLE EZ') + ylim(c(-1.6,1.1)) + 
  geom_errorbar(aes(ymin=EffectSize-1.96*se, ymax=EffectSize+1.96*se), width=0.4, show.legend = FALSE, color=gtex.colors) + 
  theme_bw(base_size=12) + theme(axis.text.y = element_text(colour = gtex.colors, size = 6))

grid.arrange(p1, p2, nrow = 1)

Version Author Date
9694106 zouyuxin 2020-01-15

sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.15.2

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/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] gridExtra_2.3     ggplot2_3.2.0     kableExtra_1.1.0  knitr_1.23       
[5] mashr_0.2.21.0641 ashr_2.2-39      

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3        mvtnorm_1.0-11    lattice_0.20-38  
 [4] assertthat_0.2.1  zeallot_0.1.0     rprojroot_1.3-2  
 [7] digest_0.6.23     foreach_1.4.7     truncnorm_1.0-8  
[10] R6_2.4.1          plyr_1.8.5        backports_1.1.5  
[13] evaluate_0.13     httr_1.4.0        highr_0.8        
[16] pillar_1.4.2      rlang_0.4.2       lazyeval_0.2.2   
[19] pscl_1.5.2        rstudioapi_0.10   whisker_0.3-2    
[22] Matrix_1.2-15     rmarkdown_1.13    labeling_0.3     
[25] webshot_0.5.1     readr_1.3.1       stringr_1.4.0    
[28] munsell_0.5.0     mixsqp_0.3-10     compiler_3.5.3   
[31] httpuv_1.5.1      xfun_0.7          pkgconfig_2.0.3  
[34] SQUAREM_2017.10-1 htmltools_0.3.6   tidyselect_0.2.5 
[37] tibble_2.1.3      workflowr_1.5.0   codetools_0.2-16 
[40] viridisLite_0.3.0 crayon_1.3.4      dplyr_0.8.1      
[43] withr_2.1.2       later_0.8.0       MASS_7.3-51.1    
[46] grid_3.5.3        gtable_0.3.0      git2r_0.26.1     
[49] magrittr_1.5      scales_1.0.0      stringi_1.4.3    
[52] fs_1.3.1          promises_1.0.1    doParallel_1.0.15
[55] xml2_1.2.0        vctrs_0.2.0       rmeta_3.0        
[58] iterators_1.0.12  tools_3.5.3       glue_1.3.1       
[61] purrr_0.3.2       hms_0.5.2         abind_1.4-5      
[64] parallel_3.5.3    yaml_2.2.0        colorspace_1.4-1 
[67] rvest_0.3.4       corrplot_0.84