Computes Jaccard Similarity between two sets, x1 and x2.

getJaccard(x1, x2, assert.unique = T)

Arguments

x1

set 1

x2

set 2

assert.unique

Logical flag specifying whether to ensure that x1 and x2 are unique. Default is TRUE.

Value

Jaccard similarity score (numeric)

See also

pheatmap

Examples


# compute jaccard similarity matrix for (named) list of genesets.
n.sets <- length(gene.sets)
#> Error in eval(expr, envir, enclos): object 'gene.sets' not found
j.mat <- matrix(nrow = n.sets, ncol = n.sets)
#> Error in matrix(nrow = n.sets, ncol = n.sets): object 'n.sets' not found
for (i in 1:n.sets){
  for (j in 1:n.sets){
    i.name <- names(gene.sets)[i]
    j.name <- names(gene.sets)[j]
    j.mat[i, j] <- getJaccard(gene.sets[[i.name]], gene.sets[[j.name]])
  }
}
#> Error in eval(expr, envir, enclos): object 'n.sets' not found

# assign row and col names
rownames(j.mat) <- names(gene.sets)
#> Error in eval(expr, envir, enclos): object 'gene.sets' not found
colnames(j.mat) <- names(gene.sets)
#> Error in eval(expr, envir, enclos): object 'gene.sets' not found

# generate heatmap
pheatmap::pheatmap(j.mat, show_colnames = F, main = "Jaccard Similarity")
#> Error in rownames(mat): object 'j.mat' not found