## ---- echo=FALSE, results="hide", message=FALSE-------------------------- require(knitr) opts_chunk$ set(error = false,message = false,警告= false)## ----样式,echo = false,结果='asis'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------设置,echo = false,message = false ----------------------------------------------------------------------库(Cydar)寄存器(SerialParam())set.seed(100)## ------------------------------------------------------------------------------------------------------------------------------ ncells <-20000 nda <-200 nmarkers <-31 down.pos <-1.8 up.pos <-1.2条件<-Rep(c(“ a”,“”,“”b“),每个= 3)组合<-rbind(矩阵(rnorm(ncells*nmarkers,1.5,0.6),ncol = nmarkers),矩阵(rnorm(nda*nmarkers,down.pos,0.3),ncol = ncol = ncol = nmarkers),,矩阵(rnorm(nda*nmarkers,up.pos,0.3),ncol = nmarkers))组合[,31] <-rnorm(nrow(组合),1,0.5)#最后标记是QC标记。组合<-10^组合#原始强度值sample.ID <-c(示例(长度(条件),ncells,replace = true),sample((条件==“ a”),nda,替换= true),示例(条件==“ b”),nda,替换= true))colnames(组合)< - paste0(“ marker”,seq_len(nmarkers))## -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------库(ncdfflow)Collected.exprs <-list()for(i在seq_along(条件))){sutt])名称(quits)< - paste0(“ sample”,i)collected.exprs [[i]] <-poolcells(quft)} names(collected.exprs)<-paste0(“ sample”,seq_along(条件))collected.exprs <-ncdfflowset(as(Collected.exprs,“ flowset”))## -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- pool.ff <- poolCells(collected.exprs)## ----------------------------------------------------------------------------------------------------------库(FlowCore)trans <-估算元素(pool.ff,colnames(pool.ff))proc.ff <- transform(pool.ff, trans) ## ------------------------------------------------------------------------ gate.31 <- outlierGate(proc.ff, "Marker31", type="upper") gate.31 filter.31 <- filter(proc.ff, gate.31) summary(filter.31@subSet) ## ------------------------------------------------------------------------ processed.exprs <- transform(collected.exprs, trans) ## ------------------------------------------------------------------------ processed.exprs <- Subset(processed.exprs, gate.31) ## ------------------------------------------------------------------------ processed.exprs <- processed.exprs[,1:30] ## ------------------------------------------------------------------------ cd <- prepareCellData(processed.exprs) ## ------------------------------------------------------------------------ cd <- countCells(cd, tol=0.5) ## ------------------------------------------------------------------------ head(assay(cd)) ## ------------------------------------------------------------------------ head(intensities(cd)) ## ------------------------------------------------------------------------ library(edgeR) y <- DGEList(assay(cd), lib.size=cd$totals) ## ------------------------------------------------------------------------ keep <- aveLogCPM(y) >= aveLogCPM(5, mean(cd$totals)) cd <- cd[keep,] y <- y[keep,] ## ------------------------------------------------------------------------ design <- model.matrix(~factor(conditions)) y <- estimateDisp(y, design) fit <- glmQLFit(y, design, robust=TRUE) res <- glmQLFTest(fit, coef=2) ## ------------------------------------------------------------------------ qvals <- spatialFDR(intensities(cd), res$table$PValue) ## ------------------------------------------------------------------------ is.sig <- qvals <= 0.05 summary(is.sig) ## ------------------------------------------------------------------------ sig.coords <- intensities(cd)[is.sig,] sig.res <- res$table[is.sig,] coords <- prcomp(sig.coords) ## ------------------------------------------------------------------------ plotCellLogFC(coords$x[,1], coords$x[,2], sig.res$logFC) ## ----fig.width=10,fig.height=12------------------------------------------ par(mfrow=c(6,5), mar=c(2.1, 1.1, 3.1, 1.1)) limits <- intensityRanges(cd, p=0.05) all.markers <- rownames(markerData(cd)) for (i in order(all.markers)) { plotCellIntensity(coords$x[,1], coords$x[,2], sig.coords[,i], irange=limits[,i], main=all.markers[i]) } ## ------------------------------------------------------------------------ nonred <- findFirstSphere(intensities(cd), res$table$PValue) summary(nonred) ## ------------------------------------------------------------------------ all.coords <- prcomp(intensities(cd)) app <- interpretSpheres(cd, select=nonred, metrics=res$table, run=FALSE, red.coords=all.coords$x[,1:2], red.highlight=is.sig) # Set run=TRUE if you want the app to run automatically. ## ------------------------------------------------------------------------ sessionInfo()