单细胞数据拟时序分析-destiny
2019-12-22 本文已影响0人
生信编程日常
单细胞数据分析常用到建立trajectory和pseudoTime,拟时序分析可以用 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
给每个细胞添加注释信息,如这个细胞的类型或者属于的类群
palette(cube_helix(6)) #用cube_helix创建连续的颜色
#palette(hue_pal()(6))#也可以用ggplot2里面的默认颜色
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)#转化为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的数据输入格式为Biobase包建立的ExpressionSet格式的文件,如果我们的数据是表达矩阵,则数据需要转化成这个格式,如seurat包里面的数据Seurat.object可以这样转化:
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
欢迎关注微信公众号~
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