Skip to content

Commit

Permalink
Merge 29a5aec into 70b793a
Browse files Browse the repository at this point in the history
  • Loading branch information
stolarczyk committed May 27, 2020
2 parents 70b793a + 29a5aec commit 440b59d
Show file tree
Hide file tree
Showing 131 changed files with 2,193 additions and 378 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Expand Up @@ -4,10 +4,15 @@ cache: packages
warnings_are_errors: false
r_packages: devtools
r_github_packages:
- pepkit/pepr
#- pepkit/pepr
- databio/simpleCache
- r-lib/covr
bioc_packages:
- GenomicRanges
- BiocStyle
- BiocFileCache
before_install:
- Rscript -e 'install.packages("devtools");devtools::install_github(repo = "pepkit/pepr",ref = "dev")'
after_success:
- Rscript -e 'covr::coveralls()'

24 changes: 11 additions & 13 deletions DESCRIPTION
@@ -1,23 +1,21 @@
Package: BiocProject
Title: Bioconductor Management with Portable Encapsulated Project (PEP) Objects
Version: 0.2
Authors@R: c(person("Michal", "Stolarczyk", email = "mjs5kd@virginia.edu",role = c("aut", "cre")),
Version: 0.2.1
Authors@R: c(person("Michal", "Stolarczyk", email = "michal@virginia.edu",role = c("aut", "cre")),
person("Nathan", "Sheffield", email = "nathan@code.databio.org",role = c("aut")))
Description: A Bioconductor-oriented project management class. It wraps the
generic pepr R package for project metadata. BiocProject allows you to read
in project metadata and data for an entire project with a single line of R code.
License: GPL-3
License: BSD_2_clause + file LICENSE
Encoding: UTF-8
LazyData: true
Depends: S4Vectors, pepr, methods
Suggests:
knitr,
rmarkdown,
testthat,
yaml
Depends: pepr, S4Vectors
Imports: methods, glue, RCurl, yaml, stats, pryr
Suggests: knitr, rmarkdown, testthat, BiocStyle
Enhances: BiocFileCache, simpleCache, GenomicRanges
biocViews: DataImport, DataRepresentation
RoxygenNote: 6.1.1
URL: https://github.com/pepkit/BiocProject
BugReports: https://github.com/pepkit/BiocProject
License: BSD_2_clause + file LICENSE
biocViews: Infrastructure, DataImport, DataRepresentation
RoxygenNote: 7.1.0
URL: http://code.databio.org/BiocProject/
BugReports: https://github.com/pepkit/BiocProject/issues
VignetteBuilder: knitr
2 changes: 2 additions & 0 deletions LICENSE
@@ -0,0 +1,2 @@
YEAR: 2018
COPYRIGHT HOLDER: Nathan Sheffield
18 changes: 16 additions & 2 deletions NAMESPACE
@@ -1,13 +1,27 @@
# Generated by roxygen2: do not edit by hand

export(.insertPEP)
export(.pyToR)
export(.setShowMethod)
export(.updateList)
export(.unionList)
export(BiocProject)
export(gatherPipelineInterfaces)
export(getOutputsBySample)
export(getProjectOutputs)
export(pipelineInterfacesBySample)
export(readSchema)
exportMethods(config)
exportMethods(getProject)
exportMethods(is)
exportMethods(samples)
exportMethods(sampleTable)
import(S4Vectors)
import(methods)
import(pepr)
importFrom(RCurl,getURLContent)
importFrom(glue,glue)
importFrom(methods,new)
importFrom(pepr,checkSection)
importFrom(pepr,config)
importFrom(pryr,partial)
importFrom(stats,setNames)
importFrom(yaml,yaml.load_file)
12 changes: 11 additions & 1 deletion NEWS.md
@@ -1,3 +1,13 @@
# BiocProject 0.2.1 - 2020-05-26

## Added

* pipeline interface support, including functions: `getPipelineInterfaces`, `outputsByPipeline`, `outputsByProtocol`, `getPipelines`,`getProtocolMappings` and `samplesByProtocol`

## Changed

* the `bioconductor` section can be provided in either in the pipeline interface or in the project config. The project config location is given the priority

# BiocProject 0.2 - 2019-04-19

## Added
Expand Down Expand Up @@ -71,4 +81,4 @@

* make `BiocProject` class inherit from `pepr::Project` and `base::list`
* the `initialize` method can read in the data with the provided `func`
* the object constructor does not fail if the `pepr::Project` object is provided in the `funcArgs` arguments list
* the object constructor does not fail if the `pepr::Project` object is provided in the `funcArgs` arguments list
12 changes: 11 additions & 1 deletion R/constants.R
Expand Up @@ -8,7 +8,17 @@
# FUNCTION_ARGS:
# <arg1>: <val1>
# <arg2>: <val2>
MAIN_SECTION = "bioconductor"
BIOC_SECTION = "bioconductor"
FUNCTION_ARGS = "funcArgs"
FUNCTION_PATH = "readFunPath"
FUNCTION_NAME = "readFunName"

# other constants
PIP_TYPE_KEY = "pipeline_type"
PIP_NAME_KEY = "pipeline_name"
OUTPUT_SCHEMA_SECTION = "output_schema"
LOOPER_SECTION = "looper"
PIP_IFACE_NAME = "pipeline_interfaces"
PIP_IFACE_KEY = "pipeline_interfaces_key"
SCHEMA_SAMPLE_OUTS = c("properties", "samples", "items", "properties")
PIP_IFACE_SECTION = c(LOOPER_SECTION, PIP_IFACE_NAME)
90 changes: 24 additions & 66 deletions R/functions.R
Expand Up @@ -41,6 +41,7 @@
#' If the \code{autoLoad} is set to \code{FALSE} the data will not be loaded
#' and empty \code{\link[pepr]{Project-class}} object will be returned.
#'
#' @note The \code{bioconductor} section can be read from the project config file or pipeline interface. The former is given the priority
#'
#' @section Further reading:
#' Browse the
Expand All @@ -49,7 +50,7 @@
#'
#'
#' @param file a character vector with a path to the PEP config file
#' @param subproject a character vector with a name of the subproject
#' @param amendments a character vector with a name of the subproject
#' to be activated
#' @param func a anonymous function that reads and/or processess the data,
#' it must take
Expand All @@ -63,6 +64,8 @@
#' the \code{bioconductor} section in the config file.
#' @param autoLoad a logical indicating whether the data should be loaded
#' automatically. See \code{Details} for more information.
#' @param projectLevel logical indicating whether a only project-level pifaces
#' should be considered. Otherwise, only sample-level ones are.
#'
#' @return an object of \code{\link[S4Vectors]{Annotated-class}} that is
#' returned by the user provided function with
Expand All @@ -81,27 +84,31 @@
#' @seealso \url{https://pepkit.github.io/}
#' @import pepr
#' @export BiocProject
BiocProject = function(file, subproject = NULL, autoLoad = TRUE, func = NULL,
funcArgs = NULL) {
p = pepr::Project(file=file, subproject=subproject)
BiocProject = function(file, amendments = NULL, autoLoad = TRUE, func = NULL,
funcArgs = NULL, projectLevel = FALSE) {
p = pepr::Project(file=file, amendments = amendments)
# prevent PEP (Project object) input. This prevents BiocProject object
# failing when the user provides the Project object
if(is.null(funcArgs)){
funcArgs = list()
}else{
if (length(.findProjectInList(funcArgs)) > 0)
if (length(.findProjectInList(funcArgs)) > 0) {
warning("Project object was found in the arguments list. It will be removed.")
funcArgs = funcArgs[-.findProjectInList(funcArgs)]
}
}
args = append(list(p), funcArgs)
if(pepr::checkSection(pepr::config(p), c(MAIN_SECTION, FUNCTION_ARGS))){
args = .updateList(config(p)[[MAIN_SECTION]][[FUNCTION_ARGS]],args)
cfg = .getBiocConfig(p, projectLevel)
if(is.null(cfg))
cfg = pepr::config(p)
if(pepr::.checkSection(cfg, c(BIOC_SECTION, FUNCTION_ARGS))){
args = .unionList(config(p)[[BIOC_SECTION]][[FUNCTION_ARGS]],args)
argsNames = names(args)
project = args[[.findProjectInList(args)]]
argsNames = append("",argsNames[-.findProjectInList(args)])
args = append(list(p), args[[-.findProjectInList(args)]])
names(args) = argsNames
}

if (!is.null(func)) {
# use the anonymous function if provided
if (is.function(func)) {
Expand All @@ -116,14 +123,14 @@ BiocProject = function(file, subproject = NULL, autoLoad = TRUE, func = NULL,
if(!is.logical(autoLoad)) stop("'autoLoad' argument has to be a logical,
got '", class(autoLoad),"'")
if (autoLoad) {
# check if the config consists of MAIN_SECTION section
if(!pepr::checkSection(pepr::config(p), MAIN_SECTION)){
# check if the config consists of BIOC_SECTION section
if(!pepr::.checkSection(cfg, BIOC_SECTION)){
message("No data was read. Returning a Project object")
warning("The config YAML is missing the '",
MAIN_SECTION,"' section.")
BIOC_SECTION,"' section.")
return(p)
}
funcName = pepr::config(p)[[MAIN_SECTION]][[FUNCTION_NAME]]
funcName = cfg[[BIOC_SECTION]][[FUNCTION_NAME]]
# check if the function name was provided
# and if it exists in the environment
if (!is.null(funcName) && exists(funcName)) {
Expand All @@ -132,7 +139,8 @@ BiocProject = function(file, subproject = NULL, autoLoad = TRUE, func = NULL,
message("Used function '", funcName, "' from the environment")
return(.insertPEP(readData, p))
}else{
if (!is.null(funcName) && length(grep("(\\:){2,3}", funcName)) != 0) {
if (!is.null(funcName) &&
length(grep("(\\:){2,3}", funcName)) != 0) {
# trying to access the function from the namespace that
# was specified in the config.yaml FUNCTION_NAME
splitted = strsplit(funcName, ":")[[1]]
Expand All @@ -147,10 +155,10 @@ BiocProject = function(file, subproject = NULL, autoLoad = TRUE, func = NULL,
# trying to source the file specified
# in the config.yaml FUNCTION_PATH
funcPath = pepr::.expandPath(
pepr::config(p)[[MAIN_SECTION]][[FUNCTION_PATH]])
cfg[[BIOC_SECTION]][[FUNCTION_PATH]])
if (!is.null(funcPath)){
if (!file.exists(funcPath))
funcPath = .makeAbsPath(funcPath,dirname(p@file))
funcPath = .makeAbsPath(funcPath, dirname(p@file))
if (!file.exists(funcPath))
stop(
"The function does not exist in the environment and file '",
Expand Down Expand Up @@ -193,54 +201,4 @@ BiocProject = function(file, subproject = NULL, autoLoad = TRUE, func = NULL,
return(p)
}
}
}

#' Insert a PEP metadata in a metadata slot of Annotated
#'
#' This function inserts the PEP (\code{\link[pepr]{Project-class}})
#' into the metadata slot of objects that
#' extend the \code{\link[S4Vectors]{Annotated-class}}
#'
#' Additionally, if the object extends the
#' \code{\link[S4Vectors]{Annotated-class}} (or is a list that will be
#' automatically converted to a \code{\link[S4Vectors]{List}}) the show method
#' for its class is redefined to display the \code{\link[pepr]{Project-class}}
#' as the metadata.
#'
#' @param object an object of \code{\link[S4Vectors]{Annotated-class}}
#' @param pep an object of class \code{\link[pepr]{Project-class}}
#'
#' @return an object of the same class as the object argument but enriched
#' with the metadata from the pep argument
#'
#' @examples
#' # If the object is of class Annotated
#' object = S4Vectors::List(result="test")
#' result = .insertPEP(object, pepr::Project())
#' metadata(result)
#'
#' # If the object is not of class Annotated
#' object1 = "test"
#' result1 = .insertPEP(object1, pepr::Project())
#' metadata(result1)
#' @import S4Vectors methods
#' @export
.insertPEP = function(object, pep) {
if(!methods::is(pep, "Project"))
stop("the pep argument has to be of class 'Project',
got '", class(pep),"'")
# do we throw a warning/message saying what happens in the next line?
if(methods::is(object, "list"))
object = S4Vectors::List(object)
if(methods::is(object, "Annotated")){
S4Vectors::metadata(object) = list(PEP=pep)
} else{
warning("BiocProject expects data loading functions to return an 'Annotated' object, but your function returned a '",
class(object),"' object. To use an Annotated, this returned object has been placed in the first slot of a List")
result = S4Vectors::List(result=object)
S4Vectors::metadata(result) = list(PEP=pep)
object = result
}
.setShowMethod(object)
object
}
}
6 changes: 3 additions & 3 deletions R/methods_Annotated.R
Expand Up @@ -54,14 +54,14 @@ setMethod("getProject","Annotated",function(.Object){
#' projectConfig = system.file("extdata", "example_peps-master",
#' "example_BiocProject", "project_config.yaml", package="BiocProject")
#' p=BiocProject(projectConfig)
#' samples(p)
#' sampleTable(p)
#' @import pepr
#' @export
setMethod(
f = "samples",
f = "sampleTable",
signature = "Annotated",
definition = function(object) {
pepr::samples(getProject(object))
pepr::sampleTable(getProject(object))
})


Expand Down

0 comments on commit 440b59d

Please sign in to comment.