CibersortX網站是常用的工具,但是是網頁上傳數據,現在網頁503打不開,而BayesPrism在PMID: 37717006 文章benchmark 9種方法中發現BayesPrism的假陽性與假陰性數量上最低,并且在分解精細的免疫譜系時展現出最佳性能;因此可以作為替代工具,并且BayesPrism也提供了網頁工具,不過我們還是習慣本地跑代碼;新版的BayesPrism支持系數矩陣作為輸入。
BayesPrism是一個綜合工具,旨在利用貝葉斯統計方法從bulk RNA測序數據中精確解析腫瘤微環境的細胞組成,并同時考慮細胞特異性的基因表達模式,通過先進的算法模塊實現對復雜細胞混合物的深入分析和理解。
BayesPrism包含細胞去卷積模塊和嵌入學習模塊。細胞去卷積模塊依據來自單細胞RNA測序(scRNA-seq)的細胞類型特異性表達輪廓建立先驗,聯合估計腫瘤(或非腫瘤)樣本的bulk RNA-seq表達數據中細胞類型組成及其特異性基因表達的后驗分布。嵌入學習模塊采用期望最大化算法,基于去卷積模塊推測出的非惡性細胞表達量和比例條件,通過線性組合惡性基因程序來近似腫瘤表達模式。
安裝
library(remotes)
remotes::install_github("Danko-Lab/BayesPrism")
注:using是我寫的函數,有需要可以后臺聯系,加入交流群;using作用是一次性加載多個R包,不用寫雙引號,并且不在屏幕上打印包的加載信息
加載示例數據,可以后臺聯系獲得數據代碼和結果文件
using(remotes, data.table, BayesPrism)
load('tutorial.gbm.rdata')
輸入文件
bk.dat
: bulk轉錄組表達譜(矩陣、行樣本、列基因)
sc.dat
: 單細胞轉錄組表達譜(矩陣、行樣本、列基因)
cell.type.labels
: 細胞標簽(向量)
cell.state.labels
: 細胞狀態標簽(向量,每個標簽對應的細胞數目要大于20)
注意:
- bk.dat等只是變量名換成其他也行;
- bk.dat和sc.dat為同樣的標準化方式,支持raw count、TPM, RPM, RPKM, FPKM,不支持log轉化后的數據
質控圖
相關性圖查看樣本間相關性
BayesPrism::plot.cor.phi(
input = sc.dat,
input.labels = cell.state.labels,
title = "cell state correlation",
pdf.prefix="gbm.cor.cs",
cexRow = 0.2,
cexCol = 0.2,
margins = c(2, 2)
)
相關性圖查看細胞類型間相關性
BayesPrism::plot.cor.phi(
input = sc.dat,
input.labels = cell.type.labels,
title = "cell type correlation",
pdf.prefix="gbm.cor.ct",
cexRow = 0.5,
cexCol = 0.5
)
過濾基因
目的:去除線粒體、核糖體基因、性染色體基因、低表達基因,只選擇編碼蛋白的基因
繪制單細胞和bulk的離群基因
圖中顯示每個基因的歸一化平均表達(x 軸)和最大特異性(y 軸)的對數,以及每個基因是否屬于一個潛在的“異常”,糖體蛋白基因通常表現出高平均表達水平和低細胞類型特異性得分。
sc.stat <- BayesPrism::plot.scRNA.outlier(
input = sc.dat, # make sure the colnames are gene symbol or ENSMEBL ID
cell.type.labels = cell.type.labels,
species = "hs", # currently only human(hs) and mouse(mm) annotations are supported
return.raw = TRUE # return the data used for plotting.
pdf.prefix="gbm.sc.stat"
)
bk.stat <- BayesPrism::plot.bulk.outlier(
bulk.input = bk.dat, # make sure the colnames are gene symbol or ENSMEBL ID
sc.input = sc.dat, # make sure the colnames are gene symbol or ENSMEBL ID
cell.type.labels = cell.type.labels,
species = "hs", # currently only human(hs) and mouse(mm) annotations are supported
return.raw = TRUE
pdf.prefix="gbm.bk.stat"
)
去除線粒體、核糖體基因、性染色體基因、低表達基因
sc.dat.filtered <- BayesPrism::cleanup.genes(
input = sc.dat,
input.type = "count.matrix",
species = "hs",
gene.group = c("Rb", "Mrp", "other_Rb", "chrM", "MALAT1", "chrX", "chrY"),
exp.cells = 5
)
繪制bk.dat與sc.dat間的相關性(只支持人的基因數據)
BayesPrism::plot.bulk.vs.sc(
sc.input = sc.dat.filtered,
bulk.input = bk.dat
pdf.prefix="gbm.bk.vs.sc"
)
只選擇編碼蛋白的基因
sc.dat.filtered.pc <- BayesPrism::select.gene.type(sc.dat.filtered, gene.type = "protein_coding")
選擇signature基因
用差異分析方法給每個細胞類型選擇相應的marker基因(>50),如果基因少,可以調整閾值
diff.exp.stat <- BayesPrism::get.exp.stat(
sc.dat = sc.dat[, colSums(sc.dat > 0) > 3], # filter genes to reduce memory use
cell.type.labels = cell.type.labels,
cell.state.labels = cell.state.labels,
pseudo.count = 0.1, # a numeric value used for log2 transformation. =0.1 for 10x data, =10 for smart-seq. Default=0.1.
cell.count.cutoff = 50, # a numeric value to exclude cell state with number of cells fewer than this value for t test. Default=50.
n.cores = 1 # number of threads
)
sc.dat.filtered.pc.sig <- BayesPrism::select.marker(
sc.dat = sc.dat.filtered.pc,
stat = diff.exp.stat,
pval.max = 0.01,
lfc.min = 0.1
)
構造Prism對象
myPrism <- BayesPrism::new.prism(
reference = sc.dat.filtered.pc,
mixture = bk.dat,
input.type = "count.matrix",
cell.type.labels = cell.type.labels,
cell.state.labels = cell.state.labels,
key = "tumor",
outlier.cut = 0.01,
outlier.fraction = 0.1,
)
運行BayesPrism
分布運行,
bp.res.initial <- BayesPrism::run.prism(prism = myPrism, n.cores = 50, update.gibbs = FALSE)
base::saveRDS(bp.res.initial, file = file.path(outdir, "bp.res.initial.rds"))
bp.res.update <- BayesPrism::update.theta(bp = bp.res.initial)
base::saveRDS(bp.res.update, file = file.path(outdir, "bp.res.update.rds"))
提取細胞比例
BayesPrism在輸出中同時保留了細胞類型組成θ0的初始估計值和經過更新的細胞類型組成估計值θf。大多數情況下,用戶應使用更新后的θ值,因為它往往能改進初始估計。然而,在某些特殊情況下,可能需要使用初始估計值θ0。例如,當混合物中腫瘤成分含量較少(<50%)時,或者參考樣本和混合樣本之間不存在批次效應,比如參考數據是從同一bulk RNA-seq平臺上通過流式細胞分選獲得的情況下。
theta <- BayesPrism::get.fraction(
bp = bp.res.update,
which.theta = "final",
state.or.type = "type"
)
data.table::as.data.table(theta, keep.rownames = "Sample") %>% data.table::fwrite(file.path(outdir, "theta.csv"))
Reference
https://www.bayesprism.org/
https://github.com/Danko-Lab/BayesPrism
本文由mdnice多平臺發布