Last updated: 2019-08-21

Checks: 6 1

Knit directory: Comparative_eQTL/analysis/

This reproducible R Markdown analysis was created with workflowr (version 1.4.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:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    analysis/.DS_Store
    Ignored:    analysis/20190521_eQTL_CrossSpeciesEnrichment_cache/
    Ignored:    analysis_temp/.DS_Store
    Ignored:    code/.DS_Store
    Ignored:    code/snakemake_workflow/.DS_Store
    Ignored:    data/.DS_Store
    Ignored:    data/PastAnalysesDataToKeep/.DS_Store
    Ignored:    docs/.DS_Store
    Ignored:    docs/assets/.DS_Store

Untracked files:
    Untracked:  analysis/20190821_eGeneTissueCount.Rmd
    Untracked:  docs/figure/20190716_VarianceInsteadOfEgenes.Rmd/
    Untracked:  docs/figure/20190821_eGeneTissueCount.Rmd/

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


library(tidyverse)
library(knitr)

Are eGenes that are shared between humans and chimps more likely to be eGenes in many tissues?

From a table of eGene qvalues across all GTEx tissues (GTEx v7 release), first get distribution of how many tissues each gene has a qval under some threshold

GTEx <- read.table("../data/AllGTExTissues.egenes.txt", header=T, sep='\t')

Threshold=0.1
TissueEgeneCount <- data.frame(TissueCount=rowSums(GTEx[,-1]<=Threshold, na.rm=T), Gene.stable.ID=gsub("\\.\\d+", "", GTEx$gene_id, perl=T))


hist(TissueEgeneCount$TissueCount, breaks=50)

From my data, plot this distribution (as a cumulative dist) after stratifying into human-specific eGenes, versus shared eGenes.

eQTLs <- read.table(gzfile("../data/PastAnalysesDataToKeep/20190521_eQTLs_250kB_10MAF.txt.gz"), header=T)
kable(head(eQTLs))
snps gene beta statistic pvalue FDR qvalue
ID.1.126459696.ACCCTAGTAAG.A ENSPTRG00000001061 3.570039 12.50828 0 3.5e-06 3.5e-06
ID.1.126465687.TTGT.A ENSPTRG00000001061 3.570039 12.50828 0 3.5e-06 3.5e-06
ID.1.126465750.TG.CT ENSPTRG00000001061 3.570039 12.50828 0 3.5e-06 3.5e-06
ID.1.126465756.T.C ENSPTRG00000001061 3.570039 12.50828 0 3.5e-06 3.5e-06
ID.1.126465766.C.A ENSPTRG00000001061 3.570039 12.50828 0 3.5e-06 3.5e-06
ID.1.126465774.G.A ENSPTRG00000001061 3.570039 12.50828 0 3.5e-06 3.5e-06
# List of chimp tested genes
ChimpTestedGenes <- rownames(read.table('../output/ExpressionMatrix.un-normalized.txt.gz', header=T, check.names=FALSE, row.names = 1))

ChimpToHumanGeneMap <- read.table("../data/Biomart_export.Hsap.Ptro.orthologs.txt.gz", header=T, sep='\t', stringsAsFactors = F)
kable(head(ChimpToHumanGeneMap))
Gene.stable.ID Transcript.stable.ID Chimpanzee.gene.stable.ID Chimpanzee.gene.name Chimpanzee.protein.or.transcript.stable.ID Chimpanzee.homology.type X.id..target.Chimpanzee.gene.identical.to.query.gene X.id..query.gene.identical.to.target.Chimpanzee.gene dN.with.Chimpanzee dS.with.Chimpanzee Chimpanzee.orthology.confidence..0.low..1.high.
ENSG00000198888 ENST00000361390 ENSPTRG00000042641 MT-ND1 ENSPTRP00000061407 ortholog_one2one 94.6541 94.6541 0.0267 0.5455 1
ENSG00000198763 ENST00000361453 ENSPTRG00000042626 MT-ND2 ENSPTRP00000061406 ortholog_one2one 96.2536 96.2536 0.0185 0.7225 1
ENSG00000210127 ENST00000387392 ENSPTRG00000042642 MT-TA ENSPTRT00000076396 ortholog_one2one 100.0000 100.0000 NA NA NA
ENSG00000198804 ENST00000361624 ENSPTRG00000042657 MT-CO1 ENSPTRP00000061408 ortholog_one2one 98.8304 98.8304 0.0065 0.5486 1
ENSG00000198712 ENST00000361739 ENSPTRG00000042660 MT-CO2 ENSPTRP00000061402 ortholog_one2one 97.7974 97.7974 0.0106 0.5943 1
ENSG00000228253 ENST00000361851 ENSPTRG00000042653 MT-ATP8 ENSPTRP00000061400 ortholog_one2one 94.1176 94.1176 0.0325 0.3331 1
# Of this ortholog list, how many genes are one2one
table(ChimpToHumanGeneMap$Chimpanzee.homology.type)

ortholog_many2many  ortholog_one2many   ortholog_one2one 
              2278              19917             140351 
OneToOneMap <- ChimpToHumanGeneMap %>%
  filter(Chimpanzee.homology.type=="ortholog_one2one") %>%
  distinct(Chimpanzee.gene.stable.ID, .keep_all = TRUE) %>%
  left_join(TissueEgeneCount, by="Gene.stable.ID")

# Read gtex heart egene list
# Only consider those that were tested in both species and are one2one orthologs
GtexHeartEgenes <- read.table("../data/Heart_Left_Ventricle.v7.egenes.txt.gz", header=T, sep='\t', stringsAsFactors = F) %>%
  mutate(gene_id_stable = gsub(".\\d+$","",gene_id)) %>%
  filter(gene_id_stable %in% OneToOneMap$Gene.stable.ID) %>%
  mutate(chimp_id = plyr::mapvalues(gene_id_stable, OneToOneMap$Gene.stable.ID,  OneToOneMap$Chimpanzee.gene.stable.ID, warn_missing = F)) %>%
  filter(chimp_id %in% ChimpTestedGenes)

ChimpToHuman.ID <- function(Chimp.ID){
  #function to convert chimp ensembl to human ensembl gene ids
  return(
    plyr::mapvalues(Chimp.ID, OneToOneMap$Chimpanzee.gene.stable.ID, OneToOneMap$Gene.stable.ID, warn_missing = F)
  )}

HumanFDR <- 0.1
ChimpFDR <- 0.1

#Get chimp eQTLs
Chimp_eQTLs <- eQTLs %>%
  filter(qvalue<ChimpFDR)

# Count chimp eGenes
length(unique(Chimp_eQTLs$gene))
[1] 336
# Count human eGenes
length(GtexHeartEgenes %>% filter(qval< HumanFDR) %>% pull(chimp_id))
[1] 5410
# Count number genes tested in both species (already filtered for 1to1 orthologs)
length(GtexHeartEgenes$gene_id_stable)
[1] 11586
#Change FDR thresholds or take top N eGenes by qvalue
HumanTopN <- 600
HumanFDR <- 0.1
ChimpFDR <- 0.1

# Filter human eGenes by qval threshold
HumanSigGenes <- GtexHeartEgenes %>% filter(qval<HumanFDR) %>% pull(chimp_id)

# Filter human eGenes by topN qval
# HumanSigGenes <- GtexHeartEgenes %>% top_n(-HumanTopN, qval) %>% pull(chimp_id)

# Filter human eGeness by qval threshold then topN betas 
# HumanSigGenes <- GtexHeartEgenes %>% filter(qval<HumanFDR) %>% top_n(1000, abs(slope)) %>% pull(chimp_id)

HumanNonSigGenes <- GtexHeartEgenes %>%
  filter(!chimp_id %in% HumanSigGenes) %>%
  pull(chimp_id)

ChimpSigGenes <- GtexHeartEgenes %>%
  filter(chimp_id %in% Chimp_eQTLs$gene) %>%
  pull(chimp_id)

ChimpNonSigGenes <- GtexHeartEgenes %>%
  filter(! chimp_id %in% Chimp_eQTLs$gene) %>%
  pull(chimp_id)



ContigencyTable <- matrix( c( length(intersect(ChimpSigGenes,HumanSigGenes)),
                              length(intersect(HumanSigGenes,ChimpNonSigGenes)),
                              length(intersect(ChimpSigGenes,HumanNonSigGenes)),
                              length(intersect(ChimpNonSigGenes,HumanNonSigGenes))), 
                           nrow = 2)

rownames(ContigencyTable) <- c("Chimp eGene", "Not Chimp eGene")
colnames(ContigencyTable) <- c("Human eGene", "Not human eGene")

#what is qval threshold for human eGene classification in this contigency table
print(GtexHeartEgenes %>% top_n(-HumanTopN, qval) %>% top_n(1, qval) %>% pull(qval))
[1] 5.83223e-12
#Contigency table of one to one orthologs tested in both chimps and humans of whether significant in humans, or chimps, or both, or neither
ContigencyTable
                Human eGene Not human eGene
Chimp eGene             145             135
Not Chimp eGene        5265            6041
#One-sided Fisher test for greater overlap than expected by chance
fisher.test(ContigencyTable, alternative="greater")

    Fisher's Exact Test for Count Data

data:  ContigencyTable
p-value = 0.04779
alternative hypothesis: true odds ratio is greater than 1
95 percent confidence interval:
 1.002643      Inf
sample estimates:
odds ratio 
  1.232354 
#Chimp eGenes vs non chimp eGenes
ToPlot <- GtexHeartEgenes %>%
  mutate(group = case_when(
        chimp_id %in% ChimpSigGenes ~ "chimp.eGene",
        !chimp_id %in% ChimpSigGenes ~ "not.chimp.eGene")) %>%
left_join(OneToOneMap, by=c("chimp_id"="Chimpanzee.gene.stable.ID"))
Chimp.tissue.plot <- ggplot(ToPlot, aes(color=group,x=TissueCount)) +
  stat_ecdf(geom = "step") +
  ylab("Cumulative frequency") +
  xlab("TissueCount") +
  annotate("text", x = 40, y = 0.4, label = paste("Mann-Whitney\none-sided P =", signif(wilcox.test(data=ToPlot, TissueCount ~ group, alternative="greater")$p.value, 2) )) +
  theme_bw() +
  theme(legend.position = c(.80, .2), legend.title=element_blank())

#Human eGenes vs non human eGenes
ToPlot <- GtexHeartEgenes %>%
  mutate(group = case_when(
        chimp_id %in% HumanSigGenes ~ "human.eGene",
        !chimp_id %in% HumanSigGenes ~ "not.human.eGene")) %>%
left_join(OneToOneMap, by=c("chimp_id"="Chimpanzee.gene.stable.ID"))
Human.tissue.plot <- ggplot(ToPlot, aes(color=group,x=TissueCount)) +
  stat_ecdf(geom = "step") +
  ylab("Cumulative frequency") +
  xlab("TissueCount") +
  annotate("text", x = 40, y = 0.4, label = paste("Mann-Whitney\none-sided P =", signif(wilcox.test(data=ToPlot, TissueCount ~ group, alternative="greater")$p.value, 2) )) +
  theme_bw() +
  theme(legend.position = c(.80, .2), legend.title=element_blank())

#Shared eGenes vs human-specific eGenes
ToPlot <- GtexHeartEgenes %>%
  mutate(group = case_when(
        chimp_id %in% intersect(HumanSigGenes, ChimpSigGenes) ~ "shared.eGene",
        chimp_id %in% setdiff(HumanSigGenes, ChimpSigGenes) ~ "human.specific.eGene")) %>%
  filter(chimp_id %in% union(intersect(HumanSigGenes, ChimpSigGenes), setdiff(HumanSigGenes, ChimpSigGenes)))%>%
left_join(OneToOneMap, by=c("chimp_id"="Chimpanzee.gene.stable.ID"))
Shared.human.tissue.plot <- ggplot(ToPlot, aes(color=group,x=TissueCount)) +
  stat_ecdf(geom = "step") +
  ylab("Cumulative frequency") +
  xlab("TissueCount") +
  annotate("text", x = 40, y = 0.4, label = paste("Mann-Whitney\none-sided P =", signif(wilcox.test(data=ToPlot, TissueCount ~ group, alternative="less")$p.value, 2) )) +
  theme_bw() +
  theme(legend.position = c(.80, .2), legend.title=element_blank())

#Shared eGenes vs chimp-specific eGenes
ToPlot <- GtexHeartEgenes %>%
  left_join(OneToOneMap, by=c("chimp_id"="Chimpanzee.gene.stable.ID")) %>%
mutate(dN.dS = dN.with.Chimpanzee/dS.with.Chimpanzee) %>%
mutate(group = case_when(
        chimp_id %in% intersect(HumanSigGenes, ChimpSigGenes) ~ "shared.eGene",
        chimp_id %in% setdiff(ChimpSigGenes, HumanSigGenes) ~ "chimp.specific.eGene")) %>%
dplyr::filter(chimp_id %in% union(intersect(HumanSigGenes, ChimpSigGenes), setdiff(ChimpSigGenes, HumanSigGenes)))
Shared.chimp.tissue.plot <- ggplot(ToPlot, aes(color=group,x=TissueCount)) +
  stat_ecdf(geom = "step") +
  ylab("Cumulative frequency") +
  xlab("TissueCount") +
  annotate("text", x = 40, y = 0.4, label = paste("Mann-Whitney\none-sided P =", signif(wilcox.test(data=ToPlot, TissueCount ~ group, alternative="less")$p.value, 2) )) +
  theme_bw() +
  theme(legend.position = c(.80, .2), legend.title=element_blank())

Chimp.tissue.plot

Human.tissue.plot

Shared.human.tissue.plot

Shared.chimp.tissue.plot

Make same plots, but using top 600 human eGenes to classify heart eGene for purposes of species sharing.

#Change FDR thresholds or take top N eGenes by qvalue
HumanTopN <- 600
HumanFDR <- 0.1
ChimpFDR <- 0.1

# Filter human eGenes by qval threshold
# HumanSigGenes <- GtexHeartEgenes %>% filter(qval<HumanFDR) %>% pull(chimp_id)

# Filter human eGenes by topN qval
HumanSigGenes <- GtexHeartEgenes %>% top_n(-HumanTopN, qval) %>% pull(chimp_id)

# Filter human eGeness by qval threshold then topN betas 
# HumanSigGenes <- GtexHeartEgenes %>% filter(qval<HumanFDR) %>% top_n(1000, abs(slope)) %>% pull(chimp_id)

HumanNonSigGenes <- GtexHeartEgenes %>%
  filter(!chimp_id %in% HumanSigGenes) %>%
  pull(chimp_id)

ChimpSigGenes <- GtexHeartEgenes %>%
  filter(chimp_id %in% Chimp_eQTLs$gene) %>%
  pull(chimp_id)

ChimpNonSigGenes <- GtexHeartEgenes %>%
  filter(! chimp_id %in% Chimp_eQTLs$gene) %>%
  pull(chimp_id)



ContigencyTable <- matrix( c( length(intersect(ChimpSigGenes,HumanSigGenes)),
                              length(intersect(HumanSigGenes,ChimpNonSigGenes)),
                              length(intersect(ChimpSigGenes,HumanNonSigGenes)),
                              length(intersect(ChimpNonSigGenes,HumanNonSigGenes))), 
                           nrow = 2)

rownames(ContigencyTable) <- c("Chimp eGene", "Not Chimp eGene")
colnames(ContigencyTable) <- c("Human eGene", "Not human eGene")

#what is qval threshold for human eGene classification in this contigency table
print(GtexHeartEgenes %>% top_n(-HumanTopN, qval) %>% top_n(1, qval) %>% pull(qval))
[1] 5.83223e-12
#Contigency table of one to one orthologs tested in both chimps and humans of whether significant in humans, or chimps, or both, or neither
ContigencyTable
                Human eGene Not human eGene
Chimp eGene              28             252
Not Chimp eGene         572           10734
#One-sided Fisher test for greater overlap than expected by chance
fisher.test(ContigencyTable, alternative="greater")

    Fisher's Exact Test for Count Data

data:  ContigencyTable
p-value = 0.0006395
alternative hypothesis: true odds ratio is greater than 1
95 percent confidence interval:
 1.444504      Inf
sample estimates:
odds ratio 
  2.084996 
#Chimp eGenes vs non chimp eGenes
ToPlot <- GtexHeartEgenes %>%
  mutate(group = case_when(
        chimp_id %in% ChimpSigGenes ~ "chimp.eGene",
        !chimp_id %in% ChimpSigGenes ~ "not.chimp.eGene")) %>%
left_join(OneToOneMap, by=c("chimp_id"="Chimpanzee.gene.stable.ID"))
Chimp.tissue.plot <- ggplot(ToPlot, aes(color=group,x=TissueCount)) +
  stat_ecdf(geom = "step") +
  ylab("Cumulative frequency") +
  xlab("TissueCount") +
  annotate("text", x = 40, y = 0.4, label = paste("Mann-Whitney\none-sided P =", signif(wilcox.test(data=ToPlot, TissueCount ~ group, alternative="greater")$p.value, 2) )) +
  theme_bw() +
  theme(legend.position = c(.80, .2), legend.title=element_blank())

#Human eGenes vs non human eGenes
ToPlot <- GtexHeartEgenes %>%
  mutate(group = case_when(
        chimp_id %in% HumanSigGenes ~ "human.eGene",
        !chimp_id %in% HumanSigGenes ~ "not.human.eGene")) %>%
left_join(OneToOneMap, by=c("chimp_id"="Chimpanzee.gene.stable.ID"))
Human.tissue.plot <- ggplot(ToPlot, aes(color=group,x=TissueCount)) +
  stat_ecdf(geom = "step") +
  ylab("Cumulative frequency") +
  xlab("TissueCount") +
  annotate("text", x = 40, y = 0.4, label = paste("Mann-Whitney\none-sided P =", signif(wilcox.test(data=ToPlot, TissueCount ~ group, alternative="greater")$p.value, 2) )) +
  theme_bw() +
  theme(legend.position = c(.80, .2), legend.title=element_blank())

#Shared eGenes vs human-specific eGenes
ToPlot <- GtexHeartEgenes %>%
  mutate(group = case_when(
        chimp_id %in% intersect(HumanSigGenes, ChimpSigGenes) ~ "shared.eGene",
        chimp_id %in% setdiff(HumanSigGenes, ChimpSigGenes) ~ "human.specific.eGene")) %>%
  filter(chimp_id %in% union(intersect(HumanSigGenes, ChimpSigGenes), setdiff(HumanSigGenes, ChimpSigGenes)))%>%
left_join(OneToOneMap, by=c("chimp_id"="Chimpanzee.gene.stable.ID"))
Shared.human.tissue.plot <- ggplot(ToPlot, aes(color=group,x=TissueCount)) +
  stat_ecdf(geom = "step") +
  ylab("Cumulative frequency") +
  xlab("TissueCount") +
  annotate("text", x = 40, y = 0.4, label = paste("Mann-Whitney\none-sided P =", signif(wilcox.test(data=ToPlot, TissueCount ~ group, alternative="less")$p.value, 2) )) +
  theme_bw() +
  theme(legend.position = c(.80, .2), legend.title=element_blank())

#Shared eGenes vs chimp-specific eGenes
ToPlot <- GtexHeartEgenes %>%
  left_join(OneToOneMap, by=c("chimp_id"="Chimpanzee.gene.stable.ID")) %>%
mutate(dN.dS = dN.with.Chimpanzee/dS.with.Chimpanzee) %>%
mutate(group = case_when(
        chimp_id %in% intersect(HumanSigGenes, ChimpSigGenes) ~ "shared.eGene",
        chimp_id %in% setdiff(ChimpSigGenes, HumanSigGenes) ~ "chimp.specific.eGene")) %>%
dplyr::filter(chimp_id %in% union(intersect(HumanSigGenes, ChimpSigGenes), setdiff(ChimpSigGenes, HumanSigGenes)))
Shared.chimp.tissue.plot <- ggplot(ToPlot, aes(color=group,x=TissueCount)) +
  stat_ecdf(geom = "step") +
  ylab("Cumulative frequency") +
  xlab("TissueCount") +
  annotate("text", x = 40, y = 0.4, label = paste("Mann-Whitney\none-sided P =", signif(wilcox.test(data=ToPlot, TissueCount ~ group, alternative="less")$p.value, 2) )) +
  theme_bw() +
  theme(legend.position = c(.80, .2), legend.title=element_blank())

Chimp.tissue.plot

Human.tissue.plot

Shared.human.tissue.plot

Shared.chimp.tissue.plot


sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.14

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] knitr_1.23      forcats_0.4.0   stringr_1.4.0   dplyr_0.8.1    
 [5] purrr_0.3.2     readr_1.3.1     tidyr_0.8.3     tibble_2.1.3   
 [9] ggplot2_3.1.1   tidyverse_1.2.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1       highr_0.8        cellranger_1.1.0 plyr_1.8.4      
 [5] pillar_1.4.1     compiler_3.5.1   git2r_0.25.2     workflowr_1.4.0 
 [9] tools_3.5.1      digest_0.6.19    lubridate_1.7.4  jsonlite_1.6    
[13] evaluate_0.14    nlme_3.1-140     gtable_0.3.0     lattice_0.20-38 
[17] pkgconfig_2.0.2  rlang_0.3.4      cli_1.1.0        rstudioapi_0.10 
[21] yaml_2.2.0       haven_2.1.0      xfun_0.7         withr_2.1.2     
[25] xml2_1.2.0       httr_1.4.0       hms_0.4.2        generics_0.0.2  
[29] fs_1.3.1         rprojroot_1.3-2  grid_3.5.1       tidyselect_0.2.5
[33] glue_1.3.1       R6_2.4.0         readxl_1.3.1     rmarkdown_1.13  
[37] modelr_0.1.4     magrittr_1.5     backports_1.1.4  scales_1.0.0    
[41] htmltools_0.3.6  rvest_0.3.4      assertthat_0.2.1 colorspace_1.4-1
[45] labeling_0.3     stringi_1.4.3    lazyeval_0.2.2   munsell_0.5.0   
[49] broom_0.5.2      crayon_1.3.4