空间细胞邻域网络图

本文介绍如何使用Python绘制单细胞和空间邻域网络图。通过Cell2location或RCTD进行单细胞空间联合分析,计算邻域,确定目标细胞类型并构建网络。文章详细阐述了数据处理、网络构建和绘图过程。
摘要由CSDN通过智能技术生成
作者,Evil Genius~~~
今天不想看文章了,我们来画一画图吧。
单细胞的我们来画一画下面的图

Transcription factor network in the pancreatic epithelial cell population

空间的部分我们来画一画邻域网络图

Neighborhood graph representing neighborhood enrichment of cell types. Edges represent average neighborhood enrichment scores (observed‑to‑expected ratio) between the cell types, and only the bidirectional enrichments were depicted in this graph as edges. Dot sizes are proportional to the estimated abundances (log scale), and the colors represent average cancer cell abundances in each cell type’s neighborhood

注意空间图的注释

Neighborhood graph representing neighborhood enrichment of cell types. Edges
represent average neighborhood enrichment scores (observed‑to‑expected ratio) between the cell types, and only the bidirectional enrichments were depicted in this graph as edges. Dot sizes are proportional to the estimated abundances (log scale), and the colors represent average cancer cell abundances in each cell type’s neighborhood.

当然了,有AI的部分在里面,我们需要绘制主图
我们先来画单细胞的,比较简单
import sceleto as scl
import sys
import scanpy as sc
import matplotlib.pyplot as plt
sys.path.append('/home/user1/python_package_jp')
import scjp
import scipy
import numpy as np
import pickle as pkl

def pklrd(filename):
    with open(filename, "rb") as file:
        data = pkl.load(file)
        return data

csdict=pklrd('/home/srkim/02_PancCa/16_FIGURE/csdict.pkl')

def size2(a,b):
    plt.rcParams['figure.figsize'] = (a,b)
def size(a,b):
    plt.gcf().set_size_inches(a,b)

def pklrd(filename):
    with open(filename, "rb") as file:
        data = pkl.load(file)
        return data

def pklwr(data, filename):
    with open(filename, "wb") as file:
        pkl.dump(data, file)

def save(name):
    scjp.save_fig(version,'Fig_'+name,fig_folder='./Fig')


plt.rcParams['figure.dpi'] = 300
# printing version
## from GSE154778, Lin, 2020
nb_name = 'test'
version =02
Name = nb_name
print('Version: %s'%(version))
print('NB_name: %s'%(Name))

plt.rcParams['figure.dpi'] = 300
读取示例数据,anndata
adata = sc.read_h5ad('/home/srkim/02_PancCa/16_FIGURE/data/PCI01.v43.canrawt_final_02.h5ad')
adata

AnnData object with n_obs × n_vars = 11536 × 2536
    obs: 'Sample', 'n_counts', 'n_genes', 'mito', 'doublet_scores', 'predicted_doublets', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts', 'pct_counts_in_top_50_genes', 'pct_counts_in_top_100_genes', 'pct_counts_in_top_200_genes', 'pct_counts_in_top_500_genes', 'name', 'status', 'assignment', 'genotype', 'KRASg', 'pathol', 'leiden', 'leiden_0.50', 'anno', 'anno_fib', 'anno_final_temp', 'anno_can', 'anno_final', 'ID', 'cID', 'pID', 'copykat.pred', 'anno_predict', 'batch', 'leiden_2.00', 'Fb_COL9A1', 'Fb_ANXA8', 'Fb_Base', 'Fb_LRRC15', 'Fb_SFRP1', 'Fb_VIT', 'Stellate', 'confused'
    var: 'means', 'dispersions', 'dispersions_norm', 'mean', 'std'
    uns: 'anno_final_colors', 'genotype_colors', 'neighbors', 'pathol_colors', 'pca', 'umap'
    obsm: 'X_pca', 'X_umap'
    varm: 'PCs'
    obsp: 'connectivities', 'distances'
画一个UMAP图
scjp.us(adata, 'anno_final')

数据处理
adata = adata[~adata.obs.anno_final.isin(['Ep_CDK1','Ep_Base'])].copy()
adata = adata.raw.to_adata()
scjp.sc_process(adata, 'fspku')

sc.external.pp.harmony_integrate(adata, 'ID', adjusted_basis='X_pca')

scjp.sc_process(adata, 'ku')

scjp.bbknn_umap(adata, 'ID', 50)
构建网络
N = scjp.network.network(adata, n_neighbor=8)

N.get_grid(select_per_grid=4)

N.impute()

N.idata

##AnnData object wit
  • 17
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值