單細(xì)胞數(shù)據(jù)分析常用到建立trajectory和pseudoTime,擬時(shí)序分析可以用 Diffusion( Destiny R package)
#Diffusion PseudoTime Analysis
library(destiny) # 加載 destiny...
data(guo_norm) # 測試用的data
class(guo_norm)
image.png
dm <- DiffusionMap(ct,k = 3)
plot(dm)
image.png
給每個(gè)細(xì)胞添加注釋信息,如這個(gè)細(xì)胞的類型或者屬于的類群
palette(cube_helix(6)) #用cube_helix創(chuàng)建連續(xù)的顏色
#palette(hue_pal()(6))#也可以用ggplot2里面的默認(rèn)顏色
plot(dm, pch = 20, # pch for prettier points
col_by = 'num_cells', # or “col” with a vector or one color
legend_main = 'Cell stage')
image.png
#2D plot
plot(dm, 1:2, pch = 20, col_by = 'num_cells',
legend_main = 'Cell stage')
image.png
#3D plot
library(rgl)
plot3d(eigenvectors(dm)[, 1:3],
col = log2(guo_norm$num_cells),
type = 's', radius = .01)
view3d(theta = 10, phi = 30, zoom = .8)
# now use your mouse to rotate the plot in the window
rgl.close()
image.png
同樣可以用ggplot畫出來
qplot(DC1, DC2, data = dm, colour = factor(num_cells)) +
scale_color_cube_helix()
image.png
# or alternatively:
dif<-fortify(dm)#轉(zhuǎn)化為data.frame
ggplot(dif, aes(DC1, DC2, color = factor(num_cells)))+geom_point()
image.png
#plot 特征值
plot(eigenvalues(dm), ylim = 0:1, pch = 20,
xlab = 'Diffusion component (DC)', ylab = 'Eigenvalue')
image.png
detiny的數(shù)據(jù)輸入格式為Biobase包建立的ExpressionSet格式的文件,如果我們的數(shù)據(jù)是表達(dá)矩陣,則數(shù)據(jù)需要轉(zhuǎn)化成這個(gè)格式压昼,如seurat包里面的數(shù)據(jù)Seurat.object可以這樣轉(zhuǎn)化:
library(Biobase)
ct <-GetAssayData(object = Seurat.object)
ct<-ct[VariableFeatures(Seurat.object),]
ct <- as.ExpressionSet(as.data.frame(t(ct)))
#添加注釋信息
#. Annotations can be accessed directly via ct$column and ct[['column']].
ct$celltype <- DPT@meta.data[,c("integrated_merge_cluster")]
dm <- DiffusionMap(ct,k = 10)
palette(cube_helix(4)) # configure color palette
plot(dm, pch = 20, # pch for prettier points
col_by = "celltype")
image.png
歡迎關(guān)注微信公眾號(hào)~
image.png
參考:
[http://10.30.30.253:8787/help/library/destiny/doc/Diffusion-Maps.pdf]
[https://bioconductor.org/packages/release/bioc/vignettes/destiny/inst/doc/DPT.pdf]
https://broadinstitute.github.io/2019_scWorkshop/functional-pseudotime-analysis.html