Skip to content

Instantly share code, notes, and snippets.

@mojaveazure
Last active July 7, 2017 19:35
Show Gist options
  • Save mojaveazure/15e4ac726e73dc340884854607b70a42 to your computer and use it in GitHub Desktop.
Save mojaveazure/15e4ac726e73dc340884854607b70a42 to your computer and use it in GitHub Desktop.
Install Seurat easily and effectively
#!/usr/bin/env Rscript
args <- commandArgs(trailingOnly = TRUE)
msg <- "Please pass 'bitbucket' or 'github' to choose where we install Seurat from"
if (length(x = args) != 1) {
stop(msg)
}
library.path <- '~/R/packages'
seurat.bitbucket <- 'nygcresearch/seurat'
# seurat.bitbucket <- '[email protected]:nygcresearch/seurat.git'
seurat.github <- 'satijalab/seurat'
# A list of packages from CRAN
cran.packages <- c(
'devtools',
'getPass',
'enrichR'
)
# A list of packages from BioConductor
bioc.packages <- c(
'AnnotationDbi',
'impute',
'GO.db',
'preprocessCore',
'made4'
)
# Functions to install dependencies
# BioConductor dependencies
BioCInstall <- function(package.list) {
ifelse(
test = 'biocLite' %in% rownames(x = installed.packages()),
yes = print('Found biocLite'),
no = source(file = "http://bioconductor.org/biocLite.R")
)
# library(BiocInstaller)
for (package in package.list) {
ifelse(
test = package %in% rownames(x = installed.packages()),
yes = print(paste('Found', package)),
no = BiocInstaller::biocLite(package)
)
}
}
# Cran dependencies
InstallCRANPackage <- function(package) {
tryCatch(
expr = ifelse(
test = package %in% rownames(x = utils::installed.packages()),
yes = print(paste('Found', package)),
no = install.packages(package)
),
error = function(e) {cat()}
)
}
# Set library path
.libPaths(new = library.path)
# Set CRAN mirror
options(repos = c(CRAN = "https://cran.rstudio.com"))
# Install BioConductor packages
BioCInstall(package.list = bioc.packages)
# Install CRAN packages
for (package in cran.packages) {
if (nchar(x = package) >= 1) {
InstallCRANPackage(package = package)
}
}
# Install Seurat
seurat.source <- tolower(x = args[1])
if (seurat.source == 'github') {
devtools::install_github(repo = seurat.github)
} else if (seurat.source == 'bitbucket') {
cat("Be sure to use an account with admin access\n")
cat("Seurat branch (eg 'master'): ")
branch <- readLines(con = 'stdin', n = 1)
# cat(branch, '\n')
cat("Bitbucket username: ")
user <- readLines(con = 'stdin', n = 1)
# cat(user, '\n')
passwd <- getPass::getPass(msg = 'Bitbucket password: ')
devtools::install_bitbucket(
repo = seurat.bitbucket,
ref = branch,
auth_user = user,
password = passwd
)
} else {
stop(msg)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment