偷偷问一下,关注了吗?
内容获取
1、购买打包合集(《KS科研分享与服务》付费内容打包集合),价格感人,可以加入微信VIP群(答疑交流群,甚至有小伙伴觉得群比代码更好),可以获取建号以来所有内容,群成员专享视频教程,提前更新,其他更多福利!
2、《KS科研分享与服务》公众号有QQ群,进入门槛是20元(完全是为了防止白嫖党,请理解),请考虑清楚。群里有免费推文的注释代码和示例数据(终身拥有),没有付费内容,群成员福利是购买单个付费内容半价!
需要者详情请联系作者(非需要者勿扰,处理太费时间):
#安装软件
pip install infercnvpy -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
import scanpy as sc
import infercnvpy as cnv
import matplotlib.pyplot as plt
import warnings
warnings.simplefilter("ignore")
sc.settings.set_figure_params(figsize=(5, 5))
#library(sceasy)
#library(reticulate)
#use_condaenv('sceasy')
#loompy <- reticulate::import('loompy')
# sceasy::convertFormat(uterus, from="seurat", to="anndata", outFile='sce_uterus.h5ad')
import anndata
adata = anndata.read_h5ad('sce_uterus.h5ad')
adata
# AnnData object with n_obs × n_vars = 27914 × 27001
# obs: 'orig.ident', 'nCount_RNA', 'nFeature_RNA', 'S.Score', 'G2M.Score', 'Phase', 'percent.mt', 'percent.rb', 'percent.hb', 'integrated_snn_res.0.1', 'integrated_snn_res.0.2', 'integrated_snn_res.0.3', 'integrated_snn_res.0.4', 'integrated_snn_res.0.5', 'integrated_snn_res.0.6', 'integrated_snn_res.0.7', 'integrated_snn_res.0.8', 'integrated_snn_res.0.9', 'integrated_snn_res.1', 'integrated_snn_res.1.1', 'integrated_snn_res.1.2', 'seurat_clusters', 'celltype', 'cell_type', 'group_cell'
# var: 'name'
# obsm: 'X_pca', 'X_tsne'
sc.pl.tsne(adata, color="cell_type")
gene_annotations = pd.read_csv('geneannotation.csv')
# 将染色体位置信息添加到 adata.var
adata.var['chromosome'] = '' # 初始化染色体列
adata.var['start'] = 0 # 初始化起始位置列
adata.var['end'] = 0 # 初始化结束位置列
# 匹配基因ID并添加染色体位置信息
for gene_id in adata.var_names:
if gene_id in gene_annotations['gene_symbol'].values:
# 找到匹配的基因并获取其染色体位置信息
chromosome, start, end = gene_annotations.loc[gene_annotations['gene_symbol'] == gene_id, ['chromosome', 'start', 'end']].values[0]
adata.var.loc[gene_id, 'chromosome'] = chromosome
adata.var.loc[gene_id, 'start'] = start
adata.var.loc[gene_id, 'end'] = end
#去掉NA
adata = adata[: , adata.var.chromosome.notna()]
run infercnvpy:速度很快!
#run infercnvpy
cnv.tl.infercnv(
adata,
reference_key="group_cell",
reference_cat=[
"HC_Ly",
"HC_Endo",
"HC_Uepi",
"HC_Cepi",
"HC_Mac",
"HC_SMC",
"HC_Sfib",
],
window_size=250,
)
cnv.pl.chromosome_heatmap(adata, groupby="group_cell")
#Clustering by CNV profiles and identifying tumor cells
cnv.tl.pca(adata)
cnv.pp.neighbors(adata)
cnv.tl.leiden(adata)
cnv.pl.chromosome_heatmap(adata, groupby="cnv_leiden", dendrogram=True)
#我这里按照cnv_score进行区分
adata.obs["cnv_status"] = "normal"
adata.obs.loc[adata.obs["cnv_score"]>0.008, "cnv_status"] = (
"tumor"
)
sc.pl.tsne(adata, color="cnv_status")
cnv.pl.chromosome_heatmap(adata[adata.obs["cnv_status"] == "normal", :])
最后,我们可以将cell信息提取,然后在R里面区分提取恶性细胞。总之,infercnvpy在分析和可视化上面表现都挺好,可以尝试一下!
觉得我们分享有些用的,点个赞再走呗!
关注我们获取精彩内容:
关注不迷路:扫描下面二维码关注公众号!
B站视频号链接:https://space.bilibili.com/471040659?spm_id_from=333.1007.0.0
关注 KS科研分享与服务,
认清正版优质内容和服务!
优质内容持续输出,物超所值!
合作联系:ks_account@163.com