Skip to content

Commit

Permalink
Merge pull request #41 from pepkit/dev
Browse files Browse the repository at this point in the history
v0.4.0
  • Loading branch information
stolarczyk authored Oct 14, 2020
2 parents 345cb54 + 2e231a8 commit a38873b
Show file tree
Hide file tree
Showing 30 changed files with 197 additions and 92 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/new-build-R.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
on:
push:
branches:
- master
pull_request:
branches:
- master

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@master
with:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-pandoc@master

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
- name: Install dependencies
run: |
remotes::install_cran("covr")
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check

- name: Report test coverage
run: covr::codecov()
shell: Rscript {0}
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: pepr
Type: Package
Title: Reading Portable Encapsulated Projects
Version: 0.3.2
Date: 2020-06-03
Version: 0.4.0
Date: 2020-10-15
Authors@R: c(person("Nathan", "Sheffield", email = "nathan@code.databio.org",
role = c("aut", "cph")),person("Michal","Stolarczyk",email="michal@virginia.edu",role=c("aut","cre")))
Maintainer: Michal Stolarczyk <michal@virginia.edu>
Expand Down
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# pepr 0.4.0 - 2020-10-14

## Changed

* added multiple subsample_table support

## Fixed

* issues with config file determination

# pepr 0.3.2 - 2020-06-03

