首页 > 其他 > 详细

SC3 | 拉普拉斯矩阵 | Laplacian matrix | 图论 | 聚类 | R代码

时间:2019-05-16 22:44:48      阅读:311      评论:0      收藏:0      [点我收藏+]

最近在看SC3聚类这篇文章,SC3使用了这个工具。

All distance matrices are then transformed using either principal component analysis (PCA) or by calculating the eigenvectors of the associated graph Laplacian (L = I – D–1/2AD–1/2, where I is the identity matrix, A is a similarity matrix (A = e–A′/max(A′)), where A′ is a distance matrix) and D is the degree matrix of A, a diagonal matrix that contains the row-sums of A on the diagonal (Dii = ΣjAij). The columns of the resulting matrices are then sorted in ascending order by their corresponding eigenvalues.

先看下该工具的功能:SC3 package manual

跑一下常规代码:

library(SingleCellExperiment)
library(SC3)
library(scater)

head(ann)
yan[1:3, 1:3]

# create a SingleCellExperiment object
sce <- SingleCellExperiment(
  assays = list(
    counts = as.matrix(yan),
    logcounts = log2(as.matrix(yan) + 1)
  ), 
  colData = ann
)

# define feature names in feature_symbol column
rowData(sce)$feature_symbol <- rownames(sce)
# remove features with duplicated names
sce <- sce[!duplicated(rowData(sce)$feature_symbol), ]

# define spike-ins
isSpike(sce, "ERCC") <- grepl("ERCC", rowData(sce)$feature_symbol)

plotPCA(sce, colour_by = "cell_type1")

sce <- sc3(sce, ks = 2:4, biology = TRUE)
# sc3_interactive(sce)
# sc3_export_results_xls(sce)

######################################
sce <- sc3_prepare(sce)

sce <- sc3_estimate_k(sce)

sce <- sc3_calc_dists(sce)
names(metadata(sce)$sc3$distances)

sce <- sc3_calc_transfs(sce)
names(metadata(sce)$sc3$transformations)
metadata(sce)$sc3$distances

sce <- sc3_kmeans(sce, ks = 2:4)
names(metadata(sce)$sc3$kmeans)

col_data <- colData(sce)
head(col_data[ , grep("sc3_", colnames(col_data))])
sce <- sc3_calc_consens(sce)
names(metadata(sce)$sc3$consensus)
names(metadata(sce)$sc3$consensus$`3`)

col_data <- colData(sce)
head(col_data[ , grep("sc3_", colnames(col_data))])

sce <- sc3_calc_biology(sce, ks = 2:4)

sce <- sc3_run_svm(sce, ks = 2:4)
col_data <- colData(sce)
head(col_data[ , grep("sc3_", colnames(col_data))])

  

接下来会尝试拆一下该工具。

 

先开题,待续~

 

参考:

拉普拉斯矩阵(Laplacian matrix)

 

SC3 | 拉普拉斯矩阵 | Laplacian matrix | 图论 | 聚类 | R代码

原文:https://www.cnblogs.com/leezx/p/10878506.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!