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

最近在看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)

 

上一篇:Laplacian


下一篇:Manifold learning流行学习和谱聚类