-
Notifications
You must be signed in to change notification settings - Fork 12
/
JAMSinstaller_BW
executable file
·201 lines (170 loc) · 7.43 KB
/
JAMSinstaller_BW
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env Rscript
if ((.Platform$OS.type) != "unix"){
cat("JAMS was written for UNIX systems. It looks like you may be on Windows. Will try installing JAMSbeta. For JAMSalpha, use a Unix system.")
OnUnix <- FALSE
} else {
OnUnix <- TRUE
}
print_help <- function(){
cat("JAMSinstaller - a script for installing the JAMS package safely on your system.\n")
cat("Please read instructions on this page before attempting to install:\nhttps://github.com/johnmcculloch/JAMS_BW/wiki/Installing_JAMS_on_Biowulf\n")
cat("\n")
cat("Usage: JAMSinstaller --install [options]\n")
cat("\n")
cat("Options:\n")
#cat("--onlybeta #Installs only JAMSbeta. Useful to install on a computer where only JAMSbeta will be run.\n")
cat("--linkto #Creates symbolic links to the JAMS excecutables to this path. Default: ~/bin\n")
cat("\n")
#cat("If only --install is passed, both JAMSalpha and JAMSbeta will be installed,\nand symlinks to the excecutables will be created in the user\'s ~/bin folder,\nwhich is assumed to be in $PATH\n")
#cat("\n")
q()
}
# get path of running script
getScriptPath <- function() {
cmdArgs <- commandArgs(trailingOnly = FALSE)
needle <- "--file="
match <- grep(needle, cmdArgs)
if (length(match) > 0) {
return(dirname(normalizePath(sub(needle, "", cmdArgs[match]))))
} else {
return(dirname(normalizePath(sys.frames()[[1]]$ofile)))
}
}
#Allow for some very simple options with base package fucntions, as we still do not know what the user has installed.
args <- commandArgs(trailingOnly = TRUE)
if (length(args) > 0){
if(!all((as.character(args) %in% c("--install", "--onlybeta", "--linkto", "--force")))){
print_help()
}
} else {
print_help()
}
#Decide what to install and where
#if (("--onlybeta") %in% (as.character(args))){
# installalpha <- FALSE
# binexecs <- c("JAMSbeta", "JAMS16", "JAMSjoinlanes", "JAMSmakeswarm", "JAMSbankit", "JAMSfastqprefixrenamer")
#} else {
installalpha <- TRUE
binexecs <- c("JAMSalpha", "JAMSbeta", "JAMS16", "JAMSbuildk2db", "JAMSjoinlanes", "JAMSmakeswarm", "JAMSbankit", "JAMSfastqprefixrenamer")
#}
homefolder <- as.character(Sys.getenv("HOME"))
if ("--linnkto" %in% (as.character(args))){
linkto <- args[(which(args) == "--linkto") + 1]
} else {
linkto <- file.path(homefolder, "bin")
}
if (!file.exists(linkto)){
stop(paste("The specified folder for creating executable symbolic links does not exist:", linkto))
}
if ("--force" %in% (as.character(args))){
force_install <- TRUE
} else {
force_install <- FALSE
}
jamsdir <- getScriptPath()
#Make sure we are writing to the right place
rlibs <- as.character(Sys.getenv("R_LIBS"))
if(nchar(rlibs) == 0){
rlibs <- .libPaths()[1]
}
#Decide which kind of system you are on.
currslurmjobid <- as.character(Sys.getenv("SLURM_JOB_ID"))
if (nchar(currslurmjobid) > 3){
onbiowulf <- TRUE
#Define appropriate functions for slurm system
detectBatchCPUs <- function() {
slurmjobid <- as.character(Sys.getenv("SLURM_JOB_ID"))
sacctraw <- system2("sacct", args = c("-j", slurmjobid, "-X", "-P"), stdout = TRUE)
jobinforaw <- sacctraw[2]
jobinfoheaders <- sacctraw[1]
#jobinfo <- unlist(strsplit(jobinforaw, split=" "))[which(unlist(strsplit(jobinforaw, split=" ")) != "")]
jobinfo <- unlist(strsplit(jobinforaw, split="\\|"))
#names(jobinfo) <- unlist(strsplit(jobinfoheaders, split=" "))[which(unlist(strsplit(jobinfoheaders, split=" ")) != "")]
names(jobinfo) <- unlist(strsplit(jobinfoheaders, split="\\|"))
ncores <- as.integer(jobinfo["AllocCPUS"])
print(jobinfo)
if (is.na(ncores)) {
#Try plan B
ncores <- as.numeric(Sys.getenv("SLURM_CPUS_PER_TASK"))
if (is.na(ncores)) {
stop("Could not determine how many CPUs you have. Aborting.")
}
}
return(ncores)
}
detectAvailRAM <- function(){
mempercpu <- as.integer(Sys.getenv("SLURM_MEM_PER_CPU"))
mempernode <- as.integer(Sys.getenv("SLURM_MEM_PER_NODE"))
cpuspertask <- as.integer(Sys.getenv("SLURM_CPUS_PER_TASK"))
if(!(is.na(mempernode))){
totmem <- mempernode
} else {
totmem <- mempercpu * cpuspertask
}
totmembytes<-totmem * 1000000
return(totmembytes)
}
} else {
onbiowulf <- FALSE
detectBatchCPUs <- function() {
ncores <- detectCores()
if (is.na(ncores)) {
stop("Could not determine how many CPUs you have. Aborting.")
}
return(ncores)
}
detectAvailRAM <- function(){
totmembytes<-as.numeric(get_ram())
return(totmembytes)
}
#if (installalpha == TRUE){
# stop("You are not on a node on Biowulf. This version of JAMSalpha will only work on HPC Biowulf. Refer to documentation. Aborting now. If you want to install only JAMSbeta, use the --onlybeta option.")
#}
if (nchar(rlibs) < 5){
rlibs <- .libPaths()[1]
}
}
cat(paste("JAMS R libraries will be installed to", rlibs, "\n"))
#if (onbiowulf == TRUE){
# system("export TMP=/data/$USER")
#} else {
# system("export TMP=~/")
#}
#Install devtools and stringr if not present
repos <- "https://cloud.r-project.org"
if(!(all((c("devtools", "stringr", "parallel", "benchmarkme", "BiocManager", "prettyunits") %in% rownames(installed.packages()))))){
install.packages(c("devtools", "stringr", "parallel", "benchmarkme", "BiocManager", "prettyunits"), repos = repos, update = TRUE, lib = rlibs)
}
#Make sure we have the correct version of Bioconductor
BiocManager::install(version = "3.19", ask = FALSE)
require("devtools")
require("stringr")
require("parallel")
require("benchmarkme")
require("BiocManager")
threads <- detectBatchCPUs()
cat(paste("You have", threads, "cpus available\n"))
bytesRAM <- detectAvailRAM()
cat(paste0("You have ~", round(bytesRAM/1E9, 1), " Gbytes of RAM available\n"))
#Install all packages via Bioconductor
alldeps <- c("R.utils", "Rcpp", "RcppEigen", "parallel", "optparse", "tcltk", "futile.logger", "benchmarkme", "RCurl", "Rtsne", "uwot", "circlize", "Polychrome", "openxlsx", "grid", "gridExtra", "tidyverse", "ggplot2", "ggrepel", "wordcloud", "gplots", "vegan", "matrixStats", "Biostrings", "seqinr", "dada2","DECIPHER","survival", "survminer", "SummarizedExperiment", "ComplexHeatmap", "HybridMTest", "ggpubr", "combinat", "data.table", "genefilter", "gg3D", "gtools", "gtable", "fastSave", "Matrix")
bioconductordeps <- c("dada2", "DECIPHER","SummarizedExperiment", "HybridMTest", "Biostrings", "genefilter", "ComplexHeatmap")
non_bioconductordeps <- alldeps[!(alldeps %in% bioconductordeps)]
BiocManager::install(pkgs = alldeps, update = TRUE, ask = FALSE, site_repository = repos, force = force_install)
#devtools::install_github("jokergoo/ComplexHeatmap")
devtools::install_github('barkasn/fastSave')
#Install the rest of JAMS
devtools::install(jamsdir, upgrade = FALSE, repos = repos)
#Make symlinks for JAMS executables
jamsbinpath <- file.path(jamsdir, "libexec")
jamsBWbinpath <- file.path(jamsdir, "BWlibexec")
for (binexec in binexecs){
sourcepath <- file.path(jamsbinpath, binexec)
targetpath <- file.path(linkto, binexec)
if (file.exists(targetpath)){
cat(paste(targetpath, "already exists\n"))
} else {
cat(paste("Linking executable with", "ln", "-s", sourcepath, targetpath, "\n"))
system(paste("ln", "-s", sourcepath, targetpath))
}
}