R/util.R
4978bdfa
 #' @importFrom BiocParallel SnowParam MulticoreParam
5552e7d6
 #'
 getBPPARAM <- function(threads) {
aa875ce8
     bp <- NULL
4978bdfa
     if ( getOS() == 'Windows' ) {
aa875ce8
         bp <- SnowParam(workers=threads, type='SOCK')
4978bdfa
     } else {
aa875ce8
         bp <- MulticoreParam(workers=threads)
4978bdfa
     }
     return(bp)
5552e7d6
 }
 
 getOS <- function() {
aa875ce8
     os <- toupper(.Platform$OS.type)
     sysinf <- Sys.info()
5552e7d6
     if ( !is.null(sysinf) ) {
aa875ce8
         os <- sysinf['sysname']
5552e7d6
         if ( os == 'Darwin' ) {
aa875ce8
             os <- "OSX"
5552e7d6
         } else if ( os == 'Linux' ) {
aa875ce8
             os <- "LINUX"
5552e7d6
         } else {
aa875ce8
             os <- "WINDOWS"
5552e7d6
         }
     } else {
         if ( grepl("^darwin", R.version$os, perl=TRUE) ) {
aa875ce8
             os <- "OSX"
5552e7d6
         } else if ( grepl("linux-gnu", R.version$os, perl=TRUE) ) {
aa875ce8
             os <- "LINUX"
5552e7d6
         } else {
aa875ce8
             os <- "WINDOWS"
5552e7d6
         }
     }
 
     return(os)
 }
 
 getNodeEdge <- function(fpth) {
aa875ce8
     . <- entity <- type <- from <- to <- title <- NULL
5552e7d6
 
937bb002
     wordslist <- readLines(fpth) |> strsplit("\t")
5552e7d6
 
aa875ce8
     nodedt <- lapply(wordslist, function(words) {
937bb002
         if (length(words) == 2) as.list(words)
     }) |> rbindlist() |> setnames( c('type', 'entity') ) |>
     _[, .(entity, type)]
5552e7d6
 
aa875ce8
     edgedt <- lapply(wordslist, function(words) {
937bb002
         if (length(words) == 3) as.list(words)
     }) |> rbindlist() |> setnames( c('from', 'to', 'title') ) |>
     _[, .(from, to, title)]
5552e7d6
 
937bb002
     list(nodedt=nodedt, edgedt=edgedt)
5552e7d6
 }