Skip to content

Instantly share code, notes, and snippets.

@kieranrcampbell
Created September 26, 2018 22:09
Show Gist options
  • Save kieranrcampbell/cc265e9f7019a8c90f2a09d0145a68f6 to your computer and use it in GitHub Desktop.
Save kieranrcampbell/cc265e9f7019a8c90f2a09d0145a68f6 to your computer and use it in GitHub Desktop.
clusterMap <- function(sce1, sce2) {
clusters1 <- sort(unique(sce1$cluster)) # get unique clusters
clusters2 <- sort(unique(sce2$cluster))
# Check this is gene (row) by cluster (cell) - if not needs transposed
cluster_means_1 <- sapply(clusters1, function(x) {
rowMeans(as.matrix(logcounts(sce1[,sce1$cluster == x]))
}))
cluster_means_2 <- sapply(clusters2, function(x) {
rowMeans(as.matrix(logcounts(sce2[,sce2$cluster == x]))
}))
# The cor function can take two matrices and return
# the correlations between their columns
cor(cluster_means_1, cluster_means_2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment