Last updated: 2020-02-27

Checks: 5 2

Knit directory: Blancetal-1/analysis/

This reproducible R Markdown analysis was created with workflowr (version 1.6.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 file has unstaged changes. 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(20200217) 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.

Using absolute paths to the files within your workflowr project makes it difficult for you and others to run your code on a different machine. Change the absolute path(s) below to the suggested relative path(s) to make your code more reproducible.

absolute relative
~/Documents/Blancetal-1//analysis/ .

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:


Unstaged changes:
    Modified:   analysis/Drought-genes.Rmd
    Modified:   analysis/Identifying_quaint.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 c018f1d Em 2020-02-26 added drought info
Rmd 227a4b6 Em 2020-02-26 added figure
html 227a4b6 Em 2020-02-26 added figure
Rmd a597c91 Em 2020-02-26 stuff
html a597c91 Em 2020-02-26 stuff

Intro

I’m rerunning the code to identify selected genes with the Quaint package

### function for testing all genes
testAllGenes <- function(myTissue){
# Read in mean-centered expression values
df1 <- read.table(paste("../data/Mean_centered_expression/",myTissue,".txt",sep=""))
# Read in tissue specific kinship matrix 
myF <- read.table(paste('../data/Kinship_matrices/F_',myTissue,'.txt',sep=""))

## Get Eigen Values and Vectors 
myE <- eigen(myF)
E_vectors <- myE$vectors
E_values <- myE$values

## Testing for selection on first 5 PCs
myM = 1:5

## Using the last 1/2 of PCs to estimate Va
myL = 6:dim(myF)[1]

## test for selection on each gene
allGeneOutput <- sapply(1:ncol(df1), function(x){
myQpc = calcQpc(myZ = df1[,x], myU = E_vectors, myLambdas = E_values, myL = myL, myM = myM)
return(myQpc)
})

return(allGeneOutput)
}

###run on all genes
alltissues = c('GRoot',"Kern","LMAD26","LMAN26", "L3Tip","GShoot","L3Base","LMAD8","LMAN8")
alltissueresults = lapply(alltissues, testAllGenes)
names(alltissueresults) <- alltissues



##look at sig results
sigresults = lapply(1:length(alltissues), function(i){
# extract the pvalues
pvals = matrix(unlist(alltissueresults[[i]][4,]), ncol=5, byrow=TRUE) #each row corresponds to a gene, columns are to PCs

##look at pvalue distributions
par(mfrow=c(3,2), mar=c(4,4,1,1))
sapply(1:5, function(x){
hist(pvals[,x], border="white", col = "darkgray", main="", breaks = 20, xlab = paste('PC ',x,' ',alltissues[i],sep=""))
})

## test fpr sogmofocamce
pfdr = data.frame(apply(pvals,2, function(x){p.adjust(x, method='fdr')}))

## how many are significant?
numsig <- apply(pfdr, 2, function(x){sum(x<0.1)})
numsig
})

###make a big image of how many sig results we have
sigTable = as.data.frame(matrix(unlist(sigresults), ncol=5, byrow=T))
names(sigTable) = c('PC1','PC2','PC3','PC4','PC5')
sigTable$tissue = alltissues
sigLong = tidyr::gather(sigTable, 'variable','value', -tissue)
sigLong[sigLong == 0] <- NA

pl <- ggplot(data=sigLong,aes(x=variable,y=tissue)) + 
  geom_tile(aes(fill=value),color='black') + scale_fill_gradient(low = 'lightyellow', high = "#CC79A7", guide = FALSE, na.value = "white") + theme_bw() + xlab("\n") + ylab("Tissue") + 
  theme(axis.ticks=element_blank(),panel.border=element_blank(),panel.grid.major = element_blank(), axis.text.y = element_text(size=10,angle=0), axis.title.y = element_text(size=16),axis.title.x  = element_text(size=16),axis.text.x = element_text(angle = 0, hjust = 0.5,size=14)) + geom_text(aes(label=value),colour="grey15",size=3.5)

pl
Warning: Removed 29 rows containing missing values (geom_text).

I think the main difference is the PCs that I’m using to estimate Va are different from Jennifer’s (she uses 11:20). Let’s check.

### function for testing all genes
testAllGenes1120 <- function(myTissue){
# Read in mean-centered expression values
df1 <- read.table(paste("../data/Mean_centered_expression/",myTissue,".txt",sep=""))
# Read in tissue specific kinship matrix 
myF <- read.table(paste('../data/Kinship_matrices/F_',myTissue,'.txt',sep=""))

## Get Eigen Values and Vectors 
myE <- eigen(myF)
E_vectors <- myE$vectors
E_values <- myE$values

## Testing for selection on first 5 PCs
myM = 1:5

## Using the last 1/2 of PCs to estimate Va
myL = 11:20

## test for selection on each gene
allGeneOutput <- sapply(1:ncol(df1), function(x){
myQpc = calcQpc(myZ = df1[,x], myU = E_vectors, myLambdas = E_values, myL = myL, myM = myM)
return(myQpc)
})

return(allGeneOutput)
}



alltissueresults1120 = lapply(alltissues, testAllGenes1120)
names(alltissueresults1120) <- alltissues



##look at sig results
sigresults1120 = lapply(1:length(alltissues), function(i){
# extract the pvalues
pvals = matrix(unlist(alltissueresults1120[[i]][4,]), ncol=5, byrow=TRUE) #each row corresponds to a gene, columns are to PCs

##look at pvalue distributions
par(mfrow=c(3,2), mar=c(4,4,1,1))
sapply(1:5, function(x){
hist(pvals[,x], border="white", col = "darkgray", main="", breaks = 20, xlab = paste('PC ',x,' ',alltissues[i],sep=""))
})

## test fpr sogmofocamce
pfdr = data.frame(apply(pvals,2, function(x){p.adjust(x, method='fdr')}))

## how many are significant?
numsig <- apply(pfdr, 2, function(x){sum(x<0.1)})
numsig
})

###make a big image of how many sig results we have
sigTable1120 = as.data.frame(matrix(unlist(sigresults1120), ncol=5, byrow=T))
names(sigTable1120) = c('PC1','PC2','PC3','PC4','PC5')
sigTable1120$tissue = alltissues
sigLong1120 = tidyr::gather(sigTable1120, 'variable','value', -tissue)


pl <- ggplot(data=sigLong1120,aes(x=variable,y=tissue)) + 
  geom_tile(aes(fill=value),color='black') + scale_fill_gradient(low = 'lightyellow', high = "#CC79A7", guide = FALSE, na.value = "white") + theme_bw() + xlab("\n") + ylab("Tissue") + 
  theme(axis.ticks=element_blank(),panel.border=element_blank(),panel.grid.major = element_blank(), axis.text.y = element_text(size=10,angle=0), axis.title.y = element_text(size=16),axis.title.x  = element_text(size=16),axis.text.x = element_text(angle = 0, hjust = 0.5,size=14)) + geom_text(aes(label=value),colour="grey15",size=3.5)

pl


sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

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] tidyr_1.0.2       quaint_0.0.0.9000 ggpubr_0.2.5      magrittr_1.5     
[5] reshape2_1.4.3    ggplot2_3.2.1    

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3       plyr_1.8.5       compiler_3.6.2   pillar_1.4.3    
 [5] later_1.0.0      git2r_0.26.1     highr_0.8        workflowr_1.6.0 
 [9] tools_3.6.2      digest_0.6.25    evaluate_0.14    lifecycle_0.1.0 
[13] tibble_2.1.3     gtable_0.3.0     pkgconfig_2.0.3  rlang_0.4.4     
[17] yaml_2.2.1       xfun_0.12        withr_2.1.2      stringr_1.4.0   
[21] dplyr_0.8.4      knitr_1.28       vctrs_0.2.3      fs_1.3.1        
[25] rprojroot_1.3-2  grid_3.6.2       tidyselect_1.0.0 glue_1.3.1      
[29] R6_2.4.1         rmarkdown_2.1    farver_2.0.3     purrr_0.3.3     
[33] whisker_0.4      ellipsis_0.3.0   backports_1.1.5  scales_1.1.0    
[37] promises_1.1.0   htmltools_0.4.0  assertthat_0.2.1 colorspace_1.4-1
[41] ggsignif_0.6.0   httpuv_1.5.2     stringi_1.4.6    lazyeval_0.2.2  
[45] munsell_0.5.0    crayon_1.3.4