# Install R version >3.4.1 and RStudioversion > 1.0.153

.libPaths()
.libPaths("C:/Program Files/R/R-3.4.3/library") # or R-3.5.0 if necessary

setup_microbiome_analysis <- function(){
  
  .packages = c("ape", 
                "gridExtra", 
                "picante", 
                "data.table", 
                "RColorBrewer", 
                "DT", 
                "reshape", 
                "reshape2", 
                "magrittr", 
                "markdown",
                "ggpubr", 
                "tibble", 
                "pheatmap", 
                "dplyr", 
                "viridis", 
                "devtools", 
                "rmdformats",
                "intergraph",
                "network",
                "igraph",
                "ggplot2", 
                "gridExtra", 
                "knitr", 
                "vegan", 
                "plyr", 
                "dplyr",
                "ggrepel", 
                "ggnetwork", 
                "ade4", 
                "rmarkdown",
                "formatR",
                "caTools",
                "ashr",       # added this one
                "stringi",    # added
                "hexbin",     # added
                "lme4",       # added: generalized and mixed models
                "sciplot",    # added: bargraph.CI
                "compositions", # added
                "propr",      # added: correlations for sparse data (expected(rho))
                "emmeans",    # added (multiple comparisons GLS)
                "multcomp",   # added (glht and cld functions)
                "multcompView", # added (needed for emmeans::CLD function)
			"GGally")
  
  .bioc_packages <- c("phyloseq",
                      "microbiome", 
                      "DESeq2",       # added this one
                      "apeglm",       # added
                      "vsn",          # added
                      "decontam",     # added
                      "ALDEx2",       # added: diff abundance testing for CoDa (Gloor)
                      "phangorn", 
                      "genefilter")
  
  # Install CRAN packages (if not already installed)
  .inst <- .packages %in% installed.packages()
  if(length(.packages[!.inst]) > 0) install.packages(.packages[!.inst])

  .inst <- .bioc_packages %in% installed.packages()
  if(any(!.inst)) {
    source("http://bioconductor.org/biocLite.R")
    biocLite(.bioc_packages[!.inst], ask = F)
  }
  
  
  if (!("microbiomeutilities"  %in% installed.packages())) {
    devtools::install_github("microsud/microbiomeutilities")
  }
  
  if (!("SpiecEasi"  %in% installed.packages())) {
    devtools::install_github("zdk123/SpiecEasi")
  }
  
  if (!("ggnet"  %in% installed.packages())) {
    devtools::install_github("briatte/ggnet")
  }
  
  if (!("seqtime"  %in% installed.packages())) {               # added this one
    devtools::install_github("hallucigenia-sparsa/seqtime")
  }
  
  if (!("CoDaSeq" %in% installed.packages())) {                # added: compositional data analysis (Gregg Gloor)
    devtools::install_github("ggloor/CoDaSeq/CoDaSeq")
  }
  
  message("If there was no error then you are ready to do microbiome data analysis")
  
}

setup_microbiome_analysis()
