MarioniLab / scran

Clone of the Bioconductor repository for the scran package.
https://bioconductor.org/packages/devel/bioc/html/scran.html
40 stars 22 forks source link

Add type="jaccard" to BuildSNNGraph #40

Closed lazappi closed 5 years ago

lazappi commented 5 years ago

Would it be possible to add an option to weight edges in the SNN graph by the Jaccard index between the two sets of nearest neighbours? This would replicate how Seurat builds its SNN graph.

LTLA commented 5 years ago

Yes.

LTLA commented 5 years ago

Done. For the time being, you can get the same results in BioC-release by noting that the Jaccard similarity weights are a simple monotonic transformation of the weights from type="number":

exprs <- matrix(rnorm(100000), ncol=100)
g <- buildSNNGraph(exprs, type="number")

library(igraph) # careful, this overwrites normalize()!
E(g)$weight <- E(g)$weight / (2 * (k + 1) - E(g)$weight)

Also note that we consider a node to be an implicit neighbor of itself, so when you're asking for k nearest neighbors, the actual size of the set is k+1, because each cell adds itself to the mix. This may be necessary if you want to get the literal exact same results.

Also note that the choice of NN algorithm used by BiocNeighbors will affect the treatment of tied neighbors, which is effectively random. This may also affect the results.