This will perform differential neighbourhood abundance testing after cell counting.

Arguments

x

A Milo object with a non-empty nhoodCounts slot.

design

A formula or model.matrix object describing the experimental design for differential abundance testing. The last component of the formula or last column of the model matrix are by default the test variable. This behaviour can be overridden by setting the model.contrasts argument

design.df

A data.frame containing meta-data to which design refers to

min.mean

A scalar used to threshold neighbourhoods on the minimum average cell counts across samples.

model.contrasts

A string vector that defines the contrasts used to perform DA testing.

fdr.weighting

The spatial FDR weighting scheme to use. Choice from edge, vertex, neighbour-distance or k-distance (default). If none is passed no spatial FDR correction is performed and returns a vector of NAs.

robust

If robust=TRUE then this is passed to edgeR and limma which use a robust estimation for the global quasilikihood dispersion distribution. See edgeR and Phipson et al, 2013 for details.

Value

A data.frame of model results.

Details

This function wraps up several steps of differential abundance testing using the edgeR functions. These could be performed separately for users who want to exercise more contol over their DA testing. By default this function sets the lib.sizes to the log10(colSums(x)), and uses the Quasi-Likelihood F-test in glmQLFTest for DA testing. FDR correction is performed separately as the default multiple-testing correction is inappropriate for neighbourhoods with overlapping cells.

Examples

