R3.5 Seurat Env

echo 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/' > \
  /etc/apt/sources.list.d/r35.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9

apt-get -qq update
DEBIAN_FRONTEND=noninteractive \
  apt-get install --no-install-recommends \
  build-essential \
  'r-base=3.5.3-1bionic' 'r-recommended=3.5.3-1bionic'
DEBIAN_FRONTEND=noninteractive \
  apt-get install --no-install-recommends --allow-downgrades \
  gfortran cmake automake libtool libltdl-dev pkg-config \
  libssh2-1 libcurl4-openssl-dev libssl-dev libxml2-dev libcairo2-dev \
  'r-base-core=3.5.3-1bionic' 'r-base-dev=3.5.3-1bionic'
apt-get clean
rm -r /var/lib/apt/lists/* # Clear package list so it isn't stale

echo 'local({
  r <- getOption("repos")
  r["CRAN"] <- "https://cloud.r-project.org"
  options(repos = r, download.file.method = "libcurl")
})' > /etc/R/Rprofile.site

R -e 'install.packages(c("base64enc", "jsonlite"), Ncpus=4)'
CONDA_VER="4.5.4"
curl -sSL -o ~/anaconda.sh \
    https://repo.continuum.io/miniconda/Miniconda3-${CONDA_VER}-Linux-x86_64.sh
/bin/bash ~/anaconda.sh -b -p /opt/conda
rm ~/anaconda.sh

echo "/opt/conda/lib" >> /etc/ld.so.conf.d/conda.conf
conda config --set always_yes True
printf "[global]\ndisable-pip-version-check = True\n" > /etc/pip.conf
echo 'pip >=18.1' > /opt/conda/conda-meta/pinned # prevent pip downgrade

# upgrade Python within minor version
PYTHON_MINOR=`python --version 2>&1 | sed 's/Python //;s/.[0-9] ::.*//;'`
echo "python =$PYTHON_MINOR" >> /opt/conda/conda-meta/pinned

conda update python
conda clean -tipsy
ldconfig
conda install jupyter
R -e 'install.packages(c("feather", "devtools", "tidyverse", "plotly", "svglite", "future", "shiny", "repr", "IRdisplay", "evaluate", "crayon", "pbdZMQ", "uuid", "digest", "R.matlab"), Ncpus=4)'

R -e 'devtools::install_github(c("hadley/ggplot2", "IRkernel/IRkernel"), Ncpus=4)'

R -e 'install.packages("Matrix", Ncpus=4)'

R -e 'devtools::install_github(repo = "satijalab/seurat", ref = "develop", Ncpus=4)'
local({
  if (file.exists("/usr/share/fonts/truetype/Fira_Sans") || 
      file.exists("/usr/share/fonts/truetype/dejavu")) {
    fonts <- "Fira Sans,PT Sans,Open Sans,DejaVu Sans,sans-serif"
  } else {
    fonts <- "sans"
  }
  options(nextjournal.svg.device.default.fonts = fonts)
})

setHook(packageEvent("ggplot2", "onLoad"), 
  function(pkgname,pkgpath) {
    if (file.exists("/usr/share/fonts/truetype/Fira_Sans") || 
        file.exists("/usr/share/fonts/truetype/dejavu")) {
      fonts <- "Fira Sans,PT Sans,Open Sans,DejaVu Sans,sans-serif"
    } else {
      fonts <- "sans"
    }
    options(nextjournal.ggplot.device.default.fonts = fonts)

    ggplot2::theme_update(text = ggplot2::element_text(family = fonts))
  })

setHook(packageEvent("svglite", "onLoad"), 
  function(pkgname,pkgpath) {
    # Function to build a font alias with all four standard faces, 
    # needed because font filenames are not standardized.
    faces <- function(fam,base,r,i,b,bi) {
      list(plain = list(alias = fam, file = paste0(base,r)),
          italic = list(alias = fam, file = paste0(base,i)),
            bold = list(alias = fam, file = paste0(base,b)),
      bolditalic = list(alias = fam, file = paste0(base,bi)))
    }
    if (file.exists("/usr/share/fonts/truetype/Fira_Sans") && 
        file.exists("/usr/share/fonts/truetype/PT_Serif")) {
      fonts <- list(
        sans = faces("Fira Sans,PT Sans,Open Sans,DejaVu Sans,sans-serif",
                     "/usr/share/fonts/truetype/Fira_Sans/FiraSans-",
                     "Regular.ttf","Italic.ttf",
                     "Bold.ttf","BoldItalic.ttf"),
       serif = faces("PT Serif,Noto Serif,DejaVu Serif,serif",
                     "/usr/share/fonts/truetype/PT_Serif/PT_Serif-Web-",
                     "Regular.ttf","Italic.ttf",
                     "Bold.ttf","BoldItalic.ttf"))
    } else { # Fallback for older environments which only had DejaVu fonts
      fonts <- list(
        sans = faces("DejaVu Sans,Fira Sans,PT Sans,Open Sans,sans-serif",
                     "/usr/share/fonts/truetype/dejavu/DejaVuSans",
                     ".ttf","-Oblique.ttf",
                     "-Bold.ttf","-BoldOblique.ttf"),
       serif = faces("DejaVu Serif,PT Serif,Noto Serif,serif",
                    "/usr/share/fonts/truetype/dejavu/DejaVuSerif",
                    ".ttf","-Italic.ttf",
                     "-Bold.ttf","-BoldItalic.ttf"))
    }
    options(nextjournal.svglite.device.default.fonts = fonts)
  })
.Rprofile
R