Skip to content

Request to allow colPair to accept the output from findKNN #89

@doliv071

Description

@doliv071

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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions