Skip to content

Commit

Permalink
wip: fixing MbioDataset constructor and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
d-callan committed Feb 13, 2024
1 parent 04f8238 commit cec9738
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion R/class-MbioDataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ check_mbio_dataset <- function(object) {
# check that at least some ancestorIdColumns are shared between collections and sampleMetadata
sampleMetadataAncestorIds <- object@metadata@ancestorIdColumns
if (!!length(sampleMetadataAncestorIds)) {
if (!all(lapply(object@collections, function(x) any(x@ancestorIdColumns %in% sampleMetadataAncestorIds)))) {
if (!all(sapply(object@collections, function(x) any(x@ancestorIdColumns %in% sampleMetadataAncestorIds)))) {
msg <- "at least one ancestorIdColumn must be shared between collections and sampleMetadata"
errors <- c(errors, msg)
}
Expand Down
2 changes: 1 addition & 1 deletion R/constructors-MbioDataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ sampleMetadataBuilder <- function(dataSource) {
sampleMetadata <- new("SampleMetadata",
data=dt,
recordIdColumn = recordIdColumn,
ancestorIdColumns = findAncestorIdColumns
ancestorIdColumns = ancestorIdColumns
)

return(sampleMetadata)
Expand Down
10 changes: 5 additions & 5 deletions R/methods-MbioDataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ setMethod("getCollection", "MbioDataset", function(object, collectionName = char
}

abundanceData <- microbiomeComputations::AbundanceData(
data = object@collections[[collectionName]][[1]]@data,
sampleMetadata = sampleMetadataBuilder(object@metadata),
recordIdColumn = object@collections[[collectionName]][[1]]@recordIdColumn,
ancestorIdColumns = object@collections[[collectionName]][[1]]@ancestorIdColumns
data = object@collections[collectionName][[1]]@data,
sampleMetadata = object@metadata,
recordIdColumn = object@collections[collectionName][[1]]@recordIdColumn,
ancestorIdColumns = object@collections[collectionName][[1]]@ancestorIdColumns
)

return(abundanceData)
Expand Down Expand Up @@ -94,6 +94,6 @@ setMethod("getComputeResult", "CorrelationResult", function(object, format = c("
#' @importFrom microbiomeComputations DifferentialAbundanceResult
#' @export
setMethod("getComputeResult", "DifferentialAbundanceResult", function(object, format = c("data.table")) {
format <- veupathUtils::matchArg(format)
format <- veupathUtils::matchArg(format)
return(object@statistics)
})
8 changes: 4 additions & 4 deletions tests/testthat/test-MbioDataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ test_that("we can update collection names and get collections", {
expect_equal(getCollectionNames(testDataset)[[1]], "My Collection")

testCollection <- getCollection(testDataset, "My Collection")
expect_s4_class(testCollection, "Collection")
expect_equal(testCollection@name, "My Collection")
expect_equal(testCollection@data, data.frame(entity.id = 1, entity.collection_x = 1, entity.collection_y = 2))
expect_s4_class(testCollection, "AbundanceData")
expect_equal(testCollection@data, data.frame(entity.id = 1, entity.collection_x = 1, entity.collection_y = 2, ancestor.y = 1))
expect_equal(testCollection@recordIdColumn, "entity.id")
expect_equal(testCollection@ancestorIdColumns, "ancestor.y")
})

test_that("we can get compute results in different formats", {
Expand All @@ -74,7 +74,7 @@ test_that("we can get compute results in different formats", {
metadataFile3 <- '../../inst/extdata/DiabImmune/DiabImmune_Sample.txt'
mbioDataset <- MbioDataset(list(dataFile1, dataFile2), list(metadataFile1, metadataFile2, metadataFile3))

correlationOutput <- microbiomeComputations::correlation(getCollection(mbioDataset, "16S Genus"))
correlationOutput <- microbiomeComputations::correlation(getCollection(mbioDataset, "16S EUPATH_0009256")) ## Genus
correlationDT <- getComputeResult(correlationOutput, "data.table")

expect_equal(inherits(correlationDT, "data.table"), TRUE)
Expand Down

0 comments on commit cec9738

Please sign in to comment.