Skip to content

Commit

Permalink
add entity to pca output vars
Browse files Browse the repository at this point in the history
  • Loading branch information
asizemore committed Jan 21, 2025
1 parent d23800d commit 29fc9dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions R/method-pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ setMethod(pca, "Collection",
recordIdColumn <- collection@recordIdColumn
ancestorIdColumns <- collection@ancestorIdColumns
allIdColumns <- c(recordIdColumn, ancestorIdColumns)
entity <- veupathUtils::strSplit(recordIdColumn,".", 4, 1)

# Remove id columns from the assay to get only the features.
features <- assay[, -..allIdColumns] # features has samples as rows.
Expand Down Expand Up @@ -53,7 +54,7 @@ setMethod(pca, "Collection",
variableMetadataList <- lapply(1:nPCs, function(i) {
veupathUtils::VariableMetadata(
variableClass = veupathUtils::VariableClass(value = "computed"),
variableSpec = veupathUtils::VariableSpec(variableId = paste0("PC",i), entityId = ''), # computed var so not assinging entity.
variableSpec = veupathUtils::VariableSpec(variableId = paste0("PC",i), entityId = entity),
displayName = paste0("PC ",i),
displayRangeMin = min(pcaResult$x[,i]),
displayRangeMax = max(pcaResult$x[,i]),
Expand All @@ -68,7 +69,9 @@ setMethod(pca, "Collection",
result@ancestorIdColumns <- ancestorIdColumns
result@data <- dt
result@parameters <- paste0('recordIdColumn = ', recordIdColumn,", nPCs = ", nPCs, ', ntop = ', ntop)
result@computedVariableMetadata <- veupathUtils::VariableMetadataList(S4Vectors::SimpleList(variableMetadataList))
result@computedVariableMetadata <- veupathUtils::VariableMetadataList(
S4Vectors::SimpleList(variableMetadataList)
)

return(result)
}
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-method-pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ test_that("The pca function can handle messy data", {
expect_s4_class(computedVariableMetadata[[2]], "VariableMetadata")
expect_s4_class(computedVariableMetadata[[3]], "VariableMetadata")
expect_equal(computedVariableMetadata[[1]]@variableSpec@variableId, "PC1")
expect_equal(computedVariableMetadata[[1]]@variableSpec@entityId, "entity")
expect_equal(computedVariableMetadata[[2]]@variableSpec@variableId, "PC2")
expect_equal(computedVariableMetadata[[2]]@variableSpec@entityId, "entity")
expect_equal(computedVariableMetadata[[3]]@variableSpec@variableId, "PC3")
expect_equal(computedVariableMetadata[[3]]@variableSpec@entityId, "entity")


# Test with not enough features
Expand Down

0 comments on commit 29fc9dd

Please sign in to comment.