-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from stephenslab/revamp-dscquery-2
Revise dscquery to address Issue #182, implemented new function dscread
- Loading branch information
Showing
14 changed files
with
387 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Package: dscrutils | ||
Encoding: UTF-8 | ||
Type: Package | ||
Version: 0.3.8 | ||
Date: 2019-04-16 | ||
Version: 0.3.8.7 | ||
Date: 2019-05-15 | ||
Title: Dynamic Statistical Comparisons R Interface | ||
Authors@R: c(person("Gao","Wang",role=c("aut","cre"), | ||
email="[email protected]"), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#' @title Read DSC Module Outputs | ||
#' | ||
#' @description Reads in DSC module outputs generated from a single | ||
#' run of a module instance. | ||
#' | ||
#' @details DSC module outputs are either stored in RDS files (see | ||
#' \code{\link{readRDS}}) or a Python "pickle" file. For DSC module | ||
#' outputs stored as Python pickle files, the reticulate package is | ||
#' used to import the data into R. | ||
#' | ||
#' @param outdir Directory where the DSC output is stored. | ||
#' | ||
#' @param outfile File specifying the file path relative to the DSC | ||
#' directory. You can use \code{\link{dscquery}} with the | ||
#' \code{module.output.file} to obtain a correct file path. Note that | ||
#' the file path should not contain the file extension (".rds" or | ||
#' ".pkl"). | ||
#' | ||
#' @return The return file is a list containing the DSC module | ||
#' outputs. This list always includes a "DSC_DEBUG" list element | ||
#' containing additional information recorded by DSC, such as the | ||
#' replicate id. | ||
#' | ||
#' @seealso \code{\link{dscquery}} | ||
#' | ||
#' @examples | ||
#' | ||
#' dsc.dir <- system.file("datafiles","one_sample_location", | ||
#' "dsc_result",package = "dscrutils") | ||
#' dat <- dscquery(dsc.dir,targets = "simulate", | ||
#' module.output.file = "simulate") | ||
#' out <- dscread(dsc.dir,dat$simulate.output.file[1]) | ||
#' | ||
#' @importFrom tools file_ext | ||
#' @importFrom yaml yaml.load_file | ||
#' | ||
#' @export | ||
#' | ||
dscread <- function (outdir, outfile) { | ||
|
||
# Check the input arguments. | ||
if (!(is.character(outdir) & length(outdir) == 1)) | ||
stop("Argument \"outdir\" should be a character vector of length 1") | ||
if (!(is.character(outfile) & length(outfile) == 1)) | ||
stop("Argument \"outfile\" should be a character vector of length 1") | ||
|
||
# Look for files with extensions "rds" and "pkl". | ||
outfile <- path.expand(file.path(outdir,outfile)) | ||
rds <- paste0(outfile,".rds") | ||
pkl <- paste0(outfile,".pkl") | ||
if (file.exists(rds) & file.exists(pkl)) | ||
stop(sprintf(paste("Both %s and %s DSC output files exist; files should", | ||
"be cleaned up by running \"dsc --clean\""),rds,pkl)) | ||
else if (file.exists(rds)) | ||
|
||
# Read from the .rds file. | ||
out <- tryCatch(readRDS(rds), | ||
error = function (e) { | ||
warning(sprintf("Unable to read from %s; file may be corrupted",rds)) | ||
return(NULL) | ||
}) | ||
else if (file.exists(pkl)) { | ||
|
||
# Read from the .pkl file. | ||
if (!requireNamespace("reticulate",quietly = TRUE)) | ||
stop("Cannot read from .pkl file due to missing reticulate package") | ||
out <- tryCatch(reticulate::py_load_object(pkl), | ||
error = function (e) { | ||
warning(sprintf("Unable to read from %s; file may be corrupted",pkl)) | ||
return(NULL) | ||
}) | ||
|
||
# This additional processing step is needed to convert more | ||
# complex Python data structures such as a pandas data frames. | ||
out <- rapply(out,reticulate::py_to_r,classes = "python.builtin.object", | ||
how = "replace") | ||
} else { | ||
warning(sprintf(paste("Unable to read from DSC output file %s as one or", | ||
"more files may be missing; returning NULL"), | ||
outfile)) | ||
out <- NULL | ||
} | ||
|
||
# We may use this code in the future to read from YAML files: | ||
# | ||
# yaml.load_file(outfile) | ||
# | ||
return(out) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.