相关文章推荐
健身的苦瓜  ·  王学烨:《锶同位素考古:原理、方法和应用》& ...·  1 年前    · 
有腹肌的卡布奇诺  ·  特殊教育专业(言语听觉科学)#·  1 年前    · 
追风的毛衣  ·  纸币号码玩法多:雷达号、乱蛇、人三……你都知 ...·  1 年前    · 
踏实的佛珠  ·  【现代菲斯塔纯电动】现代菲斯塔纯电动对比评测 ...·  2 年前    · 
飘逸的小摩托  ·  妖神记漫画全解说尤里 - 抖音·  2 年前    · 
Code  ›  CellChat 细胞通讯分析(预处理)开发者社区
python 社区功能 pak
https://cloud.tencent.com/developer/article/2269647
儒雅的核桃
2 年前
作者头像
生信探索
0 篇文章

CellChat 细胞通讯分析(预处理)

原创
前往专栏
腾讯云
开发者社区
文档 意见反馈 控制台
首页
学习
活动
专区
工具
TVP
文章/答案/技术大牛
发布
首页
学习
活动
专区
工具
TVP
返回腾讯云官网
社区首页 > 专栏 > 生信探索 > CellChat 细胞通讯分析(预处理)

CellChat 细胞通讯分析(预处理)

原创
作者头像
生信探索
发布 于 2023-04-21 08:53:55
270 0
发布 于 2023-04-21 08:53:55
举报

https://mp.weixin.qq.com/s/ZsUQogkqcPXkaNDIV8GhWg

安装包

using函数是我写在 $HOME/.Rprofile 中的函数,因此每次打开R就能使用。

using 的功能是一次加载多个包,并且使用了 suppressPackageStartupMessages 函数,因此不会显示加载包过程中的信息。

使用pak管理R包,可以从Bioconductor、CRAN、Github、本地、URL安装R包,解决了R包安装需要多个不同R包去安装的问题。

因为github连接不稳定,所以想了其他办法把CellChat包从github镜像到jihulab.com,再从jihulab.com克隆下来,然后用 pak::local_install 安装,如果网络可以,可以直接用 pak::pkg_install("sqjin/CellChat") 安装

install.packages("pak")
using(pak)
pkgs <- c("BiocNeighbors", "ComplexHeatmap", "circlize", "NMF")
pak::pkg_install(pkgs, upgrade = FALSE, dependencies = TRUE)
pak::pkg_install("sqjin/CellChat")
git clone https://jihulab.com/BioQuest/cellchat.git
pak::local_install("cellchat")
# pak::local_install("CellChat-master", dependencies = TRUE)

Python环境

mamba create -n SC && mamba activate SC
mamba install -y -c conda-forge python=3.10 notebook ipywidgets pandas numpy seaborn matplotlib ipykernel openpyxl pyarrow scanpy python-igraph leidenalg pytables jaxlib leidenalg
which python
# /opt/homebrew/Caskroom/mambaforge/base/envs/SC/bin/python

每个分组的细胞通讯网络流程脚本

第一次使用CellChat,好像这个处理过程是固定的,但是可视化是个性化的,又因为处理过程需要消耗些时间,所以写成脚本,可同时在后台把所有分组处理好。

各个参数的意义

  • w: 工作目录,默认为当前目录
  • i: 输出文件的标识

根据i可以得到,normalise过的基因表达数据,行基因,列细胞;Arrow格式;第一列是为index,细胞barcode;

细胞类型信息;CSV格式,第一列是Cell,细胞barcode,第二列为CellType,细胞的类型

  • s: 物种,可以选human和mouse,默认为human
  • n: 线程数默认8
  • y: python的路径

使用方法

nohup Rscript CellChat_1.R -i C -y /opt/homebrew/Caskroom/mambaforge/base/envs/SC/bin/python &> C.log &
nohup Rscript CellChat_1.R -i T -y /opt/homebrew/Caskroom/mambaforge/base/envs/SC/bin/python &> T.log &

运行后的文件目录

