偷偷问一下,关注了吗?
内容获取
1、购买打包合集(《KS科研分享与服务》付费内容打包集合),价格感人,可以加入微信VIP群(答疑交流群,甚至有小伙伴觉得群比代码更好),可以获取建号以来所有内容,群成员专享视频教程,提前更新,其他更多福利!
2、《KS科研分享与服务》公众号有QQ群,进入门槛是20元(完全是为了防止白嫖党,请理解),请考虑清楚。群里有免费推文的注释代码和示例数据(终身拥有),没有付费内容,群成员福利是购买单个付费内容半价!
需要者详情请联系作者(非需要者勿扰,处理太费时间):
import pandas as pd
import scanpy as sc
import numpy as np
#load data
adata = sc.read_h5ad('./pbmc3k.h5ad')
adata = adata.raw.to_adata()
adata
adata_cpdb = adata[~adata.obs['leiden'].isin(['Megakaryocytes'])]
#normalize
counts = adata_cpdb.X.toarray()
adata_cpdb.X = counts
sc.pp.normalize_per_cell(adata_cpdb, counts_per_cell_after=1e4)
adata_cpdb.layers["norm"] = adata_cpdb.X
counts = pd.DataFrame(data=adata_cpdb.layers["norm"], index=adata_cpdb.obs.index.tolist(), columns=adata_cpdb.var.index.tolist()).T
counts.index.name = "Gene"
#save meta
meta = pd.DataFrame(data=adata_cpdb.obs['leiden'].tolist(), index=adata_cpdb.obs.index.tolist(), columns=["Cell type"])
meta.index.name = "Cell"
meta
import numpy as np
import pandas as pd
import scanpy as sc
import anndata
import os
import sys
from scipy import sparse
#Download database from source
from IPython.display import HTML, display
from cellphonedb.utils import db_releases_utils
display(HTML(db_releases_utils.get_remote_database_versions_html()['db_releases_html_table']))
cpdb_version = 'v5.0.0'
cpdb_target_dir = os.path.join('./', cpdb_version)
from cellphonedb.utils import db_utils
db_utils.download_database(cpdb_target_dir, cpdb_version)
sc.settings.verbosity = 3 # verbosity: errors (0), warnings (1), info (2), hints (3)
sc.logging.print_versions()
sc.settings.set_figure_params(dpi=100) # low dpi (dots per inch) yields small inline figures
cpdb_file_path = './v5.0.0/cellphonedb.zip'
meta_file_path = './meta_cpdb.txt'
counts_file_path = './count_cpdb.txt'
out_path = './test1'
from cellphonedb.src.core.methods import cpdb_statistical_analysis_method
cpdb_results1 = cpdb_statistical_analysis_method.call(
cpdb_file_path = cpdb_file_path,
meta_file_path = meta_file_path,
counts_file_path = counts_file_path,
counts_data = 'hgnc_symbol',
#active_tfs_file_path = active_tf_path,
#microenvs_file_path = microenvs_file_path,
score_interactions = True,
iterations = 1000,
threshold = 0.1,
threads = 5,
debug_seed = 42,
result_precision = 3,
pvalue = 0.05,
separator = '|',
debug = False,
output_path = out_path
)
cpdb_file_path = './v5.0.0/cellphonedb.zip'
meta_file_path = './meta_cpdb.txt'
counts_file_path = './adata_cpdb.h5ad'
out_path = './test2'
from cellphonedb.src.core.methods import cpdb_statistical_analysis_method
cpdb_results2 = cpdb_statistical_analysis_method.call(
cpdb_file_path = cpdb_file_path,
meta_file_path = meta_file_path,
counts_file_path = counts_file_path,
counts_data = 'hgnc_symbol',
#active_tfs_file_path = active_tf_path,
#microenvs_file_path = microenvs_file_path,
score_interactions = True,
iterations = 1000,
threshold = 0.1,
threads = 5,
debug_seed = 42,
result_precision = 3,
pvalue = 0.05,
separator = '|',
debug = False,
output_path = out_path
)
cpdb_pbmc = summary_cpdb_results(cpdb_results1)
cpdb_pbmc.head()
from cellphonedb.utils import search_utils
search_results = search_utils.search_analysis_results(
query_cell_types_1 = ['CD4 T'], # List of cells 1, will be paired to cells 2 (list or 'All').
query_cell_types_2 = ['CD14 Monocytes', 'FCGR3A Monocytes'], # List of cells 2, will be paired to cells 1 (list or 'All').
# query_genes = ['TGFBR1'], # filter interactions based on the genes participating (list).
#query_interactions = ['CSF1_CSF1R'], # filter intereactions based on their name (list).
significant_means = cpdb_results1['significant_means'], # significant_means file generated by CellphoneDB.
deconvoluted = cpdb_results1['deconvoluted'], # devonvoluted file generated by CellphoneDB.
interaction_scores = cpdb_results1['interaction_scores'], # interaction score generated by CellphoneDB.
query_minimum_score = 50, # minimum score that an interaction must have to be filtered.
separator = '|', # separator (default: |) employed to split cells (cellA|cellB).
long_format = True # converts the output into a wide table, removing non-significant interactions
)
search_results.head()
觉得我们分享有些用的,点个赞再走呗!
关注我们获取精彩内容:
关注不迷路:扫描下面二维码关注公众号!
B站视频号链接:https://space.bilibili.com/471040659?spm_id_from=333.1007.0.0
关注 KS科研分享与服务,
认清正版优质内容和服务!
优质内容持续输出,物超所值!
合作联系:ks_account@163.com