I think colPair is a convenient place to put a KNN graph to avoid recalculating it if multiple functions will use it. I realize findKNN doesn't return a well defined object, but I think a quick length, name, dimension check should cover most situations. This is what I'm doing now, apologies for not having a more relevant code snippet, my OOP is more or less non-existent.
colPairKnnHelper <- function(sce, type, knn){
validSCE(sce)
if(type %in% colPairNames(sce)){
stop("type already exists in colPairs")
}
stopifnot(is.list(knn) && length(knn) == 2 &&
identical(names(knn), c("index", "distance")))
stopifnot(ncol(sce) == nrow(knn$index) && ncol(sce) == nrow(knn$distance))
colPair(sce, type) <- sparseMatrix(i = rep(1:nrow(knn$index),
length.out = length(knn$index)),
j = as.vector(knn$index),
x = as.vector(knn$distance),
dims = c(nrow(knn$index), nrow(knn$index)))
return(sce)
}
I think
colPairis a convenient place to put a KNN graph to avoid recalculating it if multiple functions will use it. I realizefindKNNdoesn't return a well defined object, but I think a quick length, name, dimension check should cover most situations. This is what I'm doing now, apologies for not having a more relevant code snippet, my OOP is more or less non-existent.