R/snptestDS.R

Defines functions snptestDS

Documented in snptestDS

#' @title Interface to run SNPtest commands on a ssh connection (with SNPtest 2.5.2 installed)
#'
#' @param client \code{ssh} SSH resource
#' @param ... \code{character vector} Arguments to pass to the snptest software
#'
#' @return List containing: \cr
#' - Results: Table of results (typical SNPtest output file) \cr
#' - Output: Console output of the ssh query
#' @export
#'

snptestDS <- function(client, ...){
  
  dots <- list(...)
  arguments <- unlist(dots)
  
  # Add temp folder and set it for output
  tempDir <- client$tempDir()
  arguments <- c(arguments, "-o", paste0(tempDir, "/ex.out"))
  
  # snptest execution command
  snptest.command <- "snptest"
  
  # Run snptest
  snptest <- client$exec(snptest.command, arguments)
  
  # Get output file
  client$downloadFile(paste0(tempDir, '/ex.out'))  
  
  # Checkoutputs
  outs <- client$exec('ls', tempDir)$output
  
  if (length(outs)==0){ # No outputs means errors
    ans <- snptest$error
  }
  else {
    if (length(outs)==1) {
      # results <- readr::read_table(outs, skip = 3)
      results <- readr::read_delim(outs, delim = " ", comment = "#")
    }
    else {
      results <- c("There are more than 1 table as output")
    }
    ans <- list(results=results, snptest.out = snptest)
  }
  
  client$removeTempDir()
  client$close()
  
  return(ans)
}
  
isglobal-brge/dsOmics documentation built on March 22, 2023, 4:01 a.m.