vertesy / Seurat.multicore

Multicore and utility functions for Seurat 2 & 3, using doMC / foreach packages.

Home Page:https://vertesy.github.io/Seurat.multicore

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

color UMAP by genotype frequency

vertesy opened this issue · comments

  1. Ideally you calculate frequency in a raster like manner, with sub-cluster resolution.
  2. Store in @meta and plot as usual, but change color gradient. (Viridis?)

Steps

  • 1. Get kNN for each cell
  • 2. Calculate the ratio
  • 3. Set to metadata column
  • 4. Set color gradient in UMAP
N=10
coord.umap=cbind(rnorm(N), rnorm(N))
plot(coord.umap)
(xx = get.knn(coord.umap, k = 3, algorithm = "brute") )
(zz= xx$nn.index[1,])


MarkdownReports::wplot(coord.umap, pch=18, equal.axes = T)
points(x = coord.umap[1,1], y = coord.umap[1,2], col=2, pch=18)
points(x = coord.umap[zz,1], y = coord.umap[zz,2], col=3, pch=18)
 #--------



get.knn.Coord <- function(df2col = coord.umap=cbind(rnorm(10), rnorm(10)), k_ =3, plotit =F) {
  xx = get.knn(coord.umap, k = k_)$nn.index # , algorithm = "brute"
  
  if (plotit) {
  zz= xx$nn.index[1,]
  MarkdownReports::wplot(df2col, pch=18, equal.axes = T)
  points(x = df2col[1,1], y = df2col[1,2], col=2, pch=18)
  points(x = df2col[zz,1], y = df2col[zz,2], col=3, pch=18)
  }
  return(xx)  
}
# knn.matrix <- get.knn.Coord (df2col = coord.UMAP, k_=10)

get.knn.Coord()

frac.condition <- function(obj=combined.obj, mat = knn.matrix, colName="genotype") {
  condition = obj@meta[,colName]
}
# knn.matrix <- frac.condition (mat = knn.matrix)

hexbin with custom color scale might be an alternative approach

not maintained.