This function quantifies the number of cells in each neighbourhood according to an input experimental design. This forms the basis for the differential neighbourhood abundance testing.

countCells(x, samples, meta.data = NULL)

Arguments

x

A Milo object with non-empty graph and nhoods slots.

samples

Either a string specifying which column of data should be used to identify the experimental samples for counting, or a named vector of sample ids mapping each single cell to it's respective sample.

meta.data

A cell X variable data.frame containing study meta-data including experimental sample IDs. Assumed to be in the same order as the cells in the input Milo object.

Value

A Milo object containing a counts matrix in the nhoodCounts slot.

Details

This function generates a counts matrix of nhoods X samples, and populates the nhoodCounts slot of the input Milo object. This matrix is used down-stream for differential abundance testing.

Examples

library(igraph)
#> #> Attaching package: ‘igraph’
#> The following objects are masked from ‘package:DelayedArray’: #> #> path, simplify
#> The following object is masked from ‘package:GenomicRanges’: #> #> union
#> The following object is masked from ‘package:IRanges’: #> #> union
#> The following object is masked from ‘package:S4Vectors’: #> #> union
#> The following objects are masked from ‘package:BiocGenerics’: #> #> normalize, path, union
#> The following object is masked from ‘package:miloR’: #> #> graph
#> The following objects are masked from ‘package:stats’: #> #> decompose, spectrum
#> The following object is masked from ‘package:base’: #> #> union
m <- matrix(rnorm(100000), ncol=100) milo <- buildGraph(m, k=20, d=10)
#> 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
cond <- rep("A", nrow(m)) cond.a <- sample(1:nrow(m), size=floor(nrow(m)*0.25)) cond.b <- setdiff(1:nrow(m), cond.a) cond[cond.b] <- "B" meta.df <- data.frame(Condition=cond, Replicate=c(rep("R1", 330), rep("R2", 330), rep("R3", 340))) 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 12 neighbourhoods
#> Counting cells in neighbourhoods
milo
#> class: Milo #> dim: 1000 100 #> metadata(0): #> assays(1): logcounts #> rownames: NULL #> rowData names(0): #> colnames: NULL #> colData names(0): #> reducedDimNames(1): PCA #> spikeNames(0): #> altExpNames(0): #> nhoods dimensions(1): 12 #> nhoodCounts dimensions(2): 12 6 #> nhoodDistances dimension(1): 0 #> graph names(1): graph #> nhoodIndex names(1): 12 #> nhoodExpression dimension(2): 1 1 #> nhoodReducedDim names(0): #> nhoodGraph names(0): #> nhoodAdjacency dimension(0):