Skip to content

Commit

Permalink
Merge pull request #27 from pepkit/dev
Browse files Browse the repository at this point in the history
Release 0.2
  • Loading branch information
stolarczyk authored Apr 17, 2019
2 parents f84cb30 + c42e0dd commit da20560
Show file tree
Hide file tree
Showing 83 changed files with 3,254 additions and 481 deletions.
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: pepr
Type: Package
Title: Reading Portable Encapsulated Projects
Version: 0.1
Version: 0.2
Date: 2017-08-09
Authors@R: c(person("Nathan", "Sheffield", email = "[email protected]",
role = c("aut", "cre")),person("Michal","Stolarczyk",email="[email protected]",role=c("ctb")))
Expand Down
29 changes: 10 additions & 19 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# pepr 0.1
# pepr 0.2 - 2019-04-17

## 2019-02-01
## Changed

* keys in the config file: `sample_annotation` to `sample_table`, `sample_subannotation` to `subsample_table`. Backwards compatibility is preserved.

# pepr 0.1 - 2019-02-01

## Added

Expand All @@ -16,11 +20,7 @@
* fixed the problem with paths expansions in sample subannotaitons case


# pepr 0.0.4

## 2018-11-14

## Added
# pepr 0.0.4 - 2018-11-14

## Changed

Expand All @@ -30,25 +30,16 @@
* fix `expandPath()` function, add error when environment variable not found


# pepr 0.0.3

## 2018-09-12
# pepr 0.0.3 - 2018-09-12

## Added

* add `derived_columns` functionality
* add `implied_columns` functionality
* add `subannotation` functionality

## Changed

# pepr 0.0.2

## 2018-09-06
# pepr 0.0.2 - 2018-09-06

## Added

