偷偷问一下,关注了吗?
内容获取
1、购买打包合集(《KS科研分享与服务》付费内容打包集合),价格感人,可以加入微信VIP群(答疑交流群,甚至有小伙伴觉得群比代码更好),可以获取建号以来所有内容,群成员专享视频教程,提前更新,其他更多福利!
2、《KS科研分享与服务》公众号有QQ群,进入门槛是20元(完全是为了防止白嫖党,请理解),请考虑清楚。群里有免费推文的注释代码和示例数据(终身拥有),没有付费内容,群成员福利是购买单个付费内容半价!
需要者详情请联系作者(非需要者勿扰,处理太费时间):
The predicted potency scores additionally provide a continuous measure of developmental potential, ranging from 0 (differentiated) to 1 (totipotent).
Underlying this method is a novel, interpretable deep learning framework trained and validated across 31 human and mouse scRNA-seq datasets encompassing 28 tissue types, collectively spanning the developmental spectrum.
This framework learns multivariate gene expression programs for each potency category and calibrates outputs across the full range of cellular ontogeny, facilitating direct cross-dataset comparison of developmental potential in an absolute space.
R语言版: CytoTRACE2官网:https://github.com/digitalcytometry/cytotrace2
加载数据并安装R包,数据还是使用的之前的一篇Nature的,可以作为参考:
###加载数据及安装包
library(Seurat)
DimPlot(sce1, label = T)
sce_sub <- sce1[,sce1$cluster %in% c("YSMP","GMP","Myeloblast","Monocyte")]
devtools::install_github("digitalcytometry/cytotrace2", subdir = "cytotrace2_r")
library(CytoTRACE2)
CytoTRACE2的运行是很简单的,它的input可以是表达矩阵,也可以直接是seurat object。这里我们做了一个对比,使用counts和data得到的结果是一样的。
#data running-主要函数cytotrace2
cytotrace2_sce <- cytotrace2(sce_sub, #seurat对象
is_seurat = TRUE,
slot_type = "counts", #counts和data都可以
species = 'human')#物种要选择,默认是小鼠
class(cytotrace2_sce)
# [1] "Seurat"
# attr(,"package")
# [1] "SeuratObject"
# cytotrace2_res <- cytotrace2(sce_sub@assays$RNA$data, #seurat对象
# species = 'human')#物种要选择,默认是小鼠
#
# class(cytotrace2_res)
# [1] "data.frame"
结果可视化;
annotation <- data.frame(phenotype = sce_sub@meta.data$cluster) %>%
set_rownames(., colnames(sce_sub))
# plotting-一次性生成多个图,然后储存在一个list,用$查看即可
plots <- plotData(cytotrace2_result = cytotrace2_sce,
annotation = annotation,
is_seurat = TRUE)
#如果这些图您需要放在文章中,需要修饰也是可以的
#因为是基于ggplot的作图,所以修饰就很简单了
#比如我们修饰一下主题
library(ggplot2)
for(i in 1:(length(plots)-1)) {
plots[[i]] <- plots[[i]]+theme_bw()
}
#可以一个个查看图并保存
# #p1
# plots$CytoTRACE2_UMAP
# #p2
# plots$CytoTRACE2_Potency_UMAP
# #p3
# plots$CytoTRACE2_Relative_UMAP
# #p4
# plots$Phenotype_UMAP
# #p5
# plots$CytoTRACE2_Boxplot_byPheno
#我们这里为了方便展示,组合展示
library(cowplot)
plot_grid(plots[[1]],plots[[3]],plots[[4]],
plots[[5]],ncol=2)#ncol=4表示图片排为几列
Python版: CytoTRACE2官网: https://github.com/digitalcytometry/cytotrace2/tree/main/cytotrace2_python
cd data_analysis/cytotrace2_py/
git clone https://github.com/digitalcytometry/cytotrace2
cd cytotrace2/cytotrace2_python
conda env create -f environment_py.yml
conda activate cytotrace2-py
pip install .
gene_exp <- as.matrix(GetAssayData(sce_sub, layer = "counts"))
write.table(gene_exp, file = "gene_exp.txt", sep = '\t',quote=F)
cell_anno <- data.frame(cellid = rownames(sce_sub@meta.data),
celltype = sce_sub@meta.data$cluster)
write.table(cell_anno, file = "cell_anno.txt", sep = '\t',quote=F, row.names = F)
getwd()
setwd("/home/tq_ziv/data_analysis/cytotrace2_py/")
# sce_sub <- sce1[,sce1$cluster %in% c("YSMP","GMP","Myeloblast","Monocyte")]
# save(sce_sub, file = "sce_sub.RData")
library(sceasy)
library(reticulate)
use_condaenv('sceasy')
loompy <- reticulate::import('loompy')
sceasy::convertFormat(sce_sub, from="seurat", to="anndata", outFile='sce_sub.h5ad')
import scanpy as sc
adata=sc.read_h5ad("./sce_sub.h5ad")
expression_matrix = pd.DataFrame(adata.to_df().T) #需要转置一下
expression_matrix.head()
expression_matrix.to_csv('expression_matrix.txt',sep="\t")
cell_annotations = pd.DataFrame(data=adata.obs["cluster"])
cell_annotations
cell_annotations.to_csv('cell_annotations.txt',sep="\t")
#直接终端运行
cytotrace2 --input-path gene_exp.txt --annotation-path cell_anno.txt --species human
#python中运行
from cytotrace2_py.cytotrace2_py import *
exp_path = "./expression_matrix.txt"
annotation_path = "./cell_annotations.txt"
species = "human"
results = cytotrace2(exp_path,
annotation_path=annotation_path,
species=species)
觉得我们分享有些用的,点个赞再走呗!
关注我们获取精彩内容:
关注不迷路:扫描下面二维码关注公众号!
B站视频号链接:https://space.bilibili.com/471040659?spm_id_from=333.1007.0.0
关注 KS科研分享与服务,
认清正版优质内容和服务!
优质内容持续输出,物超所值!
合作联系:ks_account@163.com