项目作者: xinghuq

项目描述 :
DeepGenomeScan: A Deep Learning Approach for Whole Genome Scan (WGS) and Genome-wide Association Studies (GWAS)
高级语言: R
项目地址: git://github.com/xinghuq/DeepGenomeScan.git
创建时间: 2020-08-12T11:36:04Z
项目社区:https://github.com/xinghuq/DeepGenomeScan

开源协议:Other

下载


R build status
Build Status
Build status
License:C

DeepGenomeScan : A Deep Learning Approach for Whole Genome Scan (WGS) and Genome-wide Association Studies (GWAS)

This package implements the genome scan and genome-wide association studies using deep neural networks (i.e, Multi-Layer Perceptron (MLP), Convolutional Neural Network (CNN)). DeepGenomeScan offers heuristic computational framework integrating different neural network architectures (i.e.,Multi-Layer Perceptron (MLP), convolutional neural network(CNN)) and robust resampling methods, as well as the Model-Agnostic interpretation of feature importance for convolutional neural networks. DeepGenomeScan, in other words, deep learning for genome-wide scanning, is a deep learning approach for detecting signatures of natural selection and for performing various omics-based genome-wide association studies, such as GWAS, PWAS, TWAS, MWAS. The design makes the implemention user-friendly. It is compatible with most self-defined machine learning models (the self-defined models shuold be complete, including tunable parameters, fitted model, predicted model, examples can be found in our tutorial). Users can adopt the package’s framework to study various ecological and evolutionary questions.

Install packages

  1. library("devtools")
  2. devtools::install_github("xinghuq/DeepGenomeScan")
  3. devtools::install_github("xinghuq/CaretPlus/pkg/caret")
  4. `

Dependencies and environment requirements

Note: Environment requirements: python should be installed and the python package of Keras and Tensorflow should also be installed and work properly with the system

Checking the python environment

  1. library("rappdirs")
  2. library("reticulate")
  3. reticulate::use_python("/usr/bin/python3")
  4. library(caret) ### for ML calling functions and performance estimation, users should use the modified version at xinghuq/CaretPlus/caret instead of the original version
  5. library(keras)
  6. library("tensorflow")
  7. checking if Tensorflow works properly
  8. K0=keras::backend()
  1. requireNamespace("KLFDAPC")
  2. if (!requireNamespace("KLFDAPC", quietly=TRUE))
  3. devtools::install_github("xinghuq/KLFDAPC")
  4. if (!requireNamespace("DA", quietly=TRUE))
  5. devtools::install_github("xinghuq/DA")
  6. if (!requireNamespace("keras", quietly=TRUE))
  7. install.packages("keras")
  8. if (!requireNamespace("tensorflow", quietly=TRUE))
  9. install.packages("tensorflow")
  10. if (!requireNamespace("kerasR", quietly=TRUE))
  11. install.packages("kerasR")

library

```{r library,message = FALSE}
library(DeepGenomeScan)
library(caret)### for ML calling functions and performance estimation
library(keras) ### for DL
library(“tensorflow”)
library(“caretEnsemble”)
library(kerasR)
library(“h2o”)
library(NeuralNetTools)

  1. ### Example
  2. ### Preparing data
  3. ``````{r}
  4. f <- system.file('extdata',package='DeepGenomeScan')
  5. infile <- file.path(f, "sim1.csv")
  6. sim_example=read.csv(infile)
  7. genotype=sim_example[,-c(1:14)]
  8. env=sim_example[,2:11]
  9. normalize <- function(x) {
  10. return ((x - min(x)) / (max(x) - min(x)))
  11. }
  12. genotype_norm=as.data.frame(apply(genotype,2,normalize))
  13. ```

Setting the resampling method

  1. econtrol1 <- trainControl(## 5-fold CV, repeat 5 times
  2. method = "adaptive_cv",
  3. number = 5,
  4. ## repeated ten times
  5. repeats = 5,search = "random")
  6. set.seed(999)
  7. options(warn=-1)

DeepGenomeScan with “mlph2o” model

  1. h2o_mlp<- DeepGenomeScan(as.matrix(genotype_norm),env$envir1,
  2. method="mlph2o",
  3. metric = "RMSE",## "Accuracy", "RMSE","Rsquared","MAE"
  4. tuneLength = 10, ### 11 tunable parameters 11^2
  5. # tuneGrid=CNNGrid, ### or search 100 combinations of parameters using random tuneLength=100
  6. trControl = econtrol1)
  7. #### There is a model specific varIMP for this model
  8. varImp(h2o_mlp,scale = FALSE)
  9. out <- as.data.frame(h2o::h2o.varimp(h2o_mlp$finalModel), stringsAsFactors = TRUE)
  10. colnames(out)[colnames(out) == "scaled_importance"] <- "Overall"
  11. rownames(out) <- out$names
  12. ```
Calculating the p-values for SNPs and plot the SNP Manhattan plot
  1. DLqvaluesarsine<-function(DL_data,K)
  2. {
  3. loadings<-DL_data# [,1:as.numeric(K)]
  4. normdat <- apply(loadings, 2, normalize)
  5. asindat=apply(normdat,2, function(x) {asin(sqrt(x))})
  6. resmaha <- covRob(asindat, distance = TRUE, na.action= na.omit, estim="donostah")$dist
  7. lambda <- median(resmaha)/qchisq(0.5,df=K)
  8. reschi2test <- pchisq(resmaha/lambda,K,lower.tail=FALSE)
  9. qval <- qvalue(reschi2test)
  10. q.values_DL<-qval$qvalues
  11. padj <- p.adjust(reschi2test,method="bonferroni")
  12. return(data.frame(p.values=reschi2test, q.values=q.values_DL,padj=padj,mahaD=resmaha))
  13. }
  14. DLsim1=apply(out,2,normalize) #18
  15. Simqvaluear=DLqvaluesarsine(DLsim1,1)

Manhattan plot

  1. ggplot() +
  2. geom_point(aes(x=which(Loci=="Neutral"), y=-log10(Simqvaluear[-which(Loci!="Neutral"),1])), col = "gray83") +
  3. geom_point(aes(x=which(Loci!="Neutral"), y=-log10(Simqvaluear[-which(Loci=="Neutral"),1]), colour = Selected_Loci)) +
  4. xlab("SNPs") + ylab("DNN -log10(p-value)") +ylim(c(0,100))+theme_bw()
  5. plot(out$Overall, ylab="SNP importance")

Package tutorial

More about how to construct your own model using DeepGenomeScan can be found in the tutorial

Welcome any feedback and pull request.

Version

The current version is 0.5.5 (Sep 2, 2020).

Contact

qinxinghu@gmail.com

Citation

Qin X, Chiang CWK, Gaggiotti OE. 2022. Deciphering signatures of natural selection via deep learning. Briefings in Bioinformatics. bbac354, https://doi.org/10.1093/bib/bbac354.