This function will calculate Euclidean distances between single-cells in a neighbourhood using the same dimensionality as was used to construct the graph. This step follows the makeNhoods call to limit the number of distance calculations required.

calcNhoodDistance(x, d, reduced.dim = NULL, use.assay = "logcounts")



A Milo object with a valid graph slot. If reduced.dims is not provided and there is no valid populated reducedDim slot in x, then this is computed first with d + 1 principal components.


The number of dimensions to use for computing within-neighbourhood distances. This should be the same value used construct the graph.


If x is an Milo object, a character indicating the name of the reducedDim slot in the Milo object to use as (default: 'PCA'). Otherwise this should be an N X P matrix with rows in the same order as the columns of the input Milo object x.


A character scalar defining which assay slot in the Milo to use


A Milo object with the distance slots populated.


library(SingleCellExperiment) ux <- matrix(rpois(12000, 5), ncol=200) vx <- log2(ux + 1) pca <- prcomp(t(vx)) sce <- SingleCellExperiment(assays=list(counts=ux, logcounts=vx), reducedDims=SimpleList(PCA=pca$x)) milo <- Milo(sce) milo <- buildGraph(milo, d=30, transposed=TRUE)
#> Constructing kNN graph with k:10
milo <- calcNhoodDistance(milo, d=30) milo
#> class: Milo #> dim: 60 200 #> metadata(0): #> assays(2): counts logcounts #> rownames: NULL #> rowData names(0): #> colnames: NULL #> colData names(0): #> reducedDimNames(1): PCA #> spikeNames(0): #> altExpNames(0): #> nhoods dimensions(1): 0 #> nhoodCounts dimensions(2): 1 1 #> nhoodDistances dimension(1): 0 #> graph names(1): graph #> nhoodIndex names(1): 0 #> nhoodExpression dimension(2): 1 1 #> nhoodReducedDim names(0): #> nhoodGraph names(0): #> nhoodAdjacency dimension(0):