* first release, includes basic [PEP](https://pepkit.github.io/) reading functions

## Changed

* first release, includes basic [PEP](https://pepkit.github.io/) reading functions
9 changes: 3 additions & 6 deletions R/loadConfig.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# This used to be all metadata columns; now it's just: results_subdir
mdn = names(cfg$metadata)

cfg$metadata = .makeMetadataSectionAbsolute(cfg, parent = dirname(filename))
cfg$metadata = .makeMetadataSectionAbsolute(cfg, parent=dirname(filename))
# make data_sources section absolute
if(!is.null(cfg$data_sources))
cfg$data_sources = lapply(cfg$data_sources, .expandPath)
Expand All @@ -57,7 +57,7 @@
return(cfg)
}

.updateSubconfig = function(cfg, sp = NULL) {
.updateSubconfig = function(cfg, sp=NULL) {
if (!is.null(sp)) {
if (is.null(cfg$subprojects[[sp]])) {
warning("Subproject not found: ", sp)
Expand All @@ -70,8 +70,6 @@
return(cfg)
}



.listSubprojects = function(cfg, style="message") {
# this function can be used in object show method, where cat is preferred
# or for user information when the Project is created, where message
Expand All @@ -87,8 +85,7 @@

if (length(names(cfg$subprojects)) > 0) {
# If there are any show a cat and return if needed
printFun(" subprojects: ", paste0(names(cfg$subprojects),
collapse = ","))
printFun(" subprojects: ", paste0(names(cfg$subprojects), collapse=","))
invisible(names(cfg$subprojects))
} else{
# Otherwise return NULL for testing purposes
Expand Down
59 changes: 40 additions & 19 deletions R/models.R
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ setMethod(
#' projectConfig = system.file(
#' "extdata",
#' "example_peps-master",
#' "example_subannotation1",
#' "example_subtable1",
#' "project_config.yaml",
#' package = "pepr"
#' )
Expand All @@ -253,8 +253,8 @@ setMethod(
definition = function(.Object, sampleName, subsampleName) {
if (is.null(.Object@samples$subsample_name))
stop(
"There is no subsample_name attribute in the subannotation
table, therefore this method cannot be called."
"There is no subsample_name attribute in the subannotation",
" table, therefore this method cannot be called."
)
sampleNames = unlist(.Object@samples$sample_name)
rowNumber = which(sampleNames == sampleName)
Expand Down Expand Up @@ -336,18 +336,14 @@ setGeneric("activateSubproject", function(.Object, sp)

setMethod(
f = "activateSubproject",
signature = signature(.Object = "Project", sp = "character"),
signature = signature(.Object="Project", sp="character"),
definition = function(.Object, sp) {
.Object@config = .updateSubconfig(.Object@config, sp)

# Ensure that metadata paths are absolute and return the config.
# This used to be all metadata columns; now it's just: results_subdir
mdn = names(.Object@config$metadata)

.Object@config$metadata =
.makeMetadataSectionAbsolute(.Object@config,
parent = dirname(.Object@file))

.makeMetadataSectionAbsolute(.Object@config, parent=dirname(.Object@file))
.Object = .loadSampleAnnotation(.Object)
.Object = .loadSampleSubannotation(.Object)
.Object = .applyConstantAttributes(.Object)
Expand Down Expand Up @@ -468,24 +464,46 @@ setMethod(
} else {
sampleReadFunc = utils::read.table
}
sampleAnnotationPath = .Object@config$metadata$sample_annotation
if (.safeFileExists(sampleAnnotationPath)) {
if(is.null(.Object@config$metadata$sample_table)){
if(!is.null(.Object@config$metadata$sample_annotation)){
.Object@config$metadata$sample_table =
.Object@config$metadata$sample_annotation
warning("'sample_annotation' key in the 'metadata' section of the config "
,"is deprecated. Use 'sample_table' instead.")
} else{
if(!is.null(.Object@config$subprojects)){
# if there are any subprojects, just warn and return empty data.table,
# maybe there's a 'sample_table' specified in the subproject
warning("No 'sample_table' key in the 'metadata' section of the "
,"config")
.Object@samples = data.table::data.table()
return(.Object)
} else{
stop("No 'sample_table' key in the 'metadata' section of the config")
}
}
}
sampleAnnotationPath = .Object@config$metadata$sample_table
if(.safeFileExists(sampleAnnotationPath)){
samples = sampleReadFunc(sampleAnnotationPath)
} else{
if(!is.null(.Object@config$subprojects)){
warning("No sample annotation file: ", sampleAnnotationPath)
samples = data.table::data.table()
}else{
stop("No sample annotation file: ", sampleAnnotationPath)
}
stop("The sample annotation sheet does not exist: ", sampleAnnotationPath)
}
.Object@samples = samples
return(.Object)
}

.loadSampleSubannotation = function(.Object) {
.loadSampleSubannotation = function(.Object){
# Extracting needed slots
sampleSubannotationPath = .Object@config$metadata$sample_subannotation
if(is.null(.Object@config$metadata$subsample_table)){
if(!is.null(.Object@config$metadata$sample_subannotation)){
.Object@config$metadata$subsample_table =
.Object@config$metadata$sample_subannotation
warning("'sample_subannotation' key in the 'metadata' section of the"
,"config is deprecated. Use 'subsample_table' instead.")
}
}
sampleSubannotationPath = .Object@config$metadata$subsample_table
samples = .Object@samples
samples = .listifyDF(samples)
#Reading sample subannonataion table, just like in annotation table
Expand Down Expand Up @@ -522,6 +540,9 @@ setMethod(
# The column exists
whichColSamples = which(names(samples) == colName)
whichRowSamples = which(samples$sample_name == iName)
if(length(whichRowSamples) < 1){
stop("No samples named '", iName, "'")
}
# Inserting element(s) into the list
colList[[whichRowSamples]] = subTable[[colName]]
# Inserting the list as a column in the data.frame
Expand Down
8 changes: 4 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

#' Create an absolute path from a primary target and a parent candidate.
#
#' @param perhapsRelative: Path to primary target directory.
#' @param parent a path to parent folder to use if target isn't absolute.
#' @param perhapsRelative Path to primary target directory.
#' @param parent a path to parent folder to use if target isn't absolute.
#
#' @return Target itself if already absolute, else target nested within parent.
.makeAbsPath = function(perhapsRelative, parent) {
Expand Down Expand Up @@ -88,7 +88,7 @@
#' fetchSamples(s,attr = "sample_name", func=function(x){ grep("pig_",x) },action="include")
#' @export
fetchSamples = function(samples, attr=NULL, func=NULL, action="include"){
if(!is(samples, "data.table"))
if(!methods::is(samples, "data.table"))
stop("'samples' argument has to be a data.table object, got: '",
class(samples),"'")
if(!action %in% c("include","exclude"))
Expand All @@ -114,7 +114,7 @@ fetchSamples = function(samples, attr=NULL, func=NULL, action="include"){
}
}
}
if(length(rowIdx) < 1 || (!is(rowIdx,"integer")))
if(length(rowIdx) < 1 || (!methods::is(rowIdx,"integer")))
stop("your function returned invalid indices: '", rowIdx,"'")
# use action arg
if(action=="include") return(samples[rowIdx, ])
Expand Down
Binary file added inst/.DS_Store
Binary file not shown.
Binary file added inst/extdata/.DS_Store
Binary file not shown.
5 changes: 4 additions & 1 deletion inst/extdata/example_peps-master/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,7 @@ target/


# Rcaches
RCache/*
RCache/*

# macOS
*.DS_Store
2 changes: 0 additions & 2 deletions inst/extdata/example_peps-master/example_BiocProject/anno.csv

This file was deleted.

Loading

0 comments on commit da20560

Please sign in to comment.