# #——回声= FALSE,结果=“隐藏”,消息= FALSE ------------------------------- 需要(knitr)美元opts_chunk组(错误= FALSE,消息= FALSE,警告= FALSE) # #设置,呼应= FALSE,消息= FALSE ----------------------------------------- 库(后面; ) ## ----------------------------------------------------------------------------- 库(scRNAseq) sce1 < - ZeiselBrainData () sce1 sce2 < - TasicBrainData sce2 () ## ----------------------------------------------------------------------------- 库(天窗)sce1 < - addPerCellQC (sce1子集=列表(水= 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抛弃美元 ] ## ----------------------------------------------------------------------------- 宇宙< -相交(rownames (sce1) rownames (sce2)) sce1 < - sce1(宇宙)sce2 < - sce2(宇宙 ,] ## ----------------------------------------------------------------------------- < - multiBatchNorm (sce1,sce2) sce1 < - [[1]] sce2 < - [[2 ]] ## ----------------------------------------------------------------------------- 库(残渣)dec1 < - modelGeneVar (sce1)叫dec2 < - modelGeneVar (sce2) combined.dec < - combineVar (dec1,叫dec2)选择。hvgs < - getTopHVGs (combined.dec n = 5000 ) ## ----------------------------------------------------------------------------- 结合< - correctExperiments (A = sce1, B = sce2参数= NoCorrectParam())图书馆(嘘)set.seed(100)结合< - runPCA(组合,subset_row = chosen.hvgs)结合< - runTSNE(组合,dimred = PCA) plotTSNE(结合colour_by =”批处理 ") ## ----------------------------------------------------------------------------- 库(确定的)set.seed (101) f.out < - fastMNN (= sce1,B=sce2, subset.row=chosen.hvgs) str(reducedDim(f。”纠正 ")) ## ----------------------------------------------------------------------------- rle (f.out批美元 ) ## ----------------------------------------------------------------------------- set.seed (101) f.out2 < - fastMNN(结合、批量=美元批量subset.row = chosen.hvgs) str (reducedDim (f。out2”,纠正 ")) ## ----------------------------------------------------------------------------- set.seed (103) f.out < - runTSNE (f。out, dimred="corrected")colour_by = "批 ") ## ----------------------------------------------------------------------------- cor.exp < -试验(f.out)[1]嘘(软木。exp xlab =“纠正表达基因1”,上校= " grey80 ") ## ----------------------------------------------------------------------------- # 使用更少的基因多,慢得多。更少的。hvgs <- head(order(combined.dec$bio, decreasing=TRUE), 100) classic.out <- mnnCorrect(sce1, sce2, subset.row=fewer.hvgs) ## ----------------------------------------------------------------------------- classic.out ## ----------------------------------------------------------------------------- # Removing the 'unclassified' cluster, which makes no sense: not.unclass <- sce2$broad_type!="Unclassified" clust.out <- clusterMNN(sce1, sce2[,not.unclass], subset.row=chosen.hvgs, clusters=list(sce1$level1class, sce2$broad_type[not.unclass])) ## ----------------------------------------------------------------------------- clust.info <- metadata(clust.out)$cluster split(clust.info$cluster, clust.info$meta) ## ----------------------------------------------------------------------------- rescale.out <- rescaleBatches(sce1, sce2) rescale.out ## ----------------------------------------------------------------------------- rescale.out <- runPCA(rescale.out, subset_row=chosen.hvgs, exprs_values="corrected") plotPCA(rescale.out, colour_by="batch") ## ----------------------------------------------------------------------------- regress.out <- regressBatches(sce1, sce2) assay(regress.out) ## ----------------------------------------------------------------------------- # Pretend the first X cells in each batch are controls. restrict <- list(1:100, 1:200) rescale.out <- rescaleBatches(sce1, sce2, restrict=restrict) ## ----------------------------------------------------------------------------- normed <- multiBatchNorm(A=sce1, B=sce2, norm.args=list(use_altexps=FALSE)) names(normed) ## ----------------------------------------------------------------------------- set.seed(100) # Using the same BSPARAM argument as fastMNN(), for speed. pca.out <- multiBatchPCA(A=sce1, B=sce2, subset.row=chosen.hvgs, BSPARAM=BiocSingular::IrlbaParam(deferred=TRUE)) names(pca.out) ## ----------------------------------------------------------------------------- sessionInfo()