library(SingleCellExperiment) ux.1 <- matrix(rpois(12000, 5), ncol=400) ux.2 <- matrix(rpois(12000, 4), ncol=400) ux <- rbind(ux.1, ux.2) vx <- log2(ux + 1) pca <- prcomp(t(vx)) sce <- SingleCellExperiment(assays=list(counts=ux, logcounts=vx), reducedDims=SimpleList(PCA=pca$x)) milo <- Milo(sce) milo <- buildGraph(milo, k=20, d=10, transposed=TRUE)
#> Constructing kNN graph with k:20
milo <- makeNhoods(milo, k=20, d=10, prop=0.3)
#> Checking valid object
#> Warning: Rownames not set on reducedDims - setting to row indices
milo <- calcNhoodDistance(milo, d=10) cond <- rep("A", ncol(milo)) cond.a <- sample(1:ncol(milo), size=floor(ncol(milo)*0.25)) cond.b <- setdiff(1:ncol(milo), cond.a) cond[cond.b] <- "B" meta.df <- data.frame(Condition=cond, Replicate=c(rep("R1", 132), rep("R2", 132), rep("R3", 136))) meta.df$SampID <- paste(meta.df$Condition, meta.df$Replicate, sep="_") milo <- countCells(milo, meta.data=meta.df, samples="SampID")
#> Checking meta.data validity
#> Setting up matrix with 55 neighbourhoods
#> Counting cells in neighbourhoods
test.meta <- data.frame("Condition"=c(rep("A", 3), rep("B", 3)), "Replicate"=rep(c("R1", "R2", "R3"), 2)) test.meta$Sample <- paste(test.meta$Condition, test.meta$Replicate, sep="_") rownames(test.meta) <- test.meta$Sample da.res <- testNhoods(milo, design=~Condition, design.df=test.meta[colnames(nhoodCounts(milo)), ])
#> Performing spatial FDR correction withk-distance weightingPerforming spatial FDR correction withneighbour-distance weightingPerforming spatial FDR correction withedge weightingPerforming spatial FDR correction withvertex weightingPerforming spatial FDR correction withnone weighting
da.res
#> logFC logCPM F PValue FDR Nhood SpatialFDR #> 1 0.9469539 20.30610 6.53221248 1.126811e-02 0.0206582080 1 0.0208913816 #> 2 1.1846067 20.51254 15.44437879 6.068047e-04 0.0025672506 2 0.0025243225 #> 3 0.9769201 19.90336 3.96713841 4.763317e-02 0.0654956026 3 0.0651564322 #> 4 1.3820761 20.30609 12.96372796 3.924734e-04 0.0017988362 4 0.0017729982 #> 5 1.3669173 19.37827 5.48793330 2.004097e-02 0.0334016220 5 0.0333265015 #> 6 1.0962553 20.26863 8.02470029 5.042951e-03 0.0110944927 6 0.0111083709 #> 7 1.3062132 19.48015 5.03150090 2.588694e-02 0.0406794761 7 0.0404691901 #> 8 1.4382305 20.34261 15.37844543 1.409625e-04 0.0010937526 8 0.0010595174 #> 9 1.7581355 20.21051 18.40119897 2.680143e-05 0.0003760884 9 0.0003604776 #> 10 2.1671479 19.51256 11.70681050 7.423192e-04 0.0027218371 10 0.0026670511 #> 11 1.7260907 20.08678 14.77297203 1.587202e-04 0.0010937526 11 0.0010595174 #> 12 1.2754012 20.44695 17.22005398 3.571523e-04 0.0017857613 12 0.0017501431 #> 13 1.1313100 19.72116 3.57640178 5.991989e-02 0.0803803391 13 0.0803754997 #> 14 0.8965115 20.14999 5.27124961 2.262215e-02 0.0365946566 14 0.0365106597 #> 15 0.6544114 19.26866 1.40662821 2.471379e-01 0.2613958561 15 0.2613492195 #> 16 0.7359889 19.30613 1.76226625 1.878455e-01 0.2040562743 16 0.2046247303 #> 17 0.8969875 19.77561 2.60769933 1.077792e-01 0.1347239878 17 0.1350690244 #> 18 -0.1524377 19.51260 0.07943082 7.783352e-01 0.7783351650 18 0.7783351650 #> 19 1.4104305 20.32446 14.04088619 2.285738e-04 0.0013968402 19 0.0013603465 #> 20 1.1496405 20.43008 13.94562771 1.236495e-03 0.0040004239 20 0.0039265117 #> 21 0.9386035 20.36055 7.58531782 9.132489e-03 0.0186032177 21 0.0186877073 #> 22 1.1571186 20.30610 9.44577773 2.383809e-03 0.0065554736 22 0.0065200063 #> 23 0.8958807 20.69311 10.83505209 4.467833e-03 0.0104993411 23 0.0105101765 #> 24 2.0059241 20.04305 17.89911821 3.418986e-05 0.0003760884 24 0.0003604776 #> 25 1.5553836 20.17043 14.76827058 1.590913e-04 0.0010937526 25 0.0010595174 #> 26 0.8856321 20.54426 9.24215757 7.942006e-03 0.0168003982 26 0.0169181115 #> 27 1.2513787 20.06510 8.20517744 4.581531e-03 0.0104993411 27 0.0105101765 #> 28 0.8477113 19.74864 2.23670517 1.362010e-01 0.1664678419 28 0.1668493858 #> 29 0.4727447 20.04310 1.28173743 2.588087e-01 0.2685750588 29 0.2685906682 #> 30 0.5006271 20.17047 1.78961323 1.860630e-01 0.2040562743 30 0.2046247303 #> 31 1.5377155 20.06509 11.75990842 7.224917e-04 0.0027218371 31 0.0026670511 #> 32 1.2566065 19.57530 4.42784752 3.649247e-02 0.0542455651 32 0.0540532581 #> 33 1.4049673 19.77559 5.90161174 1.592940e-02 0.0273786520 33 0.0273721412 #> 34 2.1535710 19.69312 9.79511200 1.986851e-03 0.0059761142 34 0.0059187654 #> 35 1.2238438 20.12923 8.95443286 3.083921e-03 0.0077098019 35 0.0077033185 #> 36 1.5032860 20.04307 11.16497694 9.793108e-04 0.0033663810 36 0.0032960192 #> 37 0.8028340 19.54429 1.99723095 1.590002e-01 0.1860640133 37 0.1866627691 #> 38 0.6528568 19.87870 1.73443349 1.892158e-01 0.2040562743 38 0.2046247303 #> 39 1.5833427 20.36053 19.33287519 3.152394e-05 0.0003760884 39 0.0003604776 #> 40 1.5239496 20.14997 13.72280021 2.680024e-04 0.0014740135 40 0.0014358285 #> 41 1.2006892 19.54428 4.22129225 4.110145e-02 0.0594889344 41 0.0591444553 #> 42 0.6528568 19.87871 1.73443864 1.892152e-01 0.2040562743 42 0.2046247303 #> 43 0.6995363 19.90337 2.10956547 1.478056e-01 0.1767240804 43 0.1771275036 #> 44 1.0630626 20.10817 6.61879176 1.074861e-02 0.0206582080 44 0.0208913816 #> 45 0.4842359 19.72118 0.71059858 4.001607e-01 0.4075710973 45 0.4076992531 #> 46 1.1771229 20.24952 9.05248532 2.929081e-03 0.0076714024 46 0.0076475753 #> 47 1.1437087 19.51257 3.97941782 4.729350e-02 0.0654956026 47 0.0651564322 #> 48 0.9766128 19.63543 2.62378903 1.067053e-01 0.1347239878 48 0.1350690244 #> 49 2.1097922 19.66456 9.72149015 2.064476e-03 0.0059761142 49 0.0059187654 #> 50 1.4901177 19.44698 6.32665964 1.260820e-02 0.0223693806 50 0.0224344959 #> 51 1.6695980 19.69313 6.53277607 1.126465e-02 0.0206582080 51 0.0208913816 #> 52 1.3611594 19.63543 4.79580825 2.958007e-02 0.0451917737 52 0.0450248054 #> 53 1.6190956 20.46362 26.22017301 9.983383e-06 0.0002745430 53 0.0002807571 #> 54 1.9089339 20.21050 21.00235300 7.686833e-06 0.0002745430 54 0.0002807571 #> 55 0.9962289 19.54428 2.99738928 8.480073e-02 0.1110485717 55 0.1110888077