Skip to content

Commit

Permalink
Merge a22985a into 70b793a
Browse files Browse the repository at this point in the history
  • Loading branch information
stolarczyk committed Apr 17, 2020
2 parents 70b793a + a22985a commit a69d597
Show file tree
Hide file tree
Showing 142 changed files with 14,865 additions and 398 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()'

14 changes: 7 additions & 7 deletions DESCRIPTION
@@ -1,23 +1,23 @@
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
Depends: S4Vectors, pepr, methods, glue, RCurl
Suggests:
knitr,
rmarkdown,
testthat,
yaml
Enhances: BiocFileCache, simpleCache, GenomicRanges
biocViews: DataImport, DataRepresentation
RoxygenNote: 6.1.1
URL: https://github.com/pepkit/BiocProject
BugReports: https://github.com/pepkit/BiocProject
RoxygenNote: 7.0.2
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
15 changes: 13 additions & 2 deletions NAMESPACE
@@ -1,13 +1,24 @@
# 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)
10 changes: 10 additions & 0 deletions NEWS.md
@@ -1,3 +1,13 @@
# BiocProject 0.2.1 - unreleased

## 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
14 changes: 13 additions & 1 deletion R/constants.R
Expand Up @@ -8,7 +8,19 @@
# FUNCTION_ARGS:
# <arg1>: <val1>
# <arg2>: <val2>
MAIN_SECTION = "bioconductor"
BIOC_SECTION = "bioconductor"
FUNCTION_ARGS = "funcArgs"
FUNCTION_PATH = "readFunPath"
FUNCTION_NAME = "readFunName"

# other constants
S_PIP_SECTION = "sample_pipeline"
P_PIP_SECTION = "project_pipeline"
PROTO_MAP_SECTION = "protocol_mapping"
COLL_MAP_SECTION = "collator_mappings"
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)
94 changes: 27 additions & 67 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,14 +64,18 @@
#' 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 pipelineName a string indicating the name of the pipeline in the
#' pipeline interface. It is used for the \code{bioconductor} section
#' selection. If none provided and there's no \code{bioconductor} section in
#' the config file, the first pipeline in the pipeline interface will be used.
#'
#' @return an object of \code{\link[S4Vectors]{Annotated-class}} that is
#' returned by the user provided function with
#' the \code{\link[pepr]{Project-class}} object inserted into the first
#' element of the list in its medatada slot
#'
#' @examples
#' projectConfig = system.file("extdata", "example_peps-master",
#' projectConfig = system.file("extdata", "example_peps-cfg2",
#' "example_BiocProject", "project_config.yaml", package="BiocProject")
#' bp=BiocProject(projectConfig)
#'
Expand All @@ -81,27 +86,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 +125,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 +141,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 +157,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 +203,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
}
}
12 changes: 6 additions & 6 deletions R/methods_Annotated.R
Expand Up @@ -22,7 +22,7 @@ setMethod(".is.project","Annotated",function(.Object){
#' @return an object of \code{\link[pepr]{Project-class}}
#'
#' @examples
#' projectConfig = system.file("extdata", "example_peps-master",
#' projectConfig = system.file("extdata", "example_peps-cfg2",
#' "example_BiocProject", "project_config.yaml", package="BiocProject")
#' p=BiocProject(projectConfig)
#' getProject(p)
Expand Down Expand Up @@ -51,17 +51,17 @@ setMethod("getProject","Annotated",function(.Object){
#'
#' @return a data.table with the with metadata about samples
#' @examples
#' projectConfig = system.file("extdata", "example_peps-master",
#' projectConfig = system.file("extdata", "example_peps-cfg2",
#' "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 All @@ -76,7 +76,7 @@ setMethod(
#' @return a list with the config file
#'
#' @examples
#' projectConfig = system.file("extdata", "example_peps-master",
#' projectConfig = system.file("extdata", "example_peps-cfg2",
#' "example_BiocProject", "project_config.yaml", package="BiocProject")
#' p=BiocProject(projectConfig)
#' config(p)
Expand Down

0 comments on commit a69d597

Please sign in to comment.