batchelor包去除单细胞RNA-seq数据批次效应

1. 数据集的加载

# ### batchelor ##
# if (!require("BiocManager", quietly = TRUE))
#   install.packages("BiocManager")
# 
# BiocManager::install("batchelor")

library(batchelor)
library(scRNAseq)
sce1 <- ZeiselBrainData()
sce2 <- TasicBrainData()

library(scuttle)
# 过滤,取子集
sce1 <- addPerCellQC(sce1, subsets=list(Mito=grep("mt-", rownames(sce1))))
qc1 <- quickPerCellQC(colData(sce1), sub.fields="subsets_Mito_percent")
sce1 <- sce1[,!qc1$discard]

sce2 <- addPerCellQC(sce2, subsets=list(Mito=grep("mt_", rownames(sce2))))
qc2 <- quickPerCellQC(colData(sce2), sub.fields="subsets_Mito_percent")
sce2 <- sce2[,!qc2$discard]

# 行:共同的基因,取子集
universe <- intersect(rownames(sce1), rownames(sce2))
sce1 <- sce1[universe,]
sce2 <- sce2[universe,]

2. 消除批间测序覆盖度(coverage)差异

# Per-batch scaling normalization
# to remove systematic differences in coverage across batches 
# to simplify downstream comparisons.
out <- multiBatchNorm(sce1, sce2)
sce1 <- out[[1]]
sce2 <- out[[2]]

3. 差异表达基因分析

找出差异大的基因,用于下游的批间效应校正。

library(scran)
# modelGeneVar {scran}:Model the per-gene variance
dec1 <- modelGeneVar(sce1)
dec2 <- modelGeneVar(sce2)
combined.dec <- combineVar(dec1, dec2)
# 基因表达差异从大到小排序,选择前n个。
chosen.hvgs <- getTopHVGs(combined.dec, n=5000)

4. 批次差异校正

Usage

correctExperiments(
  ...,
  batch = NULL,
  restrict = NULL,
  subset.row = NULL,
  correct.all = FALSE,
  assay.type = "logcounts",
  PARAM = FastMnnParam(),
  combine.assays = NULL,
  combine.coldata = NULL,
  include.rowdata = TRUE,
  add.single = TRUE
)
combined <- correctExperiments(A=sce1, B=sce2, PARAM=FastMnnParam ())
# 等同于
combined <- fastMNN(A=sce1, B=sce2)

### 其他方法
# Using fewer genes as it is much, much slower. 
fewer.hvgs <- head(order(combined.dec$bio, decreasing=TRUE), 100)
classic.out <- correctExperiments(A=sce1, B=sce2,subset.row=fewer.hvgs,
                                  PARAM=ClassicMnnParam ())
classic.out <- mnnCorrect(sce1, sce2, subset.row=fewer.hvgs)

rescale.out <- correctExperiments(A=sce1, B=sce2, PARAM=RescaleParam ())
rescale.out <- rescaleBatches(sce1, sce2)

regress.out <- correctExperiments(A=sce1, B=sce2, PARAM=RegressParam ())
regress.out <- regressBatches(sce1, sce2)
## assay(combined)[1:2,1:3] 不同于assay(sce1)[1:2,1:3]以及
# logcounts(sce1)[1:2,1:3],已经去除了批次效应

# PARAM:A BatchelorParam object specifying the batch correction method
# to dispatch to, and the parameters with which it should be run. 
# ClassicMnnParam will dispatch to mnnCorrect; 
# FastMnnParam will dispatch to fastMNN; 
# RescaleParam will dispatch to rescaleBatches; 
# and RegressParam will dispatch to regressBatches.

5. 表达谱数据降维可视化

library(scater)
set.seed(100)

# 没有去除批次效应的数据,可视化展示
combined <- runPCA(combined, subset_row=chosen.hvgs)
combined <- runTSNE(combined, dimred="PCA")
plotPCA(combined, colour_by="batch")
plotTSNE(combined, colour_by="batch")
# 去除批次效应后的数据可视化
# dim(reducedDim(combined, "corrected"))
combined <- runTSNE(combined, dimred="corrected")
plotTSNE(combined, colour_by="batch")

set.seed(101)
f.out <- fastMNN(A=sce1, B=sce2, subset.row=chosen.hvgs)
f.out3 <- fastMNN(A=sce1, B=sce2)
str(reducedDim(f.out, "corrected")) # 命名

rle(f.out$batch)
#table(f.out$batch)

set.seed(103)
f.out <- runTSNE(f.out, dimred="corrected")
plotTSNE(f.out, colour_by="batch")

5. 查看消除批次效应后的表达量数据

# 查看校正后基因的表达量
cor.exp <- assay(f.out)[1,]
hist(cor.exp, xlab="Corrected expression for gene 1", col="grey80")

assay(combined)

# counts(combined)[2,1:2874] # 同 counts(sce1)[2,]
# logcounts(combined)[2,1:2874] # 同 logcounts(sce1)[2,]

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
《流体力学导论》是由英国物理学家G. K. Batchelor所著的一本经典著作。该书系统地介绍了流体力学的基本理论和方法。流体力学研究液体和气体等连续介质的运动规律和性质,是力学的一个重要分支,广泛应用于各个领域。 《流体力学导论》的第一部分主要介绍了流体的静力学和动力学基础。静力学研究静止流体的力学性质,如流体的压力分布和静力平衡。动力学研究流体的运动规律,括质点流体和连续流体的运动方程、速度分布以及流体的压力和速度之间的关系等。 第二部分深入探讨了流体力学中的重要概念和现象。其中涵盖了涡、湍流、边界层等内容,这些概念和现象在流体力学研究中有着重要的意义。此外,该书还介绍了流体力学在气象学、海洋学等领域的应用,并且对现代流体力学的一些发展进行了简要的讨论。 Batchelor教授的《流体力学导论》以其严谨的理论基础和深入的内容而闻名于世。该书对流体力学的各个方面进行了全面的讲解,不仅适合作为流体力学类课程的参考教材,也适用于从事流体力学研究的科研人员。通过学习《流体力学导论》,读者可以系统地掌握流体力学的基本理论、分析方法和应用技巧,为进一步深入研究和应用流体力学打下坚实的基础。 总之,《流体力学导论》是一本权威且全面的流体力学教材,对于理解和应用流体力学具有重要意义,对于希望从事相关领域研究和工程应用的人员来说是不可或缺的参考书。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值