## Changed
Expand Down
6 changes: 4 additions & 2 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ setMethod(
.expandList <- function(x) {
if(is.list(x))
return(lapply(x, .expandList))
if(length(x) > 1)
return(unname(sapply(x, .expandList)))
return(suppressWarnings(.expandPath(x)))
}

Expand Down Expand Up @@ -129,12 +131,12 @@ setMethod("[[", "Config", function(x, i) {


.DollarNames.Config <- function(x, pattern = "")
grep(pattern, grep(names(x), value=TRUE))
grep(paste0("^", pattern), grep(names(x), value=TRUE))

#' @rdname select-config
#' @export
setMethod("$", "Config", function(x, name){
matches = grep(name, names(x))
matches = grep(paste0("^", name), names(x))
if(length(matches) == 0)
return(NULL)
hits = x[[matches]]
Expand Down
38 changes: 26 additions & 12 deletions R/project.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ setMethod("initialize", "Project", function(.Object, ...) {
# check if file path provided
.Object@file = .makeAbsPath(ellipsis$file, parent = path.expand(getwd()))
# instantiate config object and stick it in the config slot
.Object@config = Config(ellipsis$file, ellipsis$amendments)
.Object@config = Config(.Object@file, ellipsis$amendments)
.Object = .loadSampleAnnotation(.Object)
.Object = .modifySamples(.Object)
}
Expand Down Expand Up @@ -479,40 +479,37 @@ setMethod(
}


#' Merge samples defined in sample table with ones in subsample table
#' Load single subsample annotation
#'
#' @param .Object an object of \code{"\linkS4class{Project}"}
#' @param path string, a path to the subsample table to read and incorporate
#'
#' @return an object of \code{"\linkS4class{Project}"}
.mergeAttrs = function(.Object){
cfg = config(.Object)
if (!CFG_SUBSAMPLE_TABLE_KEY %in% names(cfg)) return(.Object)
sampleSubannotationPath = cfg[[CFG_SUBSAMPLE_TABLE_KEY]]
samples = sampleTable(.Object)
samples = .listifyDF(samples)
if (.safeFileExists(sampleSubannotationPath)) {
samplesSubannotation = data.table::fread(sampleSubannotationPath)
.loadSubsampleAnnotation = function(.Object, path) {
if (.safeFileExists(path)) {
samplesSubannotation = data.table::fread(path)
} else{
samplesSubannotation = data.table::data.table()
}
subNames = unique(samplesSubannotation$sample_name)
samples = sampleTable(.Object)
samples = .listifyDF(samples)
rowNum = nrow(samples)
# Creating a list to be populated in the loop and inserted
# into the samples data.table as a column. This way the "cells"
# in the samples table can consist of multiple elements
colList = vector("list", rowNum)
for (iName in subNames) {
whichNames = which(samplesSubannotation$sample_name == iName)
subTable = samplesSubannotation[whichNames,]
dropCol = which(names(samplesSubannotation[whichNames,]) == "sample_name")
subTable = subset(subTable, select = -dropCol)
colList = vector("list", rowNum)
for (iColumn in seq_len(ncol(subTable))) {
colName = names(subset(subTable, select = iColumn))
if (!any(names(samples) == colName)) {
# The column doesn't exist, creating
samples[, colName] = NULL
} else{
# colList=as.list(unname(samples[, ..colName]))[[1]]
colList = samples[[colName]]
}
# The column exists
Expand All @@ -532,3 +529,20 @@ setMethod(
.Object@samples = samples
return(.Object)
}



#' Merge samples defined in sample table with ones in subsample table(s)
#'
#' @param .Object an object of \code{"\linkS4class{Project}"}
#'
#' @return an object of \code{"\linkS4class{Project}"}
.mergeAttrs = function(.Object){
cfg = config(.Object)
if (!CFG_SUBSAMPLE_TABLE_KEY %in% names(cfg)) return(.Object)
sampleSubannotationPath = cfg[[CFG_SUBSAMPLE_TABLE_KEY]]
for(p in sampleSubannotationPath){
.Object = .loadSubsampleAnnotation(.Object, p)
}
return(.Object)
}
24 changes: 14 additions & 10 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,21 @@
#' @export
#' @return Target itself if already absolute, else target nested within parent.
.makeAbsPath = function(perhapsRelative, parent) {
if (!.isDefined(perhapsRelative)) return(perhapsRelative)
perhapsRelative = .expandPath(perhapsRelative)
if (.isAbsolute(perhapsRelative)) {
abspath = perhapsRelative
} else {
abspath = file.path(path.expand(parent), perhapsRelative)
res = c()
for(pR in perhapsRelative){
if (!.isDefined(pR)) return(pR)
pR = .expandPath(pR)
if (.isAbsolute(pR)) {
abspath = pR
} else {
abspath = file.path(path.expand(parent), pR)
}
if (!.isAbsolute(abspath))
stop("Relative path ", pR, " and parent ", parent ,
" failed to create absolute path: ", abspath)
res = append(res, abspath)
}
if (!.isAbsolute(abspath))
stop("Relative path ", perhapsRelative, " and parent ", parent ,
" failed to create absolute path: ", abspath)
return(abspath)
return(res)
}

# Must test for is.null first, since is.na(NULL) returns a logical(0) which is
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Downloads](http://cranlogs.r-pkg.org/badges/grand-total/pepr)](http://cranlogs.r-pkg.org/badges/grand-total/pepr)
[![CRAN](http://www.r-pkg.org/badges/version-last-release/pepr)](http://www.r-pkg.org/badges/version-last-release/pepr)
[![Build Status](https://travis-ci.org/pepkit/pepr.svg?branch=master)](https://travis-ci.org/pepkit/pepr)
[![Coverage Status](https://coveralls.io/repos/github/pepkit/pepr/badge.svg?branch=dev)](https://coveralls.io/github/pepkit/pepr?branch=dev&service=github)
![R-CMD-check](https://github.com/pepkit/pepr/workflows/R-CMD-check/badge.svg)
[![codecov](https://codecov.io/gh/pepkit/pepr/branch/master/graph/badge.svg)](https://codecov.io/gh/pepkit/pepr)
[![PEP compatible](http://pepkit.github.io/img/PEP-compatible-green.svg)](http://pepkit.github.io)

# The `pepr` package: Portable Encapsulated Projects in R
Expand All @@ -25,7 +25,7 @@ Load a project and explore metadata like this:
library("pepr")
cfgPath = system.file(
"extdata",
paste0("example_peps-master"),
"example_peps-master",
"example_basic",
"project_config.yaml",
package = "pepr"
Expand Down
4 changes: 0 additions & 4 deletions inst/extdata/example_peps-master/data/frog1_data.txt

This file was deleted.

2 changes: 0 additions & 2 deletions inst/extdata/example_peps-master/data/frog1a_data.txt

This file was deleted.

2 changes: 0 additions & 2 deletions inst/extdata/example_peps-master/data/frog1a_data2.txt

This file was deleted.

3 changes: 0 additions & 3 deletions inst/extdata/example_peps-master/data/frog1b_data.txt

This file was deleted.

3 changes: 0 additions & 3 deletions inst/extdata/example_peps-master/data/frog1b_data2.txt

This file was deleted.

2 changes: 0 additions & 2 deletions inst/extdata/example_peps-master/data/frog1c_data.txt

This file was deleted.

2 changes: 0 additions & 2 deletions inst/extdata/example_peps-master/data/frog1c_data2.txt

This file was deleted.

7 changes: 0 additions & 7 deletions inst/extdata/example_peps-master/data/frog2_data.txt

This file was deleted.

3 changes: 0 additions & 3 deletions inst/extdata/example_peps-master/data/frog2a_data.txt

This file was deleted.

3 changes: 0 additions & 3 deletions inst/extdata/example_peps-master/data/frog2b_data.txt

This file was deleted.

7 changes: 0 additions & 7 deletions inst/extdata/example_peps-master/data/frog3_data.txt

This file was deleted.

7 changes: 0 additions & 7 deletions inst/extdata/example_peps-master/data/frog4_data.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pep_version: "2.0.0"
sample_table: sample_table.csv
subsample_table: subsample_table.csv
output_dir: $HOME/example_results
looper:
output_dir: $HOME/example_results
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
pep_version: "2.0.0"
sample_table: sample_table.csv
subsample_table: subsample_table.csv
output_dir: $HOME/hello_looper_results
pipeline_interfaces: [../pipeline/pipeline_interface.yaml]
looper:
output_dir: $HOME/hello_looper_results
pipeline_interfaces: [../pipeline/pipeline_interface.yaml]

sample_modifiers:
derive:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
pep_version: "2.0.0"
sample_table: sample_table.csv
subsample_table: subsample_table.csv
output_dir: $HOME/hello_looper_results
pipeline_interfaces: [../pipeline/pipeline_interface.yaml]
looper:
output_dir: $HOME/hello_looper_results
pipeline_interfaces: [../pipeline/pipeline_interface.yaml]

sample_modifiers:
derive:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pep_version: "2.0.0"
sample_table: sample_table.csv
subsample_table: subsample_table.csv
output_dir: $HOME/hello_looper_results
pipeline_interfaces: [../pipeline/pipeline_interface.yaml]
looper:
output_dir: $HOME/hello_looper_results
pipeline_interfaces: [../pipeline/pipeline_interface.yaml]

Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
pep_version: "2.0.0"
sample_table: sample_table.csv
subsample_table: subsample_table.csv
output_dir: $HOME/hello_looper_results
pipeline_interfaces: [../pipeline/pipeline_interface.yaml]
looper:
output_dir: $HOME/hello_looper_results
pipeline_interfaces: [../pipeline/pipeline_interface.yaml]

sample_modifiers:
derive:
Expand Down
Loading

0 comments on commit a38873b

Please sign in to comment.