Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ r:
- bioc-devel
# Mac OS R devel build URL is out of date, currently.
# https://travis-ci.community/t/672
# Also seeing trouble with bioc-devel on Mac OS, but community site is timing
# out so I'm not sure what the deal is with that one. (2019-11-20)
matrix:
exclude:
- r: devel
os: osx
- r: bioc-devel
os: osx
cache: packages
script:
- R CMD build .
Expand Down
27 changes: 16 additions & 11 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,22 @@ full_locus_match <- function(sample_data, locus_name) {
#'
#' @return character vector of entry identifiers
make_entry_id <- function(data) {
cols.names <- c("Dataset", "Sample", "Name", "Replicate", "Locus")
cols.idx <- match(cols.names, colnames(data))
cols.idx <- cols.idx[!is.na(cols.idx)]
cols.idx <- cols.idx[unlist(lapply(cols.idx, function(x) {
!all(is.na(data[, x]))
}))]
data.names <- data[, cols.idx, drop = FALSE]
sapply(1:nrow(data.names), function(nr) {
entries <- lapply(data.names[nr, !is.na(data.names[nr, ])], as.character)
do.call(paste, as.list(c(entries, sep = "-")))
})
cols_names <- c("Dataset", "Sample", "Name", "Replicate", "Locus")
cols_idx <- match(cols_names, colnames(data))
cols_idx <- cols_idx[! is.na(cols_idx)]
if (length(cols_idx)) {
cols_idx <- cols_idx[unlist(lapply(cols_idx, function(x) {
! all(is.na(data[, x]))
}))]
data_names <- data[, cols_idx, drop = FALSE]
sapply(1:nrow(data_names), function(nr) {
entries <- lapply(data_names[nr, ! is.na(data_names[nr, ])], as.character)
do.call(paste, as.list(c(entries, sep = "-")))
})
} else {
warning("no recognized columns for entry id")
paste0("entry", 1:nrow(data))
}
}

#' Create Row Names for STR Data
Expand Down
32 changes: 32 additions & 0 deletions tests/testthat/test_io.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ with(test_data, {
expect_true(all(locus_attrs == locus_attrs_test))
})

test_that("load_csv parses CSV files with unknown columns", {
# For cases where our CSV file has none of the recognized column names, it
# should still work but just give us generic rownames and a
# warning.
fp <- tempfile()
data_expected <- data.frame(
Vec1 = c("A", "D"),
Vec2 = c("B", "E"),
Vec3 = c("C", "F"),
stringsAsFactors = FALSE,
row.names = c("entry1", "entry2"))
cat("Vec1,Vec2,Vec3\nA,B,C\nD,E,F\n", file = fp)
expect_warning(data <- load_csv(fp), "no recognized columns for entry id")
file.remove(fp)
expect_equal(data, data_expected)
})


test_that("save_csv saves CSV files", {
fp <- tempfile()
Expand All @@ -86,6 +103,21 @@ with(test_data, {
expect_true(all(locus_attrs == locus_attrs_test))
})

test_that("save_csv saves CSV files with unknown columns", {
# save_csv shouldn't care about the columns but we'll make sure here.
fp <- tempfile()
data_expected <- data.frame(
Vec1 = c("A", "D"),
Vec2 = c("B", "E"),
Vec3 = c("C", "F"),
stringsAsFactors = FALSE)
save_csv(data_expected, fp)
expect_warning(data <- load_csv(fp))
file.remove(fp)
rownames(data_expected) <- c("entry1", "entry2")
expect_equal(data, data_expected)
})


# test load_locus_attrs ---------------------------------------------------

Expand Down