Seurat识别细胞类群的原理(FindNeighbors和FindClusters)

众所周知,seurat在降维之后主要依据两个函数来进行细胞分类,这里我们来深入了解一下seurat如何进行细胞分类的。
首先我们来看有关分类的两个函数

library(Seurat)
?FindNeighbors
Description:
    Constructs a Shared Nearest Neighbor (SNN) Graph for a given
     dataset. We first determine the k-nearest neighbors of each cell.
     We use this knn graph to construct the SNN graph by calculating
     the neighborhood overlap (Jaccard index) between every cell and
     its k.param nearest neighbors.
这个地方说明,这个函数首先是计算每个细胞的KNN,也就是计算每个细胞之间的相互距离,依据细胞之间距离的graph来构建snn graph(依据细胞之间“邻居”的overlop)
这里有三个问题:1、knn是什么,2、Jaccard index又是什么  3、邻居的判定
我们来看看参数(主要参数):
distance.matrix: Boolean value of whether the provided matrix is a
          distance matrix; note, for objects of class ‘dist’, this
          parameter will be set automatically
      这个参数我们通常不会设置,但是默认是TRUE。
k.param: Defines k for the k-nearest neighbor algorithm
      这个参数就是用来定义最相近的几个细胞作为邻居,默认是20
compute.SNN: also compute the shared nearest neighbor graph
     计算共享邻居的数量,一般不设置
prune.SNN: Sets the cutoff for acceptable Jaccard index when computing
          the neighborhood overlap for the SNN construction. Any edges
          with values less than or equal to this will be set to 0 and
          removed from the SNN graph. Essentially sets the strigency of
          pruning (0 - no pruning, 1 - prune everything).
     在计算SNN构造的邻域重叠时,为可接受的Jaccard index设置截止值。 值小于或等于此值的任何边将被设置为0并从SNN图中删除。 本质上设置修剪的严格程度(0-不修剪,1-修剪所有内容)。**这个我们在后面讨论**。
nn.method: Method for nearest neighbor finding. Options include: rann,
          annoy
      这个参数提供了如何判断邻居的方法,提供的可选是rann和annoy,**这个我们在后面讨论**。
      annoy.metric: Distance metric for annoy. Options include: euclidean,
          cosine, manhattan, and hamming
      (annoy距离的方式)
force.recalc: Force recalculation of SNN
      SNN强制重新计算,一般不设置

我们来一一解决其中的问题

1、什么是Jaccard index

Jaccard index , 又称为Jaccard相似系数(Jaccard similarity coefficient)用于比较有限样本集之间的相似性与差异性。Jaccard系数值越大,样本相似度越高。
给定两个集合A,B,Jaccard 系数定义为A与B交集的大小与A与B并集的大小的比值,定义如下:

Jaccard.png


这个函数用在这里就是说,两个细胞共有"邻居"数量和所有"邻居"数量的比值,值越大,共享的”邻居“越多,两个细胞越相似。
还有Jaccard 距离的概念,公式是:

2、KNN是什么,KNN是最简单的机器学习算法,这里不多介绍了,大家可以参考百度KNN
3、邻居判定方法的rann和annoy

首先来说annoy,annoy全称“Approximate Nearest Neighbors Oh Yeah”,是一种适合实际应用的快速相似查找算法。Annoy 同样通过建立一个二叉树来使得每个点查找时间复杂度是O(log n),和kd树不同的是,annoy没有对k维特征进行切分。annoy的每一次空间划分,可以看作聚类数为2的KMeans过程。收敛后在产生的两个聚类中心连线之间建立一条垂线(图中的黑线),把数据空间划分为两部分。在划分的子空间内不停的递归迭代继续划分,直到每个子空间最多只剩下K个数据节点,划分结束。最终生成的二叉树具有如下类似结构,二叉树底层是叶子节点记录原始数据节点,其他中间节点记录的是分割超平面的信息。


这听起来不像人话,主要的思想类似于层次聚类,不同的是annoy采用的是二分法,一直分割直到剩下k个数据点,这是一种计算相似性的算法,细胞之间距离的计算提供了euclidean, cosine, manhattan, and hamming等几种。
rann暂时没查到,以后更新

接下来查看第二个函数

library(Seurat)
?FindClusters
Description:

     Identify clusters of cells by a shared nearest neighbor (SNN)
     modularity optimization based clustering algorithm. First
     calculate k-nearest neighbors and construct the SNN graph. Then
     optimize the modularity function to determine clusters. For a full
     description of the algorithms, see Waltman and van Eck (2013) _The
     European Physical Journal B_. Thanks to Nigel Delaney
     (evolvedmicrobe@github) for the rewrite of the Java modularity
     optimizer code in Rcpp!
这个说明,依据SNN来识别类群,当然算法很复杂,我们可以参考给的网址。
我们来看看主要参数
resolution: Value of the resolution parameter, use a value above
          (below) 1.0 if you want to obtain a larger (smaller) number
          of communities.
这个参数可以理解为清晰度,值越低,可以容纳更少的共享邻居数量,聚类数也会变少。
modularity.fxn: 计算模块系数函数,1为标准函数;2为备选函数,这里没有具体说明是什么函数,我认为1是上面提到的Kronecker delta函数。
method: Method for running leiden (defaults to matrix which is fast
          for small datasets). Enable method = "igraph" to avoid
          casting large data to a dense matrix.
      这个参数表示leiden算法的计算方式,(我对算法是小白~,求大神告知)
algorithm: 模块系数优化算法,1使用原始Louvain算法;2使用Louvain algorithm with multilevel refinement;3使用SLM算法;4使用Leiden算法(注:4需要额外安装插件)
n.start: 随机开始的数量,默认是10
random.seed: 随机数种子,默认是0

里面有很多算法方面的内容,对于数学而言,不会就是不会,没什么炫耀的,但是要知道其原理。
,这里分享给大家一些链接,大家可以多多研究研究。
Kronecker delta函数
leiden
Louvain
SLM
请保持愤怒,让王多鱼倾家荡产

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值