├── CellChat_1.R
├── C.arrow
├── C.csv
├── T.arrow
├── T.csv
├── cc_C.rds
├── cc_T.rds
├── estimationNumCluster_C_functional_dataset_single.pdf
├── estimationNumCluster_T_structural_dataset_single.pdf
├── estimationNumCluster_C_functional_dataset_single.pdf
└── estimationNumCluster_T_structural_dataset_single.pdf

Rscript

using(optparse, data.table, tidyverse, CellChat, arrow, reticulate)
option_list <- list(
    make_option(c("-w", "--workdir"), type = "character", action = "store", default = "./", help = "工作目录路径"),
    make_option(c("-i", "--id"), type = "character", action = "store", default = FALSE, help = "文件标识"),
    make_option(c("-s", "--species"), type = "character", action = "store", default = "human", help = "物种"),
    make_option(c("-n", "--n_jobs"), type = "integer", action = "store", default = 8, help = "线程"),
    make_option(c("-y", "--python"), type = "character", action = "store", default = FALSE, help = "Python路径")
opt <- parse_args(OptionParser(
    option_list = option_list, add_help_option = TRUE,
    usage = "Usage: %prog [options] \nDescription: CellChat pre!"
setwd(opt$workdir)
reticulate::use_python(opt$python)
# ==============================================================================
# 1.创建CellChat对象
# ==============================================================================
mt <- arrow::read_ipc_file(str_glue("{opt$id}.arrow")) %>%
    column_to_rownames("index") %>%
    t() %>%
    as.matrix()
df <- data.table::fread(str_glue("{opt$id}.csv")) %>%
    column_to_rownames("Cell")
cc <- createCellChat(mt, meta = df, group.by = "CellType")
cc@DB <- switch(opt$species,
    human = CellChat::CellChatDB.human,
    mouse = CellChat::CellChatDB.mouse
# ==============================================================================
# 2.预处理表达数据 + 细胞通讯网络
# ==============================================================================
future::plan("multisession", workers = opt$n_jobs)
cc <- subsetData(cc)
cc <- identifyOverExpressedGenes(cc)
cc <- identifyOverExpressedInteractions(cc)
cc <- projectData(cc, adjMatrix = switch(opt$species,
    human = PPI.human,
    mouse = PPI.mouse
cc <- computeCommunProb(cc, raw.use = FALSE, population.size = TRUE)
cc <- filterCommunication(cc, min.cells = 10)
cc <- computeCommunProbPathway(cc)
cc <- aggregateNet(cc)
cc <- netAnalysis_computeCentrality(cc, slot.name = "netP")
cc <- computeNetSimilarity(cc, type = "functional")
cc <- netEmbedding(cc, type = "functional")
cc <- netClustering(cc, fig.id = opt$id, type = "functional", do.parallel = FALSE)
cc <- computeNetSimilarity(cc, type = "structural")
cc <- netEmbedding(cc, type = "structural")
cc <- netClustering(cc, fig.id = opt$id, type = "structural", do.parallel = FALSE)
saveRDS(cc, file = str_glue("cc_{opt$id}.rds"))

查看帮助

Rscript CellChat_1.R -h
Usage: CellChat_1.R [options] 
Description: CellChat pre!
Options:
        -w WORKDIR, --workdir=WORKDIR
                工作目录路径
        -i ID, --id=ID
        -s SPECIES, --species=SPECIES
        -n N_JOBS, --n_jobs=N_JOBS
        -y PYTHON, --python=PYTHON
 
推荐文章
健身的苦瓜  ·  王学烨:《锶同位素考古:原理、方法和应用》&讲座通讯-四川大学考古科学中心
1 年前
有腹肌的卡布奇诺  ·  特殊教育专业(言语听觉科学)#
1 年前
追风的毛衣  ·  纸币号码玩法多:雷达号、乱蛇、人三……你都知道吗?_数字
1 年前
踏实的佛珠  ·  【现代菲斯塔纯电动】现代菲斯塔纯电动对比评测_现代菲斯塔纯电动对比导购_现代菲斯塔纯电动试驾_现代菲斯塔纯电动游记-网通社汽车
2 年前
飘逸的小摩托  ·  妖神记漫画全解说尤里 - 抖音
2 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号