个人的一些碎碎念:

聚类,直觉就能想到kmeans聚类,另外还有一个hierarchical clustering,但是单细胞里面都用得不多,为什么?印象中只有一个scoring model是用kmean进行粗聚类。(10x就是先做PCA,再用kmeans聚类的)

鉴于单细胞的教程很多,也有不下于10种针对单细胞的聚类方法了。

降维往往是和聚类在一起的,所以似乎有点难以区分。

PCA到底是降维、聚类还是可视化的方法,t-SNE呢?

其实稍微思考一下,PCA、t-SNE还有下面的diffusionMap,都是一种降维方法。区别就在于PCA是完全的线性变换得到PC,t-SNE和diffusionMap都是非线性的。

为什么降维?因为我们特征太多了,基因都是万级的,降维之后才能用kmeans啥的。其次就是,降维了才能可视化!我们可视化的最高维度就是三维,几万维是无法可视化的。但paper里,我们最多选前两维,三维在平面上的效果还不如二维。

聚类策略:

聚类还要什么策略?不就是选好特征之后,再选一个k就得到聚类的结果了吗?是的,常规分析确实没有什么高深的东西。

但通常我们不是为了聚类而聚类,我们的结果是为生物学问题而服务的,如果从任何角度都无法解释你的聚类结果,那你还聚什么类,总不可能在paper里就写我们聚类了,得到了一些marker,然后就没了下文把!

什么问题?

什么叫针对问题的聚类呢?下面这篇文章就是针对具体问题的聚类。先知:我们知道我们细胞里有些污染的细胞,如何通过聚类将他们识别出来?

这种具体的问题就没法通过跑常规流程来解决了,得想办法!

Dimensionality reduction.

Throughout the manuscript we use diffusion maps, a non-linear dimensionality reduction technique37. We calculate a cell-to-cell distance matrix using 1 - Pearson correlation and use the diffuse function of the diffusionMap R package with default parameters to obtain the first 50 DMCs. To determine the significant DMCs, we look at the reduction of eigenvalues associated with DMCs. We determine all dimensions with an eigenvalue of at least 4% relative to the sum of the first 50 eigenvalues as significant, and scale all dimensions to have mean 0 and standard deviation of 1.

有点超前(另类),用diffusionMap来降维,计算了细胞-细胞的距离,得到50个DMC,鉴定出显著的DMC,scale一下。

Initial clustering of all cells.

To identify contaminating cell populations and assess  overall heterogeneity in the data, we clustered all single cells. We first combined all Drop-seq samples and normalized the data (21,566 cells, 10,791 protein-coding genes detected in at least 3 cells and mean UMI at least 0.005) using regularized negative binomial regression as outlined above (correcting for sequencing depth related factors and cell cycle). We identified 731 highly variable genes; that is, genes for which the z-scored standard deviation was at least 1. We used the variable genes to perform dimensionality reduction using diffusion maps as outlined above (with relative eigenvalue cutoff of 2%), which returned 10 significant dimensions.

For clustering we used a modularity optimization algorithm that finds community structure in the data with Jaccard similarities (neighbourhood size 9, Euclidean distance in diffusion map coordinates) as edge weights between cells38. With the goal of over-clustering the data to identify rare populations, the small neighbourhood size resulted in 15 clusters, of which two were clearly separated from the rest and expressed marker genes expected from contaminating cells (Neurod6 from excitatory neurons, Igfbp7 from epithelial cells). These cells represent rare cellular contaminants in the original sample (2.6% and 1%), and were excluded from further analysis, leaving 20,788 cells.

鉴定出了highly variable genes,还是为了降噪(其实特征选择可以很自由,只是好杂志偏爱这种策略,你要是纯手动选,人家就不乐意了)。

Jaccard相似度,来聚类。

要想鉴定rare populations,就必须over-clustering!!!居然将k设置为15,然后通过marker来筛选出contaminating cells。

确实从中学习了很多,自己手写代码就是不一样,比纯粹的跑软件要强很多。

# cluster cells and remove contaminating populations
cat('Doing initial clustering\n')
cl <- cluster.the.data.simple(cm, expr, 9, seed=42)
md$init.cluster <- cl$clustering
# detection rate per cluster for some marker genes
goi <- c('Igfbp7', 'Col4a1', 'Neurod2', 'Neurod6')
det.rates <- apply(cm[goi, ] > 0, 1, function(x) aggregate(x, by=list(cl$clustering), FUN=mean)$x)
contam.clusters <- sort(unique(cl$clustering))[apply(det.rates > 1/3, 1, any)]
use.cells <- !(cl$clustering %in% contam.clusters)
cat('Of the', ncol(cm), 'cells', sum(!use.cells), 'are determined to be part of a contaminating cell population.\n')
cm <- cm[, use.cells]
expr <- expr[, use.cells]
md <- md[use.cells, ]

  

# for clustering
# ev.red.th: relative eigenvalue cutoff of 2%
dim.red <- function(expr, max.dim, ev.red.th, plot.title=NA, do.scale.result=FALSE) {cat('Dimensionality reduction via diffusion maps using', nrow(expr), 'genes and', ncol(expr), 'cells\n')if (sum(is.na(expr)) > 0) {dmat <- 1 - cor(expr, use = 'pairwise.complete.obs')} else {# distance 0 <=> correlation 1dmat <- 1 - cor(expr)}max.dim <- min(max.dim, nrow(dmat)/2)dmap <- diffuse(dmat, neigen=max.dim, maxdim=max.dim)ev <- dmap$eigenvals# relative eigenvalue cutoff of 2%, something like PCAev.red <- ev/sum(ev)evdim <- rev(which(ev.red > ev.red.th))[1]if (is.character(plot.title)) {# Eigenvalues, We observe a substantial eigenvalue drop-off after the initial components, demonstrating that the majority of the variance is captured in the first few dimensions.plot(ev, ylim=c(0, max(ev)), main = plot.title)abline(v=evdim + 0.5, col='blue')}evdim <- max(2, evdim, na.rm=TRUE)cat('Using', evdim, 'significant DM coordinates\n')colnames(dmap$X) <- paste0('DMC', 1:ncol(dmap$X))res <- dmap$X[, 1:evdim]if (do.scale.result) {res <- scale(dmap$X[, 1:evdim])} return(res)
}# jaccard similarity
# rows in 'mat' are cells
jacc.sim <- function(mat, k) {# generate a sparse nearest neighbor matrixnn.indices <- get.knn(mat, k)$nn.indexj <- as.numeric(t(nn.indices))i <- ((1:length(j))-1) %/% k + 1nn.mat <- sparseMatrix(i=i, j=j, x=1)rm(nn.indices, i, j)# turn nn matrix into SNN matrix and then into Jaccard similaritysnn <- nn.mat %*% t(nn.mat)snn.summary <- summary(snn)snn <- sparseMatrix(i=snn.summary$i, j=snn.summary$j, x=snn.summary$x/(2*k-snn.summary$x))rm(snn.summary)return(snn)
}cluster.the.data.simple <- function(cm, expr, k, sel.g=NA, min.mean=0.001, min.cells=3, z.th=1, ev.red.th=0.02, seed=NULL, max.dim=50) {if (all(is.na(sel.g))) {# no genes specified, use most variable genes# filter min.cells and min.mean# cm only for filteringgoi <- rownames(expr)[apply(cm[rownames(expr), ]>0, 1, sum) >= min.cells & apply(cm[rownames(expr), ], 1, mean) >= min.mean]# gene sumsspr <- apply(expr[goi, ]^2, 1, sum)# scale the expression of all genes, only select the gene above z.th# need to plot the histsel.g <- goi[scale(sqrt(sspr)) > z.th]}cat(sprintf('Selected %d variable genes\n', length(sel.g)))sel.g <- intersect(sel.g, rownames(expr))cat(sprintf('%d of these are in expression matrix.\n', length(sel.g)))if (is.numeric(seed)) {set.seed(seed)}dm <- dim.red(expr[sel.g, ], max.dim, ev.red.th, do.scale.result = TRUE)sim.mat <- jacc.sim(dm, k)gr <- graph_from_adjacency_matrix(sim.mat, mode='undirected', weighted=TRUE, diag=FALSE)cl <- as.numeric(membership(cluster_louvain(gr)))results <- list()results$dm <- dmresults$clustering <- clresults$sel.g <- sel.gresults$sim.mat <- sim.matresults$gr <- grcat('Clustering table\n')print(table(results$clustering))return(results)
}

  

  

转载于:https://www.cnblogs.com/leezx/p/8648390.html

单细胞数据高级分析之初步降维和聚类 | Dimensionality reduction | Clustering相关推荐

  1. RNA-seq与scRNA-seq数据的联合分析方法(bulk与单细胞数据联合分析)

    问题:当我有一些bulk RNA-seq数据,例如高生存率与低生存率的患者组织.疾病与正常的患者组织.存在药物反应与无药物反应的患者组织.我如何找到能够影响这些条件的确切的细胞类型? Bulk数据是由 ...

  2. 单细胞转录组高级分析: 多样本合并与批次校正

    https://cloud.tencent.com/developer/article/1692238 亮点: 大概解释了Seurat多样本整合并去除批次效应的原理 介绍了两种数据集合并的方式(注意是 ...

  3. 降维技术 (Dimensionality Reduction)

    降维是一个去掉冗余的不重要的变量,而只留下主要的可以保持信息的变量的过程.通常通过两种途径来实现: 一个是特征选择(Feature Selection) 一种是特征提取(Feature Extract ...

  4. 非线性降维(Nonlinear dimensionality reduction)

    高维数据意味着需要多于两个或三个维度来表示的数据,可能很难解释.简化的一种方法是假设感兴趣的数据位于低维空间内.如果感兴趣的数据具有足够低的维数,则数据可以在低维空间中可视化. 下面是一些值得注意的非 ...

  5. 单细胞转录组数据整合分析专题研讨会(2019.11)

    2019年10月9日,单细胞转录组再等Nature.题为Decoding human fetal liver haematopoiesis的研究,对受孕后4周至17周的人胚胎肝脏.卵黄囊.肾脏和皮肤组 ...

  6. 有了易生信,导师再也不用担心我的单细胞转录组整合分析啦

    2019年10月9日,单细胞转录组再等Nature.题为Decoding human fetal liver haematopoiesis的研究,对受孕后4周至17周的人胚胎肝脏.卵黄囊.肾脏和皮肤组 ...

  7. python如何读dat数据_如何用Python进行数据质量分析

    概述 数据挖掘的第一步工作是数据准备,而数据准备的第一步就是数据质量分析了.本篇文章着重介绍如何使用Python进行数据质量分析的初步工作,属于比较基础的入门教程. 为什么要进行数据质量分析 根据百度 ...

  8. python sci数据_scanpy学习笔记:用Python分析单细胞数据

    Scanpy 是一个基于 Python 分析单细胞数据的软件包,内容包括预处理,可视化,聚类,拟时序分析和差异表达分析等.本文翻译自 scanpy 的官方教程 Preprocessing and cl ...

  9. R语言分析单细胞数据Day1——下载Seurat包并进行预处理(一)

    Task.1 安装Seurat,准备处理single cell data 安装Seurat时,只能安装3.2.3以下的版本,太高就不兼容! install.packages('remotes') %安 ...

  10. 转录组高级分析和数据可视化技术研讨会(2023.9)

    福利公告:为了响应学员的学习需求,经过易生信培训团队的讨论筹备,现安排<高级转录组分析和R数据可视化>于2023年5月12日线上/线下课程 (线上课是通过腾讯会议实时直播线下课,实时互动, ...

最新文章

  1. android 刷卡布局,刷卡布局效果-开源AndroidSwipeLayout使用解析(二)
  2. TensorFlow2简单入门-单词嵌入向量
  3. c语言在管理系统中的应用,C语言应用——学生管理系统的制作
  4. 队列模块(Queue)
  5. 在Windows XP3下搭建cocos2d-x-android开发环境
  6. 载 Kubernetes和OpenStack到底是什么关系?先搞清楚,再系列学习
  7. centos7提示ifconfig command not found解决
  8. 荣耀8获吉尼斯世界纪录!18425米高空直播体验
  9. 二叉树学习之二叉树的构建及操作
  10. mongodb数据库导出表的流程
  11. 基于JAVA的GUI编程的的迷宫游戏 2020-12-15
  12. 用 GreaseMonkey (油猴)解码 TinyURL
  13. RequireJS - 用法
  14. 机械键盘各种轴的特点
  15. 水晶报表(crystal reports)--java
  16. 平面波导型光分路器行业调研报告 - 市场现状分析与发展前景预测
  17. 微信小程序——获取用户unionId
  18. pythongui界面源码_超酷 Python 程序包 ,一行代码实现 GUI 界面
  19. php新闻增删改查操作
  20. 计算机网络授时设置,网络授时系统,网络校时系统

热门文章

  1. 全网首发:FreeSwitch服务器转发引起的硬解失败原因分析
  2. 软件对操作系统有要求?操作系统不符合要求你软件就不玩了?
  3. 对比目录差异,涉及到LINUX要小心,无法发现大小写问题
  4. 信号集 信号屏蔽字/pending的处理
  5. day_05 显示字符A
  6. Win10+Pytorch0.4.1版本+cuda一键安装
  7. 学习写第一份在CSDN上的博客;
  8. Windows下,Unicode、UTF8,GBK(GB2312)互转
  9. java反编译能拿到源码吗_大牛带你解读Spring源码,编写自定义标签,您能学会吗?
  10. Ring Buffer 实现原理