R/GalaxyConnector.R

Defines functions gx_put gx_get gx_save gx_restore

Documented in gx_get gx_put gx_save

#' gx_put
#'
#' This function uploads a dataset to the current Galaxy history
#'
#' @param filename, path to file
#' @param file_type, auto-detect otherwise specify string filetype

gx_put <- function(filename, file_type="auto"){
    command <- paste("/usr/local/bin/put", "-p", filename, "-t", file_type)
    system(command)
}

#' gx_get
#'
#' Download a dataset from the current Galaxy history by ID or by name #
#'
#' @param files, Dataset ID number or Dataset name for current history
#' @param identifier_type, hid or name

gx_get <- function(files, identifier_type="hid"){
    files_id = paste(files, collapse=" ")
    command <- paste("/usr/local/bin/get", "-i", files_id, "-t", identifier_type)
    system(command)
    paths = paste0("/import/", files)
    return(paths) 
}


#' gx_save
#'
#' Save the notebook .RData and .RHistory to Galaxy. Convenience function which wraps save.image and gx_put
#'
#' @param session_name, default "workspace"

gx_save <- function(session_name="workspace"){
    workspace <- paste("/tmp/",session_name,".RData",sep="")
    hist <- paste("/tmp/",session_name,".RHistory",sep="")
    save.image(workspace)
    savehistory(hist)
    gx_put(workspace)
    gx_put(hist)
}


#' gx_restore
#'
#' Restore the notebook from a .RData and .RHistory object from the current Galaxy history.
#' @param .RData ID number
#' @param .RHistory ID number

gx_restore <- function(rdata_id,rhistory_id){
    rdata <- gx_get(rdata_id)
    rhistory <- gx_get(rhistory_id)
    load(rdata,envir=.GlobalEnv)
    loadhistory(rhistory)
}
erasche/rGalaxyConnector documentation built on May 17, 2019, 7:04 p.m.