# #——回声= FALSE,结果=“隐藏”,消息= FALSE ------------------------------- 需要(knitr)美元opts_chunk组(错误= FALSE,消息= FALSE,警告= FALSE) # #设置,呼应= FALSE,消息= FALSE ----------------------------------------- 库(后面; ) ## ----------------------------------------------------------------------------- B1 < -矩阵(rnorm (10000), ncol = 50) # 1批B2 < -矩阵(rnorm (10000), ncol = 50) #批2 #之间的切换容易批校正方法。m.out < - batchCorrect (B1, B2, PARAM = ClassicMnnParam ()) f.out < - batchCorrect (B1, B2, PARAM = FastMnnParam (d = 20)) r.out < - batchCorrect (B1, B2, PARAM = RescaleParam (pseudo.count = 0 )) ## ----------------------------------------------------------------------------- noCorrect < -函数(…)#需要一组不加修改的批次,并返回。{做。调用(cbind,列表 (...)) } ## ----------------------------------------------------------------------------- NothingParam < - setClass(“NothingParam”,包含= " BatchelorParam ") ## ----------------------------------------------------------------------------- 没有< - NothingParam()没有什么some_value < - 1美元 ## ----------------------------------------------------------------------------- batchCorrect ## ----------------------------------------------------------------------------- setMethod(“batchCorrect”、“NothingParam”功能(…, batch =NULL, restrict=NULL,子集。row = NULL,正确。all = FALSE,化验。type = "logcounts", PARAM) {batch <- list(…)checkBatchConsistency(batch) #从SCE对象中提取信息。是多少。sce <- checkIfSCE(batch) if (any(is.sce)) {batch [is. sce))Sce] <- lapply(batch [is.]sce], assay, i=assay.type)} #如果只提供了一个对象,则通过'batch'进行子集设置。做的。split <- length(batches)==1L if (do.split) { divided <- divideIntoBatches(batches[[1]], batch=batch, restrict=restrict) batches <- divided$batches restrict <- divided$restricted } # Subsetting by row. # This is a per-gene "method", so correct.all=TRUE will ignore subset.row. # More complex methods will need to handle this differently. if (correct.all) { subset.row <- NULL } else if (!is.null(subset.row)) { subset.row <- normalizeSingleBracketSubscript(originals[[1]], subset.row) batches <- lapply(batches, "[", i=subset.row, , drop=FALSE) } # Don't really need to consider restrict!=NULL here, as this function # doesn't do anything with the cells anyway. output <- do.call(noCorrect, batches) # Reordering the output for correctness if it was previously split. if (do.split) { d.reo <- divided$reorder output <- output[,d.reo,drop=FALSE] } ncells.per.batch <- vapply(batches, FUN=ncol, FUN.VALUE=0L) batch.names <- names(batches) if (is.null(batch.names)) { batch.names <- seq_along(batches) } SingleCellExperiment(list(corrected=output), colData=DataFrame(batch=rep(batch.names, ncells.per.batch))) }) ## ----------------------------------------------------------------------------- n.out <- batchCorrect(B1, B2, PARAM=NothingParam()) n.out ## ----------------------------------------------------------------------------- sessionInfo()