Skip to content

Instantly share code, notes, and snippets.

@omsai
Last active September 8, 2017 20:17
Show Gist options
  • Save omsai/983d24898b6bba6b99f4d335c0edd748 to your computer and use it in GitHub Desktop.
Save omsai/983d24898b6bba6b99f4d335c0edd748 to your computer and use it in GitHub Desktop.
Install and run R package mappable on SLURM HPC cluster
#!/bin/bash
#SBATCH --nodes 1
#SBATCH --partition phi #general #general_requeue
#SBATCH --ntasks 1 #4 #24
#-SBATCH --cpus-per-task 64
#SBATCH --output mappable.out
#SBATCH --job-name kmap
genomes='genomes <- c(
"BSgenome.Dmelanogaster.UCSC.dm6",
"BSgenome.Hsapiens.UCSC.hg19",
"BSgenome.Hsapiens.UCSC.hg38",
"BSgenome.Hsapiens.NCBI.GRCh38"
)'
main() {
local bootstrap
bootstrap=
[[ -n ${SLURM_JOB_ID} ]] && echo ${SLURM_JOB_ID} >> mappable.out
module purge
if [[ -n "$bootstrap" ]]; then
install_and_r_and_pkgs
fi
module load git
update_kmap
run_kmap
}
install_and_r_and_pkgs() {
conda install -y -c r r-essentials r-xml r-devtools
Rscript -e 'source("https://bioconductor.org/biocLite.R")'
}
# Globals: genomes
update_kmap() {
R -q --vanilla <<EOF
$genomes
install_genome <- function(genome) {
if (! requireNamespace(genome, quietly = TRUE)) {
BiocInstaller::biocLite(genome)
}
}
invisible(lapply(genomes, install_genome))
devtools::install_github("coregenomics/kmap",
repos = BiocInstaller::biocinstallRepos())
EOF
}
run_kmap() {
R -q --vanilla <<EOF
$genomes
dump_and_quit <- function() {
# Save debugging info to file last.dump.rda
dump.frames(to.file = TRUE)
# Quit R with error status
q(status = 1)
}
options(error = dump_and_quit)
library(kmap)
invisible(lapply(genomes, mappable))
message("Completed all genomes!")
EOF
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment