单细胞学习3

cluster

不同聚类方法比较

normmlization,去除一些批次效应等外部因素。通过对表达矩阵的矩阵的聚类,对细胞群体进行分类。

无监督聚类:hierarchical clustering,k-means clustering,graph-based clustering。

library(SingleCellExperiment)
deng <- readRDS("D:/paopaoR/mass/deng-reads.rds")
deng
## class: SingleCellExperiment 
## dim: 22431 268 
## metadata(0):
## assays(2): counts logcounts
## rownames(22431): Hvcn1 Gbp7 ... Sox5 Alg11
## rowData names(10): feature_symbol is_feature_control ...
##   total_counts log10_total_counts
## colnames(268): 16cell 16cell.1 ... zy.2 zy.3
## colData names(30): cell_type2 cell_type1 ... pct_counts_ERCC
##   is_cell_control
## reducedDimNames(0):
## spikeNames(1): ERCC
table(deng$cell_type2)
## 
##     16cell      4cell      8cell early2cell earlyblast  late2cell 
##         50         14         37          8         43         10 
##  lateblast   mid2cell   midblast         zy 
##         30         12         60          4
table(deng$cell_type1)
## 
## 16cell  2cell  4cell  8cell  blast zygote 
##     50     22     14     37    133     12
library(scater)
## Warning: package 'scater' was built under R version 3.5.2
plotPCA(deng, colour_by = "cell_type2")
## Warning: 'add_ticks' is deprecated.
## Use '+ geom_rug(...)' instead.
image.png
plotPCA(deng, colour_by = "cell_type1")
## Warning: 'add_ticks' is deprecated.
## Use '+ geom_rug(...)' instead.
image.png

SC3

当细胞数量不是很多的时候可以用sc3,共识聚类,可以一步分析到位,也可以根据需要分步分析。但当细胞数量很多的时候速度会很慢,用seurat会比较方便。

library(SC3)
deng <- sc3_estimate_k(deng)
metadata(deng)$sc3$k_estimation
## [1] 6
deng <- sc3(deng, ks = 10, biology = TRUE)
## Setting SC3 parameters...
## Calculating distances between the cells...
## Performing transformations and calculating eigenvectors...
## Performing k-means clustering...
## Calculating consensus matrix...
## Calculating biology...
colnames(rowData(deng))
##  [1] "feature_symbol"          "is_feature_control"     
##  [3] "is_feature_control_ERCC" "mean_counts"            
##  [5] "log10_mean_counts"       "rank_counts"            
##  [7] "n_cells_counts"          "pct_dropout_counts"     
##  [9] "total_counts"            "log10_total_counts"     
## [11] "sc3_gene_filter"         "sc3_10_markers_clusts"  
## [13] "sc3_10_markers_padj"     "sc3_10_markers_auroc"   
## [15] "sc3_10_de_padj"
colnames(colData(deng))
##  [1] "cell_type2"                            
##  [2] "cell_type1"                            
##  [3] "total_features"                        
##  [4] "log10_total_features"                  
##  [5] "total_counts"                          
##  [6] "log10_total_counts"                    
##  [7] "pct_counts_top_50_features"            
##  [8] "pct_counts_top_100_features"           
##  [9] "pct_counts_top_200_features"           
## [10] "pct_counts_top_500_features"           
## [11] "total_features_endogenous"             
## [12] "log10_total_features_endogenous"       
## [13] "total_counts_endogenous"               
## [14] "log10_total_counts_endogenous"         
## [15] "pct_counts_endogenous"                 
## [16] "pct_counts_top_50_features_endogenous" 
## [17] "pct_counts_top_100_features_endogenous"
## [18] "pct_counts_top_200_features_endogenous"
## [19] "pct_counts_top_500_features_endogenous"
## [20] "total_features_feature_control"        
## [21] "log10_total_features_feature_control"  
## [22] "total_counts_feature_control"          
## [23] "log10_total_counts_feature_control"    
## [24] "pct_counts_feature_control"            
## [25] "total_features_ERCC"                   
## [26] "log10_total_features_ERCC"             
## [27] "total_counts_ERCC"                     
## [28] "log10_total_counts_ERCC"               
## [29] "pct_counts_ERCC"                       
## [30] "is_cell_control"                       
## [31] "sc3_10_clusters"                       
## [32] "sc3_10_log2_outlier_score"
sc3_plot_consensus(deng, k = 10, show_pdata = "cell_type2")
image.png
sc3_plot_silhouette(deng, k = 10)
image.png
sc3_plot_expression(deng, k = 10, show_pdata = "cell_type2")
image.png
sc3_plot_markers(deng, k = 10, show_pdata = "cell_type2")
image.png
plotPCA(deng, colour_by = "sc3_10_clusters")
## Warning: 'add_ticks' is deprecated.
## Use '+ geom_rug(...)' instead.
image.png
library(mclust)
adjustedRandIndex(colData(deng)$cell_type2, colData(deng)$sc3_10_clusters)
## [1] 0.6616899

pcaReduce

library(pcaReduce)
input <- logcounts(deng[rowData(deng)$sc3_gene_filter, ])
pca.ite <- PCAreduce(t(input), nbt = 1, q = 30, method = 'S')[[1]]#nbt-number of samples,q-number of dimensions to start with
colData(deng)$pcaReduce <- as.character(pca.ite[,32 - 10])#k-(2~q+1),k=10,(q+1)-10+1
plotPCA(deng, colour_by = "pcaReduce")
## Warning: 'add_ticks' is deprecated.
## Use '+ geom_rug(...)' instead.
image.png
adjustedRandIndex(colData(deng)$cell_type2, colData(deng)$pcaReduce)
## [1] 0.3504523

tsne+k-means

set.seed(1234)
deng <- runTSNE(deng,perplexity = 50)#change perplexity to have robust result
colData(deng)$tSNE_kmeans8 <- as.character(kmeans(deng@reducedDims$TSNE, centers = 8)$clust)
plotTSNE(deng,colour_by = "tSNE_kmeans8")
## Warning: 'add_ticks' is deprecated.
## Use '+ geom_rug(...)' instead.
image.png
colData(deng)$tSNE_kmeans10 <- as.character(kmeans(deng@reducedDims$TSNE, centers = 10)$clust)
plotTSNE(deng,colour_by = "tSNE_kmeans10")
## Warning: 'add_ticks' is deprecated.
## Use '+ geom_rug(...)' instead.
image.png
adjustedRandIndex(colData(deng)$cell_type2, colData(deng)$tSNE_kmeans10)
## [1] 0.3753199
deng <- runTSNE(deng,perplexity = 10)
colData(deng)$tSNE_kmeans10.1 <- as.character(kmeans(deng@reducedDims$TSNE, centers = 10)$clust)
adjustedRandIndex(colData(deng)$cell_type2, colData(deng)$tSNE_kmeans10.1)
## [1] 0.4531443
deng <- runTSNE(deng,perplexity = 5)
colData(deng)$tSNE_kmeans10.2 <- as.character(kmeans(deng@reducedDims$TSNE, centers = 10)$clust)
adjustedRandIndex(colData(deng)$cell_type2, colData(deng)$tSNE_kmeans10.2)
## [1] 0.48855

SINCERA

这个包感觉用的不是很多,感觉就是用了个zscore转换,根据相关层次聚类,迭代找个k值。

dat <- apply(input, 1, function(y) scRNA.seq.funcs::z.transform.helper(y))# perform z-score transformation
dd <- as.dist((1 - cor(t(dat), method = "pearson"))/2)# hierarchical clustering
hc <- hclust(dd, method = "average")
num.singleton <- 0
kk <- 1
for (i in 2:dim(dat)[2]) {
    clusters <- cutree(hc, k = i)
    clustersizes <- as.data.frame(table(clusters))
    singleton.clusters <- which(clustersizes$Freq < 2)
    if (length(singleton.clusters) <= num.singleton) {
        kk <- i
    } else {
        break;
    }
}
cat(kk)
## 6
library(pheatmap)
pheatmap(
    t(dat),
    cluster_cols = hc,
    cutree_cols = kk,
    kmeans_k = 100,
    show_rownames = FALSE
)
image.png
adjustedRandIndex(colData(deng)$cell_type2,clusters)
## [1] 0.3827252
clusters1 <- cutree(hc, k = 10)
adjustedRandIndex(colData(deng)$cell_type2,clusters1)
## [1] 0.3748432

dynamicTreeCut

deng <- runPCA(deng)
my.dist <- dist(reducedDim(deng))
my.tree <- hclust(my.dist, method="ward.D2")
library(dynamicTreeCut)
my.clusters <- unname(cutreeDynamic(my.tree, distM=as.matrix(my.dist), 
                                      minClusterSize=1, verbose=0))#modify cutheight to change clusters
table(my.clusters)
## my.clusters
##  1  2  3  4  5  6  7  8 
## 55 52 52 34 26 22 14 13
deng$clusters <- factor(my.clusters)
plotTSNE(deng,colour_by="clusters")
## Warning: 'add_ticks' is deprecated.
## Use '+ geom_rug(...)' instead.
image.png
adjustedRandIndex(colData(deng)$cell_type2,my.clusters)
## [1] 0.5354439

SNN clip

基于graph理论,找共有邻近点,现在的seurat也是基于graph,用knn,snn什么的,可以改变共享邻近点的数目改变cluster结果。

library(igraph)
library(scran)
snn.gr <- buildSNNGraph(deng, use.dimred="PCA")
cluster.out <- igraph::cluster_walktrap(snn.gr)
my.clusters <- cluster.out$membership
table(my.clusters)
## my.clusters
##  1  2  3  4  5  6  7  8  9 
## 53 36 13 22 40 33 36 21 14
deng$cluster <- factor(my.clusters)
plotTSNE(deng, colour_by="cluster")
## Warning: 'add_ticks' is deprecated.
## Use '+ geom_rug(...)' instead.
image.png
set.seed(123)
reducedDim(deng, "force") <- igraph::layout_with_fr(snn.gr, niter=3000)
plotReducedDim(deng, colour_by="cluster", use_dimred="force")
## Warning: 'add_ticks' is deprecated.
## Use '+ geom_rug(...)' instead.
image.png
adjustedRandIndex(colData(deng)$cell_type2,my.clusters)
## [1] 0.4505625

RCA

据说是现有的聚类效果最好的包,用分析的数据投影一个参考来进行聚类,但是模式还不是很成熟,暂时还没有小鼠的模式,而且前期流程跑下来的数据是fpkm,也许有些影响。并且要求名字格式“XXXX_genenames_YYYY",前面是位置信息,后面是ens号,emmm不知道为啥搞成这样,毕竟最后它还是提取中间的名字进行分析。。。。

RCA, short for Reference Component Analysis, is an R package for robust clustering analysis of single cell RNA sequencing data (scRNAseq). It is developed by Prabhakar Group at Genome Institute of Singapore (GIS).

Features: -clustering analysis of scRNAseq data from Human samples -three modes : “GlobalPanel”: default option for clusterig general single cell data sets that include a wide spectrum of cell types. “ColonEpitheliumPanel”: suitable for analyzing human colon/intestine derived samples. “SelfProjection”: suitable for analyzing data sets from not-well-studied tissue types (still under optimization)

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,752评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,100评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,244评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,099评论 1 286
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,210评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,307评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,346评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,133评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,546评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,849评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,019评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,702评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,331评论 3 319
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,030评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,260评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,871评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,898评论 2 351

推荐阅读更多精彩内容