mayer-lab / Mayer-et-al-2018_IntegratedAnalysis

Data and code associated with the integrated analysis (Figure 4) in Mayer et al 2018
GNU General Public License v3.0
9 stars 1 forks source link

How I can assignment of precursor cells to adult subtypes after integrating both datasets in Seurat V3? #2

Open Sophia409 opened 5 years ago

Sophia409 commented 5 years ago

Hello, Mayer-lab I have read you paper and want to follow your pipeline to assign precursor cells to adult subtypes in my data.Since Seurat has updated to V3, IntegrateData has replaced RunCCA-AlignSubspace function.So wondering in this version, how I can assignment of precursor cells to adult subtypes after integrating both datasets? I read your Script 2_cell_assignment.R,and try to modify MapCells function to v3 verison. But because I'm a new comer in single cell analysis and R language, I have try my best and still couldn't finish this task. I will be much appreciated if you can show me the updated code to Perform this function. Looking forward to your help Sophia image

# this script performs the following steps:
# 1) assignment of precursor cells to adult subtypes
# 3) visualization of assignment - cardinal types 
# 4) visualization of assignment - subtypes
# related to Fig.4 B-D) lower part and Extended Data Figure 9

library(pbapply)
# assign precursor cells to adult subtypes
MapCells=function(object, timepoint.dev="P10", timepoint.end="P56", num.k=10, thresh.require=0.9,map.col="AdultTypes1",new.col="Map1") {
  tsne.dims=object@calc.params$RunTSNE$dims.use
  input.dims=GetCellEmbeddings(object,reduction.type = "cca.aligned",dims.use = tsne.dims)
  input.dist=as.matrix(dist(input.dims))
  cells.end=FastWhichCells(object,"DevStage",timepoint.end)
  cells.map=FastWhichCells(object,"DevStage",timepoint.dev)
  map.id=pbsapply(cells.map,function(x)
    names(which(sort(table(object@meta.data[names(sort(input.dist[x,cells.end])[1:num.k]),map.col]),decreasing = T)>=num.k*thresh.require))[1])
  nn.same=pbsapply(cells.map, function(x) length(intersect(names(sort(input.dist[x,])[1:num.k]),cells.map)))
  print(table(map.id))
  map.id[is.na(map.id)]="Unassigned"
  map.id[names(which(nn.same>=num.k*1))]="Unassigned"
  print(table(map.id))
  object@meta.data[cells.end,new.col]=object@meta.data[cells.end,map.col]
  object@meta.data[cells.map,new.col]=map.id
  return(object)
} 
mayer-lab commented 5 years ago

Hi, here is a version of the MapCells function for Seurat V3:

MapCells=function(object, unknown.id="P11", known.id="P60", num.k=10, thresh.require=0.9,map.col="Cell_types",new.col="Mapped") {

  tsne.dims=object@reductions$tsne

  input.dims=Embeddings(object,reduction.type = "integrated",dims.use = tsne.dims)

  input.dist=as.matrix(dist(input.dims))

  cells.end <- colnames(object[,object@meta.data$DevStage == known.id])

  cells.map=colnames(object[,object@meta.data$DevStage == unknown.id])

  map.id=pbsapply(cells.map,function(x)

    names(which(sort(table(object@meta.data[names(sort(input.dist[x,cells.end])[1:num.k]),map.col]),decreasing = T)>=num.k*thresh.require))[1])

  nn.same=pbsapply(cells.map, function(x) length(intersect(names(sort(input.dist[x,])[1:num.k]),cells.map)))

  print(table(map.id))

  map.id[is.na(map.id)]="Unassigned"

  map.id[names(which(nn.same>=num.k*1))]="Unassigned"

  print(table(map.id))

  object@meta.data[cells.end,new.col]=object@meta.data[cells.end,map.col]

  object@meta.data[cells.map,new.col]=map.id

  return(object)

}

You can also install the modified version of Seurat that was used in Mayer et al. 2018 via GitHub:

library(devtools)
install_github("mayer-lab/SeuratForMayer2018")
library(Seurat)
library(pbapply)
Sophia409 commented 5 years ago

@mayer-lab Hello, many thanks for your help.I also installed that modified version of Seurat, but it is based on Seurat V2. So the IntegrateData method is not included. Do you continue to recommend using RunCCA for mapping precursor cells to adult subtypes or IntegrateData method?

mayer-lab commented 5 years ago

Hi, if you like to reproduce the analysis from the paper I suggest to use MapCells. Of course there are many other ways to connect cell-types across datasets (e.g. https://doi.org/10.1038/s41592-019-0534-4). As you have probably noticed, in Seurat V3 you can also transfer cell type labels from a reference dataset.